Mongoose a new way to program ESP8266

Mongoose a new way to program ESP8266

In previous blogs, I have used Arduine-IDE to develop code for the ESP8266. It was a nice and convenient way, suitable for me with a background in development. Recently I came across a new technology, that I wanted to give a try: Mongoose OS

Similar to my previous setup, I will be using a NodeMCU based on ESP8266 combined with a DHT22 sensor. I have wired the NodeMCU and DHT22 based on the following image:

Install Mongoose OS

Please install Mongoose OS based on the description provided by Mongoose OS.

Start Mongoose OS

Start Mongoose OS based on the instructions provided by them.

In my case I needed to run the following command from a Command-Line

psteiner$ ~/.mos/bin/mos

Your browser should start with the Mongoose OS User-Interface

Connecting Mongoose OS to your ESP8266 and flashing the ESP

Select the proper Port for your NodeMCU and connect Mongoose OS with your NodeMCU.

You can flash sample code to your ESP8266. Please do so, as we will be extending the sample code to do our bidding.

I will use the NodeJS based sample, but you can use the “C” demo as well.

Last thing to do is to connect the ESP8266 with your WiFi.

With the newly flashed firmware on the ESP8266 and the WiFi configured, you should see log-messages including your WiFi connection

[Dec 30 19:49:36.037] mgos_wifi_setup_sta  WiFi STA: Connecting to Steiner

as well as the ESP8266 creating and logging data

[Dec 30 19:52:06.776] Tick uptime: 150.851430 {"free_ram":36100,"total_ram":52032}
[Dec 30 19:52:07.776] Tock uptime: 151.851113 {"free_ram":36100,"total_ram":52032}
[Dec 30 19:52:08.776] Tick uptime: 152.851563 {"free_ram":36100,"total_ram":52032}

There is more features in the flashed code, but that is for you to discover!

Changing the Demo Code

As this demo is not about teaching NodeJS or ESP8266 programming, we will look into the basics of handling the Mongoose OS Web-UI.

To do this, we will stop the Blinking of the ESP8266 LED.

Make sure you are looking at the file fs/index.js

Find the following code segment and remove or comment it out

GPIO.set_mode(led, GPIO.MODE_OUTPUT);
let value = GPIO.toggle(led);

you will also have to adjust the following line, as value doesn’t exist anymore.

print(value ? 'Tick' : 'Tock', 'uptime:', Sys.uptime(), getInfo());

There are more lines of code covering the Blink-LED, but for this intro exercise, this should suffice.

After having changed the code, we obviously have to save it.

There are two options to update the code on the ESP8266, a slow and a faster one.

Let’s look at the faster one together, so you can find the other one yourself.

All you need to do is to upload the updated code to the ESP8266

In the Log-Window of Mongoose OS Web-UI you see the updated File being uploaded, and the ESP8266 being rebooted to start the new firmware.

Update ESP8266 Sample code

I have provided you with updates to the two needed source-files

they are updates to the ones from the sample and are extended by code needed to read the data from the DHT22 sensor and output this instead of free_ram and total_ram.

Next Step

In the next blog we will cover how to prepare Google Cloud IoT Core to interact with this new Sensor.

3 thoughts on “Mongoose a new way to program ESP8266

Leave a Comment

%d bloggers like this: