ESP8266 UART to Cloud Getting Started Guide

This introductory guide will teach you how to easily connect WeMos ESP8266 WiFi Module to Medium One cloud via UART for ultra rapid IoT prototyping.

Contact info@mediumone.com to request a free Wemos wifi module.

About the ESP8266 and Medium One firmware:

The Wemos module loaded with Medium One firmware will allow you to send and receive JSON events to the Medium One cloud simply by sending data via the UART pin.  You can easily integrate this wifi chip to any embedded design as long as UART is available.  The board is powered via USB and required 3.3V for the UART pins.

Features:

  • Free cloud sandbox integration with python workflows and dashboards
  • Easily integrate mobile app to view and control your devices
  • Easily integrate to your embedded system via 3.3v UART
  • Support send and receive data in real-time
  • Locate GPS of the board based on IP address (nearest city)
  • Over the air firmware update
  • Ideal for rapid IoT prototyping!

In this guide, you will:

  • Program/Flash the WeMos board
  • Setup and Connect WeMos board to Medium One cloud
  • Use Medium One Workflows to produce geolocation data
  • Use Medium One IoT Controller app to view your location on a map

Level: Beginner

What you need:

Install Windows USB driver for Wemos board

If you haven’t already, install the WeMos USB driver  using the link and instructions provided.  This will allow your Windows PC to communicate and flash the Wemos board.

Create and Set Up Medium One Sandbox Account

For Sandbox account, go to mediumone.com ; click on Sign Up in top right corner.
For Renesas Sandbox account, click here.

After signing up, you will receive an email with your account information.

 

Log into the dashboard with the link and credentials in your email.

Go to “Setup” -> “MQTT” on the left-hand sidebar, then copy down the Project MQTT ID.

NOTE: Copy down your Project MQTT ID for later use.

In Setup, click on “Manage API Keys”, then “Add New API Key”; new window opens up for managing API keys.
Create a new API key by typing ‘API’ in Description; then, click “Save”.

New API key was generated.
NOTE: Copy down your API Key for later use.

 

Still in Setup, go to “Manage Users”, then “Add New User”.

Name the new user and create password; then click “Save”.

Copy down the Login ID (aka Login Username), User MQTT ID, and Password.

NOTE: Copy down the Login Username, User MQTT ID, and User Password for later use.

 

Go back to the Dashboard, and open a “Single User Real Time Events Stream” (RTES) widget. 

 

Make sure to select your user in the top right corner.

NOTE: To save your preferred dashboard layout, click on Disk icon in the top right corner.

CHECKPOINT:

You have copied down the following info about your project:

  • Project MQTT ID
  • API Key
  • Login Username
  • Username MQTT ID
  • User’s Password

The Dashboard with RTES widget is open and ready to view data.

Flash Board

Connect (via USB) the Wemos board into PC.  If this is the first time, you may need to wait for drivers to be installed.

Open device manager.

Under Ports, note your USB Serial Port #. In this picture it’s COM6, but you’ll need to remember yours.

NOTE: Copy down COM# for later use.

Open the Command Prompt and cd into the folder with the following files:

m1_cloud_io binary and esptool.exe tool.

In the command window, type the follow command and replace COM6 with your COM#:

esptool.exe -vv -cd nodemcu -cb 921600 -cp COM6 -ca 0x00000 -cf m1_cloud_io.ino.d1_mini.bin

CHECKPOINT:

Confirm the output of the programming tool.  If you see 100%, you are done.

Connect Board to Sandbox

Keep your board connected and install putty to your windows PC.

Open PuTTY.  Click the Serial radio button.

Specify COM port from last step.

Set speed to 9600.

Click open.

CHECKPOINT:

With terminal window open, type “setup” (without quotes) and press return.  You should see a print out like this:

NOTE: If it is a newer version, you will see more options.

Congrats, you have entered the provisioning mode for the board!

 

Configure Board Settings

NOTE: If you make a typo and then press backspace, the board will not recognize your command/information. If this happens, just hit enter and retry.

On the terminal, type “wifi” and follow the prompts to enter your information.

wifi

Enter your wifi SSID: <mywifi>

Enter your wifi password: <your wifi password>

Wifi configuration complete, exiting setup mode. Type ‘setup’ to enter provision mode again. IP address will print shortly if successful.

Connecting to wifi mywifi

<Notification> Connected to Wifi, IP address: 192.168.20.112  <If you get this message you successfully connected to wifi>

On the terminal, type setup again and then m1.  Use the credentials from your Medium One account to set up the board.

m1

Enter your Medium One API key: E4SXICVM7AOJJQGVRTQNJTMNRWKNRQGQ3TAMBQ

Enter your project MQTT ID: 4DJ6hDJtI

Enter your device MQTT ID: g56OAJEE

Enter your device password: ########

Specify your Medium One cloud environment (sandbox, pro or renesas): sandbox

Medium One configuration complete, exiting setup mode. Type ‘setup’ to enter provision mode again.

Saving Medium One credentials.

<Notification> Connected to MQTT broker

<Notification> Sending connect msg: {“event_data”:{“mqtt_connected”:true, “fw_version”:”ESP.061117A”, “ip”:”192.168.20.112″, “mac”:”5C:CF:7F:2F:1E:C1″, “ssid”:”dt_router_1″, “chip_id”:”3088065″, “flash_id”:”99359″, “flash_size”:”524288″, “flash_speed”:”40000000″}, “add_client_ip”:true}

<Notification> Publish success

<Notification> Successfully subscribed

 

If you see messages similar to the above, congrats, you have successfully entered Medium One credentials!  Note, this event contains module info such as IP address, chip ID and more.

