Mongoose OS on esp32

Heard about mongoose OS from http://tech.scargill.net/mongoose-os/ . Scargills blog is always worth a read if you are interested in sbc, iot, home automation and node-red.

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.

This sounded interesting, and seemed a middle way between the arduino and esp32-IDF routes of programing the esp32. Also as it is built with IOT in mind is a good place to learn a bit more.

Installed following https://mongoose-os.com/software.html

Tried

~/.mos/bin/mos

This launches a gui in a webpage. I could select the usb port that the esp32 was on, but when i tried to flash mongoose onto it I got:

E0614 19:52:33.535553   15390 ui.go:453] Calling: FS.ListExt
Server Error: {"error":"Device is not connected"}

The solution is to flash from the command line:

~/.mos/bin/mos flash mos-esp32

Much happier:

Fetching https://mongoose-os.com/downloads/mos-esp32.zip...
Loaded mjs_base/esp32 version 1.0 (20170614-125632/???)
Using port /dev/ttyUSB0
Opening /dev/ttyUSB0...
Connecting to ESP32 ROM, attempt 1 of 10...
  Connected
Running flasher @ 460800...
  Flasher is running
Flash size: 4194304, params: 0x0220 (dio,32m,40m)
Deduping...
   16320 @ 0x1000 -> 12288
   16384 @ 0x9000 -> 8192
  819824 @ 0x10000 -> 126976
  131072 @ 0x190000 -> 16384
Writing...
   12288 @ 0x1000
    4096 @ 0x8000
    8192 @ 0x9000
    8192 @ 0xd000
    4096 @ 0x10000
  122880 @ 0x20000
   16384 @ 0x1a2000
Wrote 176128 bytes in 3.93 seconds (349.73 KBit/sec)
Verifying...
   16320 @ 0x1000
    3072 @ 0x8000
   16384 @ 0x9000
    8192 @ 0xd000
  819824 @ 0x10000
  131072 @ 0x190000
Booting firmware...
All done!

Then go back to the gui using

~/.mos/bin/mos

for final configuration (like the ssid and password).

One of the examples is a mqtt example that publishes the sys.free ram to a mqtt feed when the boot button is pressed on the esp32. With a bit of digging I found ‘api_adc.js’ that acts as a wrapper for the adc api, so I could use the YL-83 rain sensor on pin 32.

load('api_config.js');
load('api_gpio.js');
load('api_mqtt.js');
load('api_sys.js');
load('api_adc.js');
load('api_grove.js');

GPIO.set_button_handler(0, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function() {
  let topic = Cfg.get('mqtt.user') + '/feeds/rain';
  //let message = JSON.stringify(Sys.free_ram());
  let message = JSON.stringify(ADC.read(32));
  let ok = MQTT.pub(topic, message, 1);
  print('Published:', ok ? 'yes' : 'no', 'topic:', topic, 'message:', message);
}, null);

You can see the feed at after testing with drops of water.

https://io.adafruit.com/BrianDegger/feeds/rain