Commit from GitHub Actions

This commit is contained in:
Lee Lup Yuen 2021-12-30 08:35:12 +00:00
parent bc58e415c4
commit 0b5741b6a0

View file

@ -69,8 +69,22 @@
<li><a href="#lorawan-support">1.1 LoRaWAN Support</a><ul></ul></li>
<li><a href="#lora-sx1262-library">1.2 LoRa SX1262 Library</a><ul></ul></li>
<li><a href="#library-vs-driver">1.3 Library vs Driver</a><ul></ul></li></ul></li>
<li><a href="#whats-next">2 Whats Next</a><ul></ul></li>
<li><a href="#notes">3 Notes</a><ul></ul></li></ul></nav><p>📝 <em>7 Jan 2022</em></p>
<li><a href="#device-eui-and-app-key">2 Device EUI and App Key</a><ul></ul></li>
<li><a href="#join-network">3 Join Network</a><ul></ul></li>
<li><a href="#nimble-porting-layer">4 NimBLE Porting Layer</a><ul></ul></li>
<li><a href="#gpio-interrupts">5 GPIO Interrupts</a><ul></ul></li>
<li><a href="#build-nimble">6 Build NimBLE</a><ul></ul></li>
<li><a href="#sx1262-busy">7 SX1262 Busy</a><ul></ul></li>
<li><a href="#event-loop">8 Event Loop</a><ul></ul></li>
<li><a href="#nonce">9 Nonce</a><ul></ul></li>
<li><a href="#random-number-generator">10 Random Number Generator</a><ul></ul></li>
<li><a href="#logging">11 Logging</a><ul></ul></li>
<li><a href="#message-size">12 Message Size</a><ul></ul></li>
<li><a href="#send-data">13 Send Data</a><ul></ul></li>
<li><a href="#whats-next">14 Whats Next</a><ul></ul></li>
<li><a href="#notes">15 Notes</a><ul></ul></li>
<li><a href="#appendix-gpio-issue">16 Appendix: GPIO Issue</a><ul></ul></li>
<li><a href="#appendix-callout-issue">17 Appendix: Callout Issue</a><ul></ul></li></ul></nav><p>📝 <em>7 Jan 2022</em></p>
<p><img src="https://lupyuen.github.io/images/lorawan3-title.jpg" alt="PineDio Stack BL604 RISC-V Board (left) talking LoRaWAN to RAKwireless WisGate LoRaWAN Gateway (right)" /></p>
<p><em>PineDio Stack BL604 RISC-V Board (left) talking LoRaWAN to RAKwireless WisGate LoRaWAN Gateway (right)</em></p>
<p>Last article we got <strong>LoRa</strong> (the long-range, low-bandwidth wireless network) running on <a href="https://lupyuen.github.io/articles/nuttx"><strong>Apache NuttX OS</strong></a></p>
@ -87,6 +101,9 @@
<p><img src="https://lupyuen.github.io/images/sx1262-library5.jpg" alt="Porting LoRaWAN to NuttX OS" /></p>
<h1 id="small-steps" class="section-header"><a href="#small-steps">1 Small Steps</a></h1>
<p>TODO</p>
<ul>
<li><a href="https://github.com/lupyuen/LoRaMac-node-nuttx"><strong>LoRaMac-node-nuttx</strong></a></li>
</ul>
<p><em>So today well build the NuttX Drivers for LoRa SX1262 and LoRaWAN?</em></p>
<p>Not quite. Implementing LoRa AND LoRaWAN is a complex endeavour.</p>
<p>Thus we break the implementation into small steps…</p>
@ -165,7 +182,141 @@ git submodule add --branch nuttx https://github.com/lupyuen/lora-sx1262 libsx126
</ul>
<p>For now well call this SPI Test Driver in our LoRa SX1262 Library.</p>
<p><img src="https://lupyuen.github.io/images/spi2-pinedio1.jpg" alt="Inside PineDio Stack BL604" /></p>
<h1 id="whats-next" class="section-header"><a href="#whats-next">2 Whats Next</a></h1>
<h1 id="device-eui-and-app-key" class="section-header"><a href="#device-eui-and-app-key">2 Device EUI and App Key</a></h1>
<p>LoRa Frequency and Sync Word are OK … Lets fix the Device EUI and Join EUI for #LoRaWAN on #NuttX OS</p>
<p>TODO55</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run2a.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/b91c1f88645eedb813cfffa2bdf7d7a0">(Run Log)</a></p>
<p>TODO59</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run1.png" alt="" /></p>
<p>#LoRaWAN gets its Device EUI, Join EUI and App Key from the Secure Element … But since #NuttX doesnt have a Secure Element, we hardcode them in the “Soft” Secure Element</p>
<p>TODO61</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-secure1.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/LoRaMac-node-nuttx/blob/master/src/peripherals/soft-se/se-identity.h#L65-L79">(Source)</a></p>
<p>For #NuttX OS we hardcode the #LoRaWAN App Key … Into the “Soft” Secure Element</p>
<p>TODO60</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-secure2a.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/LoRaMac-node-nuttx/blob/master/src/peripherals/soft-se/se-identity.h#L100-L115">(Source)</a></p>
<h1 id="join-network" class="section-header"><a href="#join-network">3 Join Network</a></h1>
<p>Lets connect Apache #NuttX OS to a #LoRaWAN Gateway … RAKwireless WisGate D4H with ChirpStack</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-title.jpg" alt="PineDio Stack BL604 RISC-V Board (left) talking LoRaWAN to RAKwireless WisGate LoRaWAN Gateway (right)" /></p>
<p><a href="https://lupyuen.github.io/articles/wisgate">(Article)</a></p>
<p>#LoRaWAN Gateway receives the Join Request from #NuttX OS … And accepts the Join Request! 🎉</p>
<p>TODO43</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-chirpstack.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/a8e834e7b4267345f01b6629fb7f5e33">(Run Log)</a></p>
<p>#NuttX OS doesnt handle the Join Response from #LoRaWAN Gateway … Lets fix this</p>
<p>TODO56</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run3.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/a8e834e7b4267345f01b6629fb7f5e33">(Run Log)</a></p>
<h1 id="nimble-porting-layer" class="section-header"><a href="#nimble-porting-layer">4 NimBLE Porting Layer</a></h1>
<p>Our #NuttX App was waiting for the #LoRaWAN Join Request to be transmitted before receiving the Join Response … But because were polling SX1262, we missed the Join Response … Lets fix this with the multithreading functions from NimBLE Porting Layer</p>
<ul>
<li><a href="https://github.com/lupyuen/nimble-porting-nuttx"><strong>nimble-porting-nuttx</strong></a></li>
</ul>
<p>TODO57</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run4a.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/d3d9db37a40d7560fc211408db04a81b">(Log)</a></p>
<p>NimBLE Porting Layer is a portable library of Multithreading Functions … Weve used it for #LoRa on Linux and FreeRTOS … Now we call it from Apache #NuttX OS</p>
<h1 id="gpio-interrupts" class="section-header"><a href="#gpio-interrupts">5 GPIO Interrupts</a></h1>
<p>SX1262 will trigger a GPIO Interrupt on #NuttX OS when it receives a #LoRa Packet … We wait for the GPIO Interrupt to be Signalled in a Background Thread</p>
<p>TODO46</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-gpio2.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/lora-sx1262/blob/lorawan/src/sx126x-nuttx.c#L742-L778">(Source)</a></p>
<p>We handle GPIO Interrupts (SX1262 DIO1) in a #NuttX Background Thread … Awaiting the Signal for GPIO Interrupt</p>
<p>TODO47</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-gpio3.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/lora-sx1262/blob/lorawan/src/sx126x-nuttx.c#L835-L861">(Source)</a></p>
<p>Our #NuttX Background Thread handles the GPIO Interrupts (SX1262 DIO1) … By adding to the #LoRaWAN Event Queue</p>
<p>TODO48</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-gpio4a.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/lora-sx1262/blob/lorawan/src/sx126x-nuttx.c#L863-L892">(Source)</a></p>
<p>#LoRaWAN runs neater on Apache #NuttX OS … After implementing Timers and Multithreading with NimBLE Porting Layer … No more sleep()!</p>
<p><a href="https://gist.github.com/lupyuen/cad58115be4cabe8a8a49c0e498f1c95">(Log)</a></p>
<h1 id="build-nimble" class="section-header"><a href="#build-nimble">6 Build NimBLE</a></h1>
<p>To build NumBLE Porting Layer on #NuttX OS we need to enable: 1⃣ POSIX Timers &amp; Message Queues 2⃣ Clock Monotonic 3⃣ Work Queues 4⃣ SIGEV_THHREAD</p>
<ul>
<li><a href="https://github.com/lupyuen/nimble-porting-nuttx"><strong>nimble-porting-nuttx</strong></a></li>
</ul>
<p>TODO33</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-config1.png" alt="" /></p>
<p>TODO14</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-config4.png" alt="" /></p>
<h1 id="sx1262-busy" class="section-header"><a href="#sx1262-busy">7 SX1262 Busy</a></h1>
<p>Heres how we check the SX1262 Busy Pin on #NuttX OS … By reading the GPIO Input</p>
<p>TODO49</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-gpio1.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/lora-sx1262/blob/lorawan/src/sx126x-nuttx.c#L184-L199">(Source)</a></p>
<h1 id="event-loop" class="section-header"><a href="#event-loop">8 Event Loop</a></h1>
<p>Heres our #LoRaWAN Event Loop for #NuttX OS … Implemented with NimBLE Porting Library … No more polling!</p>
<p>TODO54</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-npl1.png" alt="" /></p>
<p>TODO58</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run5a.png" alt="" /></p>
<h1 id="nonce" class="section-header"><a href="#nonce">9 Nonce</a></h1>
<p>Our #NuttX App resends the same Nonce to the #LoRaWAN Gateway … Which (silently) rejects the Join Request due to Duplicate Nonce … Lets fix our Random Number Generator</p>
<p>TODO34</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-chirpstack2a.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/b38434c3d27500444382bb4a066691e5">(Log)</a></p>
<p>#LoRaWAN gets the Nonce from the Secure Elements Random Number Generator … Lets simulate the Secure Element on Apache #NuttX OS</p>
<p>TODO51</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce2a.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/LoRaMac-node-nuttx/blob/master/src/mac/LoRaMacCrypto.c#L980-L996">(Source)</a></p>
<p>Heres how we generate #LoRaWAN Nonces on #NuttX OS … With Strong Random Numbers thanks to Entropy Pool</p>
<p>TODO53</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce6.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/LoRaMac-node-nuttx/blob/master/src/nuttx.c#L136-L153">(Source)</a></p>
<p>Our #NuttX App now sends Random #LoRaWAN Nonces to the LoRaWAN Gateway … And are happily accepted by the gateway! 🎉</p>
<p>TODO36</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce7a.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/8f012856b9eb6b9a762160afd83df7f8">(Log)</a></p>
<h1 id="random-number-generator" class="section-header"><a href="#random-number-generator">10 Random Number Generator</a></h1>
<p>For #NuttX Random Number Generator, select the Entropy Pool … To generate Strong Random Numbers for our #LoRaWAN Nonce</p>
<p>TODO35</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce4a.png" alt="" /></p>
<p>We enable the Entropy Pool in #NuttX OS … To generate Strong Random Numbers for our #LoRaWAN Nonce</p>
<p>TODO52</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce3a.png" alt="" /></p>
<h1 id="logging" class="section-header"><a href="#logging">11 Logging</a></h1>
<p>Our #NuttX App was too busy to receive the #LoRaWAN Join Response … Lets disable the logging</p>
<p>TODO62</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/8f012856b9eb6b9a762160afd83df7f8">(Log)</a></p>
<p>After disabling logging, our #NuttX App successfully joins the #LoRaWAN Network! 🎉 Now we transmit some Data Packets over LoRaWAN</p>
<p>TODO63</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx3.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/0d301216bbf937147778bb57ab0ccf89">(Log)</a></p>
<p>Our #LoRaWAN Gateway receives Data Packets from #NuttX OS! 🎉 The Message Payload is empty … Lets figure out why 🤔</p>
<p>TODO44</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-chirpstack5.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/0d301216bbf937147778bb57ab0ccf89">(Log)</a></p>
<h1 id="message-size" class="section-header"><a href="#message-size">12 Message Size</a></h1>
<p>Our #NuttX App sent an empty #LoRaWAN Message because our message is too long for LoRaWAN Data Rate 2 (max 11 bytes) … Lets increase the Data Rate to 3</p>
<p>TODO65</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx4a.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/5fc07695a6c4bb48b5e4d10eb05ca9bf">(Log)</a></p>
<p>Heres how we increase the #LoRaWAN Data Rate to 3 in our #NuttX App</p>
<p>TODO67</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx5a.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/lorawan_test/blob/main/lorawan_test_main.c#L57-L70">(Source)</a></p>
<p>#LoRaWAN Data Rate has been increased to 3 … Max Message Size is now 53 bytes for our #NuttX App</p>
<p>TODO37</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx7a.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/83be5da091273bb39bad6e77cc91b68d">(Log)</a></p>
<p>#LoRaWAN Gateway now receives the correct Data Packet from our #NuttX App! 🎉</p>
<p>TODO45</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-chirpstack6.png" alt="" /></p>
<p><a href="https://gist.github.com/lupyuen/83be5da091273bb39bad6e77cc91b68d">(Log)</a></p>
<h1 id="send-data" class="section-header"><a href="#send-data">13 Send Data</a></h1>
<p>Heres how we send a #LoRaWAN Data Packet on #NuttX OS … And validate the Packet Size before sending</p>
<p>TODO68</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx6.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/lorawan_test/blob/main/lorawan_test_main.c#L311-L339">(Source)</a></p>
<p>#LoRaWAN tested OK on Apache #NuttX OS … From #PineDio Stack BL604 @ThePine64 to RAKwireless WisGate … And back! 🎉</p>
<ul>
<li><a href="https://github.com/lupyuen/LoRaMac-node-nuttx"><strong>LoRaMac-node-nuttx</strong></a></li>
</ul>
<h1 id="whats-next" class="section-header"><a href="#whats-next">14 Whats Next</a></h1>
<p>TODO</p>
<p>In our next article well move on to <strong>LoRaWAN!</strong></p>
<p>(Which will be super interesting because of multithreading)</p>
@ -193,7 +344,7 @@ git submodule add --branch nuttx https://github.com/lupyuen/lora-sx1262 libsx126
</ul>
<p><em>Got a question, comment or suggestion? Create an Issue or submit a Pull Request here…</em></p>
<p><a href="https://github.com/lupyuen/lupyuen.github.io/blob/master/src/lorawan3.md"><code>lupyuen.github.io/src/lorawan3.md</code></a></p>
<h1 id="notes" class="section-header"><a href="#notes">3 Notes</a></h1>
<h1 id="notes" class="section-header"><a href="#notes">15 Notes</a></h1>
<ol>
<li>
<p>This article is the expanded version of <a href="https://twitter.com/MisterTechBlog/status/1473593455699841027">this Twitter Thread</a></p>
@ -237,148 +388,24 @@ git submodule add --branch nuttx https://github.com/lupyuen/lora-sx1262 libsx126
<p>It might! But first lets get LoRaWAN (and ST7789) running on PineDio Stack.</p>
</li>
</ol>
<p><img src="https://lupyuen.github.io/images/lorawan3-title2.jpg" alt="PineDio Stack BL604 RISC-V Board (left) talking LoRaWAN to RAKwireless WisGate LoRaWAN Gateway (right)" /></p>
<p>https://github.com/lupyuen/LoRaMac-node-nuttx</p>
<p>#LoRaWAN needs Real Time Clock and Non-Volatile Memory … Now porting to #NuttX OS 🤔</p>
<p>https://docs.google.com/spreadsheets/d/12EFS72JFjjuK-2yWQVYrImkUjyEA_iGlnsEu1d42r68/edit#gid=0</p>
<p>Fixing the missing references for #LoRaWAN on Apache #NuttX OS</p>
<p>Run Log: https://gist.github.com/lupyuen/b91c1f88645eedb813cfffa2bdf7d7a0</p>
<p>LoRa Frequency and Sync Word are OK … Lets fix the Device EUI and Join EUI for #LoRaWAN on #NuttX OS</p>
<p>TODO55</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run2a.png" alt="" /></p>
<p>https://github.com/lupyuen/LoRaMac-node-nuttx/blob/master/src/nuttx.c</p>
<p>#LoRaWAN on #NuttX OS: Lets stub out the functions for Non-Volatile Memory and Real Time Clock … And watch what happens 🌋</p>
<p>https://github.com/lupyuen/LoRaMac-node-nuttx/blob/master/src/peripherals/soft-se/se-identity.h#L100-L115</p>
<p>For #NuttX OS we hardcode the #LoRaWAN App Key … Into the “Soft” Secure Element</p>
<p>Run Log: https://gist.github.com/lupyuen/a8e834e7b4267345f01b6629fb7f5e33</p>
<p>#NuttX OS doesnt handle the Join Response from #LoRaWAN Gateway … Lets fix this</p>
<p>TODO56</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run3.png" alt="" /></p>
<p>Run Log: https://gist.github.com/lupyuen/a8e834e7b4267345f01b6629fb7f5e33</p>
<p>#LoRaWAN Gateway receives the Join Request from #NuttX OS … And accepts the Join Request! 🎉</p>
<p>https://github.com/lupyuen/incubator-nuttx-apps/tree/lorawan</p>
<p>https://github.com/lupyuen/incubator-nuttx/tree/lorawan</p>
<p>#LoRaWAN builds OK on #NuttX OS! 🎉 … Will it run? 🤔</p>
<p>https://lupyuen.github.io/articles/wisgate</p>
<p>Lets connect Apache #NuttX OS to a #LoRaWAN Gateway … RAKwireless WisGate D4H with ChirpStack</p>
<p>https://github.com/lupyuen/LoRaMac-node-nuttx/blob/master/src/peripherals/soft-se/se-identity.h#L65-L79</p>
<p>#LoRaWAN gets its Device EUI, Join EUI and App Key from the Secure Element … But since #NuttX doesnt have a Secure Element, we hardcode them in the “Soft” Secure Element</p>
<p>TODO61</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-secure1.png" alt="" /></p>
<p>TODO60</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-secure2a.png" alt="" /></p>
<p>Log: https://gist.github.com/lupyuen/d3d9db37a40d7560fc211408db04a81b</p>
<p>Our #NuttX App was waiting for the #LoRaWAN Join Request to be transmitted before receiving the Join Response … But because were polling SX1262, we missed the Join Response … Lets fix this with the multithreading functions from NimBLE Porting Layer</p>
<p>TODO57</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run4a.png" alt="" /></p>
<p>https://github.com/lupyuen/nimble-porting-nuttx</p>
<p>NimBLE Porting Layer is a portable library of Multithreading Functions … Weve used it for #LoRa on Linux and FreeRTOS … Now we call it from Apache #NuttX OS</p>
<p>https://github.com/lupyuen/lora-sx1262/blob/lorawan/src/sx126x-nuttx.c#L863-L892</p>
<p>Our #NuttX Background Thread handles the GPIO Interrupts (SX1262 DIO1) … By adding to the #LoRaWAN Event Queue</p>
<p>TODO48</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-gpio4a.png" alt="" /></p>
<p>TODO46</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-gpio2.png" alt="" /></p>
<p>https://github.com/lupyuen/lora-sx1262/blob/lorawan/src/sx126x-nuttx.c#L835-L861</p>
<p>We handle GPIO Interrupts (SX1262 DIO1) in a #NuttX Background Thread … Awaiting the Signal for GPIO Interrupt</p>
<p>TODO49</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-gpio1.png" alt="" /></p>
<p>TODO47</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-gpio3.png" alt="" /></p>
<p>https://github.com/lupyuen/nimble-porting-nuttx</p>
<p>To build NumBLE Porting Layer on #NuttX OS we need to enable: 1⃣ POSIX Timers &amp; Message Queues 2⃣ Clock Monotonic 3⃣ Work Queues 4⃣ SIGEV_THHREAD</p>
<p>https://github.com/lupyuen/lora-sx1262/blob/lorawan/src/sx126x-nuttx.c#L742-L778</p>
<p>SX1262 will trigger a GPIO Interrupt on #NuttX OS when it receives a #LoRa Packet … We wait for the GPIO Interrupt to be Signalled in a Background Thread</p>
<p>https://github.com/lupyuen/lora-sx1262/blob/lorawan/src/sx126x-nuttx.c#L184-L199</p>
<p>Heres how we check the SX1262 Busy Pin on #NuttX OS … By reading the GPIO Input</p>
<p>https://gist.github.com/lupyuen/cad58115be4cabe8a8a49c0e498f1c95</p>
<p>#LoRaWAN runs neater on Apache #NuttX OS … After implementing Timers and Multithreading with NimBLE Porting Layer … No more sleep()!</p>
<p>https://github.com/lupyuen/incubator-nuttx-apps/blob/lorawan/examples/lorawan_test/lorawan_test_main.c#L814-L857</p>
<p>Heres our #LoRaWAN Event Loop for #NuttX OS … Implemented with NimBLE Porting Library … No more polling!</p>
<p>TODO58</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run5a.png" alt="" /></p>
<p>TODO54</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-npl1.png" alt="" /></p>
<p>https://gist.github.com/lupyuen/b38434c3d27500444382bb4a066691e5</p>
<p>Our #NuttX App resends the same Nonce to the #LoRaWAN Gateway … Which (silently) rejects the Join Request due to Duplicate Nonce … Lets fix our Random Number Generator</p>
<p>https://github.com/lupyuen/LoRaMac-node-nuttx/blob/master/src/mac/LoRaMacCrypto.c#L980-L996</p>
<p>#LoRaWAN gets the Nonce from the Secure Elements Random Number Generator … Lets simulate the Secure Element on Apache #NuttX OS</p>
<p>TODO51</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce2a.png" alt="" /></p>
<p>https://github.com/lupyuen/LoRaMac-node-nuttx/blob/master/src/nuttx.c#L136-L153</p>
<p>Heres how we generate #LoRaWAN Nonces on #NuttX OS … With Strong Random Numbers thanks to Entropy Pool</p>
<p>TODO53</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce6.png" alt="" /></p>
<p>Log: https://gist.github.com/lupyuen/8f012856b9eb6b9a762160afd83df7f8</p>
<p>Our #NuttX App now sends Random #LoRaWAN Nonces to the LoRaWAN Gateway … And are happily accepted by the gateway! 🎉</p>
<p>TODO43</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-chirpstack.png" alt="" /></p>
<p>TODO36</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce7a.png" alt="" /></p>
<p>For #NuttX Random Number Generator, select the Entropy Pool … To generate Strong Random Numbers for our #LoRaWAN Nonce</p>
<p>TODO35</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce4a.png" alt="" /></p>
<p>We enable the Entropy Pool in #NuttX OS … To generate Strong Random Numbers for our #LoRaWAN Nonce</p>
<p>TODO52</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-nonce3a.png" alt="" /></p>
<p>Log: https://gist.github.com/lupyuen/8f012856b9eb6b9a762160afd83df7f8</p>
<p>Our #NuttX App was too busy to receive the #LoRaWAN Join Response … Lets disable the logging</p>
<p>TODO62</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx.png" alt="" /></p>
<p>Log: https://gist.github.com/lupyuen/0d301216bbf937147778bb57ab0ccf89</p>
<p>Our #LoRaWAN Gateway receives Data Packets from #NuttX OS! 🎉 The Message Payload is empty … Lets figure out why 🤔</p>
<p>TODO44</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-chirpstack5.png" alt="" /></p>
<p>TODO59</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-run1.png" alt="" /></p>
<p>Log: https://gist.github.com/lupyuen/0d301216bbf937147778bb57ab0ccf89</p>
<p>After disabling logging, our #NuttX App successfully joins the #LoRaWAN Network! 🎉 Now we transmit some Data Packets over LoRaWAN</p>
<p>TODO63</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx3.png" alt="" /></p>
<p>https://gist.github.com/lupyuen/5fc07695a6c4bb48b5e4d10eb05ca9bf</p>
<p>Our #NuttX App sent an empty #LoRaWAN Message because our message is too long for LoRaWAN Data Rate 2 (max 11 bytes) … Lets increase the Data Rate to 3</p>
<p>TODO65</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx4a.png" alt="" /></p>
<p>https://github.com/lupyuen/nimble-porting-nuttx/blob/master/porting/npl/nuttx/src/os_callout.c#L35-L70</p>
<p>NimBLE Porting Layer doesnt work for multiple Callout Timers on #NuttX OS, unless we loop the thread … Will submit a Pull Request to Apache NimBLE 👍</p>
<p>TODO42</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-callout.png" alt="" /></p>
<p>https://github.com/lupyuen/incubator-nuttx/blob/lorawan/drivers/ioexpander/gpio.c#L544-L547</p>
<h1 id="appendix-gpio-issue" class="section-header"><a href="#appendix-gpio-issue">16 Appendix: GPIO Issue</a></h1>
<p>Switching a #NuttX GPIO Interrupt Pin to Trigger On Rising Edge … Crashes with an Assertion Failure … Ill submit a NuttX Issue, meanwhile I have disabled the assertion</p>
<p>TODO50</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-int.png" alt="" /></p>
<p>https://github.com/lupyuen/lorawan_test/blob/main/lorawan_test_main.c#L311-L339</p>
<p>Heres how we send a #LoRaWAN Data Packet on #NuttX OS … And validate the Packet Size before sending</p>
<p>TODO68</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx6.png" alt="" /></p>
<p>https://gist.github.com/lupyuen/83be5da091273bb39bad6e77cc91b68d</p>
<p>#LoRaWAN Gateway now receives the correct Data Packet from our #NuttX App! 🎉</p>
<p>https://gist.github.com/lupyuen/83be5da091273bb39bad6e77cc91b68d</p>
<p>#LoRaWAN Data Rate has been increased to 3 … Max Message Size is now 53 bytes for our #NuttX App</p>
<p>TODO67</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx5a.png" alt="" /></p>
<p>TODO37</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-tx7a.png" alt="" /></p>
<p>https://github.com/lupyuen/lorawan_test/blob/main/lorawan_test_main.c#L57-L70</p>
<p>Heres how we increase the #LoRaWAN Data Rate to 3 in our #NuttX App</p>
<p>https://github.com/lupyuen/LoRaMac-node-nuttx</p>
<p>#LoRaWAN tested OK on Apache #NuttX OS … From #PineDio Stack BL604 @ThePine64 to RAKwireless WisGate … And back! 🎉</p>
<p>TODO45</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-chirpstack6.png" alt="" /></p>
<p>TODO14</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-config4.png" alt="" /></p>
<p>TODO33</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-config1.png" alt="" /></p>
<p>TODO34</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-chirpstack2a.png" alt="" /></p>
<p>TODO38</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-build2a.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/incubator-nuttx/blob/lorawan/drivers/ioexpander/gpio.c#L544-L547">(Source)</a></p>
<h1 id="appendix-callout-issue" class="section-header"><a href="#appendix-callout-issue">17 Appendix: Callout Issue</a></h1>
<p>NimBLE Porting Layer doesnt work for multiple Callout Timers on #NuttX OS, unless we loop the thread … Will submit a Pull Request to Apache NimBLE 👍</p>
<p>TODO42</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-callout.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/nimble-porting-nuttx/blob/master/porting/npl/nuttx/src/os_callout.c#L35-L70">(Source)</a></p>
<p><img src="https://lupyuen.github.io/images/lorawan3-title2.jpg" alt="PineDio Stack BL604 RISC-V Board (left) talking LoRaWAN to RAKwireless WisGate LoRaWAN Gateway (right)" /></p>
<p>#LoRaWAN on #NuttX OS: Lets stub out the functions for Non-Volatile Memory and Real Time Clock … And watch what happens 🌋</p>
<p>TODO39</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-build4a.png" alt="" /></p>
<p>TODO40</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-build5a.png" alt="" /></p>
<p>TODO41</p>
<p><img src="https://lupyuen.github.io/images/lorawan3-build1.png" alt="" /></p>
<p><a href="https://github.com/lupyuen/LoRaMac-node-nuttx/blob/master/src/nuttx.c">(Source)</a></p>
<p>#LoRaWAN builds OK on #NuttX OS! 🎉 … Will it run? 🤔</p>
<p><a href="https://github.com/lupyuen/incubator-nuttx-apps/tree/lorawan">NuttX Apps</a></p>
<p><a href="https://github.com/lupyuen/incubator-nuttx/tree/lorawan">NuttX OS</a></p>
</body>