Mongoose OS

Mongoose OS is an open source Operating System for the IOT, supporting ESP32, ESP8266, STM32, TI CC3200 (Amazon AWS IoT integrated). Code in C or JavaScript.  Time to give it a go!

It has been quiet here in the cave this week because, after a winter of sitting on my bum programming, I decided to do some work involving bags of sand and large paving tiles. Needless to say after a day of that, I was out of action for another day.  I’m still walking around very carefully in case I’ve torn something inside – but that didn’t dent my enthusiasm this morning when I checked my diary which said I had promised to give Mongoose OS a go.

So the context for this is ESP8266 – as a veteran C programmer who has recently taken on Node-Red like a new religion, I’m starting to really like programming in Javascript. Up to now,  the interpreted languages I’ve seen for the ESP8266 seem to eat up all the RAM – or have other limitations – so I keep looking. I played with another Javascript last week which seemed to have very little storage for programs…and marked Mongoose down to see if it was any good.

So – Mongoose – on a Windows 10 PC at least (they support other operating systems but I only have the one), you go to their site and download a program called MOS.EXE.   I put it on my desktop.  It wants a folder for its stuff so I made one on the desktop called “mos”.  You may choose to do things differently.

I followed the instructions after telling it what chip I’m using… from the command line on the desktop (don’t worry this is not command line stuff generally)

mos init --arch esp8266

So that worked and created some files and directories under the mos directory I had manually added. Note that (for reasons that escape me) the name “esp8266” etc needs to be in lower case.

Next job was to run mos.exe with no parameters – this would bring up a web interface – from where I could pick a port for my FTDI which was sitting there with an ESP-12 board hanging on the end of it waiting to be lobotomised.

Well, that didn’t work, I tried all sorts to no avail until I tried contacting the author and in suggesting a debug he showed a command line with the port number on it.

Following their instructions but with a port number mentioned I blew the boot code onto the chip.

from the mos directory:

..\mos --port COM4 flash

In my case when doing the above I held GPIO0 low on reset to put the board into programming mode – it may be that whatever board you are using handles that using DTR… which Mongoose supports – kind of like the Arduino IDE does.

Then I ran the MOS utility from the command line (see below) WITH the port number and lo and behold the web page came up – talked to the board and I was up and running..

..\mos -–port COM4 ui

I realised looking at the web page console log messages that this was now working – but of course it did not know about my WIFI – I broke out of that command line and….

mos --port COM4 wifi mywifiname mywifipass

That sorted THAT out … back to the UI – as you can see despite referring to the wrong PORT – the UI was indeed talking to the board.

Mongoose

From there on it was plain sailing – I tried their example of a button press triggering an MQTT message… realising there was no reference to my MQTT broker in their script – in “prototyping mode”  I hit the configuration tab in the web UI and in the middle of THAT… was the MQTT setup.

No reference to ports so I put my MQTT address as “192.168.1.19:1883” – added username and password and saved the config – the UI uploaded that to the board and rebooted it. I could see in the console message that all was working well.

Here it is from boot upwards  - I’ve bolded up bits you might find interesting including the considerable amount of RAM left! Their example button used GPIO0 – I changed it to GPIO2. Looks like it knows about the time as well.

 ets Jan  8 2013,rst cause:1, boot mode:(3,0)