If you have your Dashboard open, the event should have appeared on your Real Time Events Stream.

In the terminal, type setup and then send.  Use this to send sample event to the cloud for debugging purposes.  Send the sample event:

##########################################################################

You are in setup mode.

* Type ‘wifi’ (without quotes) to configure the wifi settings.

* Type ‘m1’ (without quotes) to configure Medium One cloud credentials.

* Type ‘send’ (without quotes) to send an event to Medium One.

##########################################################################

send

<UART> Sending payload to cloud: {“event_data”:{“hello”:”world”}}

<UART> Publish ok

Note, you need to preserve the format

 

CHECKPOINT:

See the data appear in the Real Time Events Log. If too much time has passed, refresh the Dashboard and repeat the last step.

The board will say “Publish ok” even if the event did not send to Medium One, so make sure to check your event log!

Connect the Mobile App

Note: These instructions are for the IoS app, but the Android app is similar.

Open the IoT Controller app and click on the plus sign in the top right corner.

Now you can give your project a name and input your API Key, API Login, and API Password from the account set up.  In order to link your mobile app to the correct account, select ‘Renesas’ if you created your account on Renesas Sandbox IoT. Otherwise, select ‘Sandbox’ to connect to account created by Sign Up link on Medium One website.

Then press “Done”.

Press the power icon on the left-hand side of the switch to access the settings.

Type “raw” for the stream, and “switch” for the tag. Then press “Done”.

 

Press “+ Add New Widget” again and scroll down to the bottom to select “Map”.

Press the marker icon on the left-hand side of the map and type “processed” for the stream and “gps” for the tag. Then press “Done”.

Now press “Save” at the bottom of the app. You should get a confirmation that it was saved.

CHECKPOINT:

Click on the switch to turn it on.

You should see an event show up on the events log in your Dashboard.

Create Workflow To Calculate Location

Go to “Config” from the left-hand sidebar on your Medium One account and click “Data Streams”.

 

Click “raw” and then click the active check-boxes next to “ip_address” and “switch”. Then click “Save Data Stream”.

 

Now go to your Workflow Studio on your Medium One account and click “Create”.

Give your workflow a name in the top left of the workflow. Then click the “Tags and Triggers” icon, which is the first icon on the right-hand sidebar.

 

 

Select “raw”, and then draw the “ip_address” tag onto the workflow.

Now click on the “Modules” icon (the second icon in the sidebar), click on “Foundation” and drag a “Base Python” module into the workflow.

 

Click the “Outputs” icon (third icon on sidebar) and drag two “Processed Stream – Single” outputs into the workflow.

 

Double click on the Base Python module and click “Inputs/Outputs”. Then click “Add Output”.

Copy and paste the following code  (follow link below)  into the Script area, replacing any code that was previously there. Then click “Save”.

https://github.com/Medium-One/m1_cloud_io/blob/master/wemos-getting-started/workflow1.py

 

Now connect the Base Python module to its input and outputs as shown in the picture.

Click on the “Revisions” icon (second from the bottom of the sidebar).

Click the check-mark under the latest revision to activate the workflow.

CHECKPOINT:

Go to your Dashboard;  then, reset the WeMos board by pressing  Reset button. Alternatively, you can unplug/plug in the board.

In addition to the WeMos event, you should get two GPS events in your Events Stream.

Display Location Data

Click “Config” and then “Data Streams” on the left-hand sidebar. Then click “processed”.

Look for “processed.gps” and change the type from “GeoPoint – Time Series” to “GeoPoint – Last Value”.

Then press “Save Data Stream”.

 

Go back to your Dashboard, and add the “Single User GeoPoint Chart” widget.

After selecting your user, you should see your general location marked on the map. Since it is based on ip address, it is not 100% accurate.

NOTE: To save your preferred dashboard layout, click on Disk icon in the top right corner.

Additionally, if you open up your IoT Controller app, you will see this point marked on your map widget.

Create Workflow to Relay Mobile to Board

Go back to your Workflow Studio and create a new workflow.

Name it, and then drag the following into the workflow:

  • raw:switch tag (from first icon: Tags & Triggers)
  • Base Python module (from second icon: Modules)
  • one Processed Stream – Single (from third icon: Outputs).

Then connect them together as shown in the picture.

Now double-click on the Base Python module, and replace the code with the following:

https://github.com/Medium-One/m1_cloud_io/blob/master/wemos-getting-started/workflow2.py

Click “Save and Activate”.

CHECKPOINT:

Reset the Wemos board by pressing the Reset button; then, open your putty terminal (configured to the port that you have the board plugged into).

You should get the notification that you are connected to MQTT broker.

Open the mobile app and press the switch. After pressing the switch, you should get a Subscribe message on your board (on the terminal).

This was taken after turning the switch on and off.

 

Sending and Receiving Data via UART on the Wemos Board

The Wemos board can send and receive data via UART.

  • UART RX is pin D2
  • UART TX is pin D1
  • Baud rate is 9600

 

Sending Data to Medium One

You can send data to Medium One simply be sending a string to pin D2.  The string must adhere to Medium One’s JSON payload standard and end with “\r” (carriage return).

For example, you can transmit “{“event_data”:{“hello”:”world”}}\r” where {“hello”:”world”} is the JSON payload to the cloud and everything else before and after are required as part of the overall structure.

Receiving Data from Medium One

Data received from Medium One doesn’t need to be in JSON format. The packet received by the cloud will and appended with “\r” to serve as the delimiter.

broni@medium.one'

Author: Broni Thai