|
|
Subscribe / Log in / New account

Mongoose OS for IoT prototyping

September 12, 2017

This article was contributed by Nur Hussein

Mongoose OS is an open-source operating system for tiny embedded systems. It is designed to run on devices such as microcontrollers, which are often constrained with memory on the order of tens of kilobytes, while exposing a programming interface that provides access to modern APIs normally found on more powerful devices. A device running Mongoose OS has access to operating system functionality such as filesystems and networking, plus higher-level software such as a JavaScript engine and cloud access APIs.

Mongoose OS is not meant to compete in the solution space occupied by Linux and its ilk; instead it is a cross-platform Internet of Things (IoT) development toolkit for tiny devices that aren't powerful enough to run a full-featured operating system. Unlike embedded operating systems like Zephyr, Mongoose OS does not implement the entire OS stack. Instead, it relies on either the underlying hardware's SDK or a small realtime operating system like FreeRTOS to provide most of the low level access. It builds upon the underlying OS primitives to provide higher-level APIs for programmers that the embedded operating systems don't normally provide.

There is a wide range of embedded hardware specifically for IoT use; software toolkits to run on them include ARM Mbed and Arduino. Both are open-source toolkits but they are intrinsically tied to their respective hardware platforms. Mongoose OS is cross-platform and delivers a consistent programming interface across all of the different devices it supports. The goal of Mongoose OS is to give IoT developers as much software scaffolding as possible to rapidly prototype applications for their platforms. This includes support for over-the-air (OTA) updates, encryption, remote management, as well as easy-to-use APIs to control IoT devices, to get data from them, and to funnel that data to a cloud-backed service.

Once in the cloud, the data can be processed by analytics or used by any other web service. The remote procedure call (RPC) features accessible via a web services API makes devices running Mongoose OS controllable via the cloud. One can imagine industrial or scientific installations operating an array of sensors and other data collecting devices run by microcontrollers that pump the data they collect into the cloud to be retrieved or analyzed by users. Mongoose OS is one option to build the layer of software that is required to have an interface between the hardware with its users.

Architecture

Mongoose OS provides its own networking and some peripheral drivers as well as higher-level abstractions for IoT programming. There is a network library, a filesystem layer, and an API to access hardware-specific functionality such as GPIO, I2C, SPI, UART, and others. There is also a library to access cloud-based services such as Amazon AWS IoT Platform, Microsoft Azure IoT suite, Google IoT Core, Adafruit IO, Samsung ARTIK Cloud, and Blynk. You can make generic HTTP calls to implement an API for other web services. A virtual filesystem layer allows the mounting of different filesystems, but currently the only supported one is the SPI Flash File System (SPIFFS), which is a file system intended for flash-memory-based storage.

Mongoose OS can run on ESP32 and ESP8266 microcontrollers by Espressif Systems or the Texas Instruments CC3200. There is partial support for nRF52 by Nordic Semiconductor and the STM32 by STMicroelectronics, and a port for the Texas Instruments CC3220 is almost complete. On the ESP32 and CC3200, Mongoose OS runs on top of FreeRTOS, which provides task scheduling and primitives such as semaphores and queues. On the more resource-constrained ESP8266, Mongoose OS uses the SDK provided by Espressif Systems.

Embedded together with the system is a tiny JavaScript engine called mJS that implements a subset of the language; API calls can be made from C, JavaScript, or a mix of both. A developer can directly call C functions from JavaScript using the foreign function interface call, ffi(). The limitations of mJS are that there is no standard library, closures, exceptions, or Unicode strings, and there are some syntax restrictions. However, the JSON.parse() and JSON.stringify() calls are available, which is handy for JSON object manipulation that is often needed when talking to web services.

Mongoose OS supports SPI flash encryption for securing IoT devices. On the ESP32, Mongoose OS can take advantage of the built-in encryption hardware. It also supports the ATECC508A crypto chip, which can be added to a device. These mechanisms allow the encryption of the flash memory to prevent access to any of the data in the event an attacker has physical access to the devices. There is an RPC mechanism for OTA updates of the firmware; device developers can configure their own server to update from.

Libraries and apps

There is a repository of libraries provided by the Mongoose OS developers that a user can download from to help build their application. Using these libraries, a program can write to or read from hardware connections such as GPIO pins and route the data over the network. There is a compatibility layer for the use of Arduino libraries, which should give users more options.

An app is a Mongoose OS program built and flashed onto the device. There is a repository of community-contributed apps for reference. Most of them are sample applications that show how to use a certain library or hardware feature. For example, one clever hack is the automatic heater control built using a NodeMCU running Mongoose OS, I2C temperature sensors, and an AWS account.

Licensing

Mongoose OS is an open-source product of Cesanta, a company founded by Sergey Lyubka in Ireland to develop and market the operating system. There are two classes of Mongoose OS users: hobbyists and commercial customers. Hobbyists will find a fun and easy operating system to bootstrap their home IoT projects quickly. The system is available under the terms of the GPLv2; the company asserts that user programs that link to it also need to be released under a GPLv2-compatible license. However, if there are users that prefer a different licensing model, Cesanta offers alternative arrangements for paying customers. There is an open-source community around Mongoose OS, but all external code contributors must grant Cesanta the right to relicense the code.

Trying it out