load 0x40100000, len 1720, room 16 
tail 8
chksum 0x56
load 0x3ffe8000, len 784, room 0 
tail 0
chksum 0x61
csum 0x61    u  jUJ B  TTTTj-kVVU   U (TT U    U     TT U+UZ I U TT U UT  E  ]Q  u M, V      K    u  V UP        o  r  o|   l  $`   s p   mode :
esp_mgos_init2       mjs_base 1.0 (20170421-141840/???)
esp_mgos_init2       Mongoose OS Firmware 2017042114 (20170421-141840/???)
esp_mgos_init2       SDK 2.0.0(656edbf), RAM: 51984 total, 51068 free
esp_print_reset_info Reset cause: 4 (soft reset)
fs_momode : sta(18:fe:34:d2:3a:a0)
add if0
unt             Mounting FS: 131072 @ 0xdb000
mgos_sys_config_init MAC: 1AFE34D23AA0
mgos_sys_config_init WDT: 30 seconds
mgos_wifi_set_mode   WiFi mode: STA
mgos_wifi_setup_sta  WiFi STA: Connecting to wififorus
mgos_i2c_create      I2C GPIO init ok (SDA: 12, SCL: 14)
mgos_sys_config_init HTTP server started on [80]
mg_rpc_channel_mqtt  0x3ffeff8c esp8266_D23AA0/rpc/#
mg_rpc_channel_uart  0x3fff002c UART0
Flash button is configured on GPIO pin  2 
Press the flash button now! 
mgos_app_init        mJS memory stat: before init: 46872 after init: 45920 after init.js: 41348
mgos_init            Init done, RAM: 41348 free, 39184 min free
scandone
aid 31
cnt 
_wifi_on_change_ Wifi: connected
ip:192.168.1.38,mask:255.255.255.0,gw:192.168.1.1
mgos_wifi_on_change_ WiFi: ready, IP 192.168.1.38, DNS 208.122.23.23
mqtt_global_reconnec MQTT connecting after 1859 ms
mgos_sntp_query      SNTP query to pool.ntp.org
mgos_sntp_ev         SNTP reply from 195.43.138.123: time 1492863022.756811, local 11.453939, delta 1492863011.302872
mqtt_global_connect  MQTT connecting to 192.168.1.19:1883
mgos_mqtt_ev         MQTT Connect (1)
mgos_mqtt_ev         MQTT CONNACK 0
mgos_mqtt_ev         Subscribing to 'esp8266_D23AA0/rpc'
mgos_mqtt_ev         Subscribing to 'esp8266_D23AA0/rpc/#'
pm open,type:2 0

I ran their button_mqtt example with this setup – worked a treat as I could see on the console log and also on my MQTT client set up to monitor this board.

Is any of this any use? After all we can program these boards in Arduino IDE or in C using the SDK and you can write BIG programs in C without worrying too much about storage?

Well, I’m only at the start of this but if you look at their site it looks like they handle OTA, temperature sensors and other stuff already and once you get past the hurdle I had (you may not have any of the problems I had getting started) – it takes seconds to try a sample program and if you are comfortable with Javascript – you might find this useful.

Couple of things – I tried disconnecting and reconnecting the MQTT broker – the board performed perfectly, I did NOT  try disconnecting and reconnecting the WIFI. Also there is only one access point name – a backup one would be nice… also I note that I2C is set up automatically on GPIO12 and GPIO14, so not as flexible there as doing your own thing in C – however – this is about ease of use if you’re into Javascript -  so this is not a definitive “yes this is a winner” but more just an introduction.  Comments welcome.

The ESP32 update 05/MAY/2017: I received a note to confirm that the MOS.EXE program should be placed in \WINDOWS directory which saves worrying about where it is – unusual – however, it works – along with confirmation that the name of the system (esp8266, esp32 etc) has to be in lower case.

And at that point my ESP32 board arrived from China.  On power up a red light came on and that was about it – two buttons (reset (EN) and program)  - all for something like £6 – I always said I would not touch the ESP32 until it came down in price – well, now it has.

So as my first step into using this device – I tried Mongoose. With MOS moved to Windows – and with an empty \users\peter\desktop\mos directory – I moved into that directory and issued the commands:

mos init –-arch esp32

mos build

mos –-port COM6 flash

All went swimmingly well – after attempt 4 of 10 and without me pressing any buttons – the board flashed up, no problem.

At this point it was time to try the gui

mos –-port COM6 ui

By this time the EXE program was already out of date – so I loaded another copy into Windows, overwriting the original – and tried again.

Sure enough the web interface came up and THIS time spotted COM6 immediately. I set up the WIFI, selected the button/MQTT example and lo and behold I had a working program on the ESP32 with an amazing 177k of free heap !!! Well, not quite – because the default button is set to button 0, which as we all know on the ESP8266 – is GPIO0 and that’s where I enter a brave new world – I haven’t a CLUE what button 0 is on the ESP32. Certainly, P0 which, according to imagery on Google is indeed GPIO0, wasn’t having it.

Then I realised the example program was supposed to start by declaring which pin is the button pin and also announcing that a message had been published to MQTT –  and indeed after a couple of updates, by 5th of May I could get the software to react to a button press and send an MQTT message.  So very much to learn but i have made contact with Sergey Lyubka of Mongoose – and he’s now aware of the issues I’ve had – expect more updates soon. This looks well worth progressing.

Facebooktwittergoogle_pluspinterestlinkedin

14 thoughts on “Mongoose OS

  1. Looks interesting Pete.

    Have you also taken a look at ESPeasy @ http://www.letscontrolit.com ?. It supports tons of sensor, ota, has built in rules and is Arduino based.
    I tend to flash all my modules with this now. Use Openhab version of mqtt for generic mqtt brokers.

    1. Hi Tony - most of these systems are in development and are fairly basic. I'm merely experimenting to see which are most likely to succeed.

      For my own control at home in the UK and here in Spain, I mostly I use my own software http://tech.scargill.net/blowing-the-home-control-2016-code/. all under Node-Red control. I also use Tasmota for the Sonoff devices mainly as that is where his focus is and he can manage OTA on limited FLASH devices (if they'd put 4MB of FLASH in the Sonoffs I'd use my own software).

      As a reminder, this works on the ESP8266, has a Node-Red node to work with it and can control Dallas chips, DHT11 and DHT22, has digital inputs and outputs as well as the analog input, runs relays, LEDS, RGB LEDs (both serial and PWM offering eye-compensated colour and hue control), BMP280 and BME280, Seed OLED, PCA9685 PWM, ADS1115, GY30, Hitachi displays, port expansion and a lot more as well as working with Nextion displays and handling two access points with automatic fallover and unlike the general ESP-Arduino software, for storage of data it uses multiple copies for failure recovery. All of that is detailed in the blog here with articles covering the development of this as it happened.

      However, occasionally it pays to look up and see what others are up to and that is why I'm having a look at Mongoose. Up to now I've found only limited examples but I'm hoping that people will write in to show me where all the other examples are hiding. Meanwhile of course I keep finding ways to improve my setup such as the new Amazon Polly which I'm writing about as we speak.

      Someone pointed me to ESPEasy some time ago and while it offers a few ready-programmed peripherals there is little there to to attract me right now.

      I do like the idea of programming in Javascript instead of C, though I suspect that either RAM or FLASH will ultimately become a bottleneck - too early to tell with Mongoose - it does however raise the prospect of easy initial entry into the world of the ESP32 and I have some of these on the way from China right now - so worth more than a glance perhaps.

        1. its is good that there are a number of devs working on it now. The guys producing plugins are also very active.

          I developed my own code a couple? of years ago for my "IoTBox" but once the programming novelty wears off I found it was easier to use this :-).

          Javascript on the esp does look interesting though!.

          (Pete - I have used your Homecontrol code as well - thanks for making it!. I noticed on Letscontrolit that someone has used your nextion board and written a module for it)

  2. I found it a quick way to get one's feet wet with a ESP32. All the examples I tried ran nicely. However, the MQTT Sub example kept disconnecting.
    I let it send random ADC reads to my MQTT server every 5 seconds for two days without a hitch.

    1. That's encouraging, Bruce, looking forward to getting my ESP32 in the post... worrying however about the disconnects. Do let us know if you find a reliable way to stop that - absolutely no use unless it is completely reliable.

      1. {
        "clean_session": true,
        "client_id": "esp32",
        "enable": true,
        "keep_alive": 60,
        "pass": "",
        "reconnect_timeout_max": 60,
        "reconnect_timeout_min": 2,
        "server": "192.168.11.52:1883",
        "ssl_ca_cert": "",
        "ssl_cert": "",
        "ssl_cipher_suites": "",
        "ssl_key": "",
        "ssl_psk_identity": "",
        "ssl_psk_key": "",
        "user": "",
        "will_message": "",
        "will_topic": ""
        }
        mqtt_global_connect MQTT connecting to 192.168.11.52:1883
        mgos_mqtt_ev MQTT Connect (0)
        mgos_mqtt_ev MQTT Disconnect
        mqtt_global_reconnec MQTT connecting after 14515 ms
        mqtt_global_connect MQTT connecting to 192.168.11.52:1883
        mgos_mqtt_ev MQTT Connect (0)
        mgos_mqtt_ev MQTT Disconnect
        mqtt_global_reconnec MQTT connecting after 29763 ms
        mgos_fs_get_handler Sending conf0.json
        mqtt_global_connect MQTT connecting to 192.168.11.52:1883
        mgos_mqtt_ev MQTT Connect (0)
        mgos_mqtt_ev MQTT Disconnect

        My MQTT test server is running on the 192.168.11 segment with no passwords or other security. Strictly for in house testing.
        Other clients are subscribed without issue.

        1. Thank you. We were testing agains AWS IoT, Hive MQ, test.mosquitto.org, Google MQTT servers. No issues.

          What server software you're using, and what MQTT protocol version?

          Actually, I suggest starting a thread at forum.mongoose-os.com.

  3. I've been playing with these on and off.
    https://learn.sparkfun.com/tutorials/getting-started-with-the-tessel-2
    https://tessel.io/
    "It runs JavaScript and supports npm, which means scripts to control it can be built with Node.js."

    Whilst playing with it, I got introduced to Atom and Platformio, which also works great for Arduino code development - check this out
    https://www.youtube.com/watch?v=EIkGTwLOD7o

    In other works, the same IDE experience for all devices and differing languages - I know its not Mongoose, but just another take on things "dev"

Leave a Reply

Your email address will not be published. Required fields are marked *