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
X.509
Certificate
Private
Key
6. 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 -b release https://github.com/cesanta/mongoose-os
7. 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
8. 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
9. 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
10. 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
12. 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
13. Exercise #2 (create AWS IoT Rule to publish to S3 bucket)
• Navigate to AWS IoT ⇒ Rules
• Click “Create a rule”
14. Exercise #2 (create AWS IoT Rule to publish to S3 bucket)
• Enter Name and Description (“Publish2S3”, “Send FreeRAM values to S3”)
• Define which attributes you would like to store
• Click “Add Action” and choose “Store messages in an Amazon S3 bucket”
15. Exercise #2 (create AWS IoT Rule to publish to S3 bucket)
• Create a new S3 bucket or use existing one (If creating use unique name)
• Create a new role “iotPublish2S3”
• Enter the key as shown
• Click “Add action”
16. Exercise #2 (create AWS IoT Rule to publish to S3 bucket)
• Click “Create Rule”
17. Exercise #2 (create AWS IoT Rule to publish to S3 bucket)
• Press the button on ESP32 few times
• Go to S3 ⇒ {your bucket}
• You should see number of files similar to this picture:
18. Exercise #3 (Shadow State sets LED)
In the mjs_base directory, copy over the Shadow code:
Ø cp ../mjs_aws_shadow/init.js fs/init.js
Ø edit fs/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
19. Exercise #3 (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: {}
20. Exercise #3 (Shadow State sets LED)
• Log in to your AWS IoT account and go to AWS IoT service page
• Click on Registry
• Select device
22. Exercise #3 (Shadow State sets LED)
• Pressing button on your ESP32 will toggle the LED and the Shadow state
23. 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