Mongoose OS is available from the project's download page, which offers a tool called mos to build and deploy the system on the user's embedded hardware. On Ubuntu, a convenient PPA is available for version 16.04 and up. However to run the OS itself, one of the supported boards is required as there is no emulator that works with it.

To try out Mongoose OS, I purchased a ESP8266-powered NodeMCU. It is a microcontroller that includes an on-board WiFi chip. I connected it via USB to my Ubuntu machine and it was detected as a serial USB device. I added the Mongoose OS PPA and used the package manager to install the mos management utility, which allows a user to flash a supported hardware module with Mongoose OS; the package also includes some development tools.

Running mos brings up a web interface on the default system browser that is connected to a tiny web server that the management tool runs on your host machine. The web interface can be used to set up the connected device, which is a simple three-step process: specify the serial USB interface it is connected on, identify the attached chip and flash the OS image, and specify the wireless access point information for the device to connect to.

After the initial set up, the web interface gives the user an integrated development environment (IDE) that allows projects to be created, to import applications or libraries, and to be built and flashed onto the device. I used the Blynk sample app from the repository to try out the cloud features. Blynk is a cloud service that allows a user to control a network-connected embedded system via a proprietary mobile app, which is available for free download but has in-app purchases of certain features. However, the Blynk library and sample app on the device side is open source; flashing it to the device was a straightforward process. Using the mobile app, I could turn on and off the LED on the board. It was a quick way to prototype an IoT application; a user can be up and running in minutes.

Conclusion

For anyone tinkering with Internet of Things programming, Mongoose OS takes the hassle out of interfacing with the low-level hardware for some tiny embedded devices. The range of hardware it supports is limited, but the boards that it does support are quite popular. The repository of apps and libraries for Mongoose OS is also still in its infancy. The features roadmap does include more hardware support, better cloud integration, and the ability to mount SD cards. Being able to set up and program an IoT device easily should be an attractive option for hobbyists and commercial developers looking for rapid prototyping.

[I would like to thank the Mongoose OS developers and community for help in clarifying aspects of the project.]

Index entries for this article
GuestArticlesHussein, Nur


to post comments

Mongoose OS for IoT prototyping

Posted Sep 12, 2017 12:48 UTC (Tue) by bradfa (subscriber, #71357) [Link] (1 responses)

The article makes clear that applications which link against Mongoose OS should be compatible with the GPLv2 (I would expect they would *HAVE* to be GPLv2 as they would become "infected," but this is not my point) but in my experience with silicon vendors is that the code they release to support a given microcontroller is almost never GPL licensed yet Mongoose OS requires you to use some kind of vendor provided "SDK."

Isn't there a clear license conflict of using a GPLv2 "OS" on top of vendor provided likely-non-GPL licensed hardware support code?

Mongoose OS for IoT prototyping

Posted Sep 12, 2017 13:05 UTC (Tue) by mfuzzey (subscriber, #57966) [Link]

IANAL but as I understand it the hardware support code does not have to be licensed under the GPL but under a license that is *compatible* with the GPL.

The BSD 3 clause license is compatible for example.

https://www.gnu.org/licenses/license-list.html#GPLCompati...

And, even if the licenses are incompatible that is only a problem when *distributing* binaries that run on the devices.

Mongoose themselves aren't doing that.

Device builders using Mongoose may have a problem depending on who gets the devices (custom devices for internal use probably OK, publicly distributed devices probably not). Which may be why they give an option to buy a non GPL version...

Mongoose OS for IoT prototyping

Posted Sep 12, 2017 17:20 UTC (Tue) by SEJeff (guest, #51588) [Link] (3 responses)

MongooseOS is great stuff, but PlatformIO is a similarly targetted embedded platform with a bit more permissive (Apache 2) License. I've played with both on the esp8266 and esp32 series microcontrollers to build little IoT (the S is for security) devices.

http://platformio.org/

Mongoose OS for IoT prototyping

Posted Sep 12, 2017 19:05 UTC (Tue) by zdzichu (subscriber, #17118) [Link] (1 responses)

(the S is for security)

Interesting (telling?) to see that you left ‘S‘ out of ‘IoT‘..

Mongoose OS for IoT prototyping

Posted Sep 12, 2017 20:11 UTC (Tue) by SEJeff (guest, #51588) [Link]

That is a long running joke in the infosec community about IoT I always laugh at because it is true. If you follow Matthew Garrett any and watch him own device after device you'll realize it currently is where computing was in the 90s when it comes to security.

Mongoose OS for IoT prototyping

Posted Sep 21, 2017 10:01 UTC (Thu) by sergey.lyubka (guest, #118679) [Link]

Mongoose OS and Platformio are very different.

Platformio is a build system and a library manager. It does not provide it's own functionality, it wraps an existing toolchain in an easy to use shape.

Mongoose OS, however, DOES provide tons of functionality on top of the native SDK. For example, an integration with major cloud providers like AWS IoT and Google IoT Core, the configuration subsystem, JavaScript engine for prototyping, etc etc - something that is completely out of scope of PlatformIO.

There is a bit of overlap between the two - because Mongoose OS also wraps a native toolchain into an easy to use build system. Despite this overlap, Mongoose OS and Platformio are totally different things, don't mix the two.

Mongoose OS for IoT prototyping

Posted Oct 11, 2017 18:36 UTC (Wed) by xxiao (guest, #9631) [Link]

The fork civetweb is MIT-licensed.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds