Let's build an #IoT App with #ZigLang and #LoRaWAN ... To show that we can maintain and extend Complex IoT Apps with Zig!
https://github.com/lupyuen/zig-bl602-nuttx#convert-lorawan-app-to-zig
We take this #LoRaWAN App in C and convert to #ZigLang ... 700 Lines of C Code, no sweat!
https://github.com/lupyuen/zig-bl602-nuttx#convert-lorawan-app-to-zig
Here's how we import #LoRaWAN Library from C into #ZigLang ... Yep Zig understands C Header Files! 👍
https://github.com/lupyuen/zig-bl602-nuttx#convert-lorawan-app-to-zig
This is how we call the #LoRaWAN Library from #ZigLang
https://github.com/lupyuen/zig-bl602-nuttx#convert-lorawan-app-to-zig
#ZigLang Compiler will helpfully Auto-Translate our code from C to Zig ... Rewriting C to Zig gets so much easier 👍
https://github.com/lupyuen/zig-bl602-nuttx#auto-translate-lorawan-app-to-zig
Our #LoRaWAN App ... Original C code vs Auto-Translated #ZigLang code
https://github.com/lupyuen/zig-bl602-nuttx#auto-translate-lorawan-app-to-zig
Auto-Translating C to #ZigLang is not perfect (like for C Bit Fields) ... But we can fix it ourselves
https://github.com/lupyuen/zig-bl602-nuttx#opaque-type-error
#ZigLang Compiler can't Auto-Translate some tricky C Macros into Zig ... Here's a workaround
#ZigLang Compiler won't init this C Struct ... So we init the struct ourselves
https://github.com/lupyuen/zig-bl602-nuttx#struct-initialisation-error
After fixing the code, our #LoRaWAN #ZigLang App runs perfectly on Apache #NuttX RTOS! 🎉 (670 lines of Zig code!)
https://github.com/lupyuen/zig-bl602-nuttx#lorawan-zig-app-runs-ok
#ZigLang Compiler reveals fascinating insights about Safety Checks when it auto-translates C code to Zig ... Here's how it handles a potential Integer Overflow
Here's our #LoRaWAN App in C vs #ZigLang ... After some hand-scrubbing
https://github.com/lupyuen/zig-bl602-nuttx#compare-c-and-zig
Our #LoRaWAN Stack for #ZigLang is in C ... And that's perfectly OK!
https://lupyuen.github.io/articles/iot?2#lorawan-network-stack
Importing the #LoRaWAN Library from C into #ZigLang ... Piece of cake!
https://lupyuen.github.io/articles/iot?3#import-lorawan-library
How our #ZigLang App transmits a #LoRaWAN Packet
https://lupyuen.github.io/articles/iot?6#transmit-data-packet
#ZigLang's Auto-Translator reveals interesting differences between C and Zig
#ZigLang helpfully catches all kinds of Runtime Errors: Underflow, Overflow, Array Out-Of-Bounds, ...
Our #ZigLang App handles #LoRaWAN Events ... By calling NimBLE Porting Layer
https://lupyuen.github.io/articles/iot?12#appendix-handle-lorawan-events
#ZigLang supports Custom Panic Handlers
https://lupyuen.github.io/articles/iot?16#appendix-panic-handler
#ZigLang Compiler works as a Drop-In Replacement for GCC! Here's how we tested
https://lupyuen.github.io/articles/iot?17#appendix-zig-compiler-as-drop-in-replacement-for-gcc
#ZigLang Compiler can Auto-Translate our C Code into Zig
https://lupyuen.github.io/articles/iot?18#appendix-auto-translate-lorawan-app-to-zig
#ZigLang Compiler might stumble when importing C code ... Here's how we fix the Opaque Type error
https://lupyuen.github.io/articles/iot?19#appendix-opaque-type-error
Debug Logging in #ZigLang
https://lupyuen.github.io/articles/iot?7#logging