This document summarizes a webinar about using the ESP32 microcontroller with AWS IoT and Mongoose OS. It introduces ESP32 and Mongoose OS, then describes two exercises - publishing button presses to AWS IoT and using AWS IoT shadow state to control an LED. Attendees are encouraged to try the examples and follow up with additional Mongoose OS tutorials and videos.
3. Espressif
Company behind popular ESP8266 and ESP32 modules
• ESP32:
• 240 MHz dual core Tensilica LX6 MCU (600 DMIPS)
• Integrated 520 KB SRAM
• Integrated 802.11BGN HT40 Wi-Fi transceiver
• Integrated dual mode Bluetooth (classic and BLE)
• 16 MByte flash
Find out more at https://www.espressif.com
Espressif and AWS are co-sponsoring this workshop
4. Cesanta Mongoose OS (mongoose-os.com)
• Hardware agnostic: ESP32, ESP8266, TI CC3200, STM32 and others
• Secure: SSL/TLS, Microchip ATECC508A crypto-chip support, ESP32
encrypted flash support
• Develop in C or JavaScript, or both
• Networking: MQTT, WebSocket, COAP, HTTP/ HTTPS and other
• Mongoose Embedded Web Server and Networking Library
5. The power of the ESP32
with AWS IoT
X.509
Certificate
Private
Key
6. Follow along (for a limited time only)...
http://cowbelle.xyz/iotloftguide
7. Prerequisites
• AWS CLI configured with valid credentials in the AWS account that
you intend to use
http://docs.aws.amazon.com/cli/latest/userguide/installing.html
• ESP32 Dev board
• A (good!) USB cable to connect the ESP32 board to your computer
• mos – The Mongoose OS flashing tool. Download at
http://www.mongoose-os.com
• git clone of the Mongoose OS repository from GitHub:
Ø git clone https://github.com/cesanta/mongoose-os
8. Let’ Get Started
• Plugin in the USB cable to your laptop and the ESP32
• The LED module will blink
Start Mos Console:
Ø mos console
You should see:
Using port /dev/cu.SLAB_USBtoUART
Tock uptime: 8.25607 RAM: 166700
Tick uptime: 9.25616 RAM: 166700
9. Exercise #1 (publish button presses to AWS IoT)
Once you clone git repo, change directory to:
Ø cd mongoose-os/fw/examples/mjs_base
Then execute:
Ø mos build --arch esp32
Ø mos flash
Ø mos wifi SSID PASSWORD
Ø mos aws-iot-setup --aws-region REGION --aws-iot-policy
mos-default *
* mos-default is demo quite permissive policy. Please use more restrictive policies in production!
Change the value of highlighted values to reflect your setup
LED will stop blinking
10. Exercise #1 (publish button presses to AWS IoT)
Start mos console:
Ø mos console
You should see:
Using port /dev/cu.SLAB_USBtoUART
Tock uptime: 8.25607 RAM: 166700
Tick uptime: 9.25616 RAM: 166700
Tock uptime: 10.2566 RAM: 166700
Published: yes topic: /devices/esp32_xxx/events message:
{"free_ram":166632,"total_ram":0}
I (13755) wifi: pm start, type:0
11. Exercise #1 (publish button presses to AWS IoT)
• Log in to your AWS IoT account and go to AWS IoT service page
• Click on Test
13. Exercise #1 (publish button presses to AWS IoT)
• Pressing button on your ESP32 will publish free RAM to the MQTT topic
/devices/esp_XXX
/devices/esp_XXX
14. Exercise #2 (Shadow State sets LED)
In the mjs_base directory, copy over the Shadow code:
Ø cp ../mjs_aws_shadow/init.js fs/init.js
Ø edit fw/init.js and change GPIO to:
Ø // TODO: support other platforms
Ø let LED_GPIO = 5;
From mjs_base directory execute:
Ø mos build --arch esp32
Ø mos flash
Ø mos wifi SSID PASSWORD
Ø mos aws-iot-setup --aws-region REGION --aws-iot-policy
mos-default
15. Exercise #2 (Shadow State sets LED)
Start mos console:
Ø mos console
You should see when you press the button:
[Jul 11 18:05:18.108] Click! Updated: true
[Jul 11 18:05:18.120] mgos_aws_shadow_ev Update: {"state":
{"desired":{"ledOn":false,"foo":2}}, "clientToken": "d7d06332"}
[Jul 11 18:05:18.213] mgos_aws_shadow_ev Version: 5 -> 6 (5)
[Jul 11 18:05:18.225] Event: 3 (UPDATE_ACCEPTED)[Jul 11 18:05:18.235]
mgos_aws_shadow_ev Version: 6 -> 6 (7)
[Jul 11 18:05:18.246] Event: 5 (UPDATE_DELTA)
[Jul 11 18:05:18.252] Reported state: {}
16. Exercise #2 (Shadow State sets LED)
• Log in to your AWS IoT account and go to AWS IoT service page
• Click on Registry
• Select device
18. Exercise #2 (Shadow State sets LED)
• Pressing button on your ESP32 will toggle the LED and the Shadow state
19. Follow up steps
Go to https://mongoose-os.com/#videos
Follow the examples:
• Internet button
• Smart heater
• ECC508A crypto-element
Cesanta is running a Give Away
https://mongoose-os.com/awsloft