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 – 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.
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  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 126.96.36.199 mqtt_global_reconnec MQTT connecting after 1859 ms mgos_sntp_query SNTP query to pool.ntp.org mgos_sntp_ev SNTP reply from 188.8.131.52: 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?
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 –-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.