Using zig for a lightweight embedded-mobile-connectivity framework

i spent quite a few years perfecting an embedded-mobile-connectivity framework, in which popular handheld devices running android or iOS could communicate wirelessly with resource-constrained MCUs… depending upon the actual MCU and its peripherals, the wireless transport could be BLE, NFC, Wifi, or a proprietary radio; the framework also supports a “wired” wireless link using a UART, for instance…

porting the embedded side of this stack to zig should be relatively straightforward for me, given that i plan to leverage the Zig•EM framework introduced here… where i’m seeking some guidance is how to approach the mobile side of the stack…

in my past life, this clearly required quite of bit of low(er)-level android (java/kotlin) or iOS (objective-c/swift) code to interact (say) with the mobile device’s bluetooth radio… and aside from this sort of code, there was a measure of link-independent middleware serving as a peer to similar code on the embedded device… here too, the same logic was expressed in different languages…

i eventually start exploring a variety of “write-once” mobile frameworks, many of which were based on HTML5… the UI itself was a little klunky – but at least the underlying headless logic was only coded once (in javascript)…

more recently, i started playing with react/JS (and its adaptation for mobile devices)… in this case, i “upgraded” to TypeScript and had good IDE support through vscode…

my immediate use-case has a VERY minimal UI – basically a “console output” widget with a Reset, Start, and Stop button which controls what is effectively a command-line app that uses the framework to interact with some peripheral HW…

so now, let’s assume that this underlying command-line app were written in zig – with some obvious binding to my user-facing console widget… is this a web-assembly??? and if so, can it call native OS routines for accessing the radio??? does my app run “natively” or within some sandboxed browser???

does anyone have experience in writing “headless” zig code targeting mobile devices, or at least have some suggestions that could point me towards a viable solution??? :pray:

2 Likes

On most mobile devices, nearly everything is sandboxed. web assembly typically is running in a browser (possibly an embedded one), and even more sandboxed. Interfacing with hardware is usually highly restricted in these constrained environments, and very specific to the OS, so I’m not seeing the benefit of web assembly, whose strength is portability. For this purpose, I’d look to building a module accessed via C FFI, and call the OS via it’s native API, and make the UI in whatever the system-preferred UI toolkit is for your mobile device. This imposed the fewest layers between your code and the functionality you’re wanting to access.

But don’t take my comment too seriously. I haven’t done any mobile dev yet. Targeting mobile platforms is still very immature in Zig.