This tutorial uses the WeMos ESP8266 WiFi Module and Medium One to control an LED and get your geolocation data.
In this WeMos Quick Start Guide, you will:
Set up an Arduino environment
Program the WeMos board
Use Medium Workflows to produce geolocation data and switch the LED
Use the Medium One IoT Controller app to control the LED and view your location on a map
Here’s what you need to get started:
Medium One Prototyping Sandbox [Buy]
WeMos WiFi Module
WeMos Driver [Download]
2.4 GHz WiFi Internet Access
Medium One IoT Controller App
Step 1. Set up your Account
Click “Setup” in the left-hand sidebar of your Medium One account.
Go to “MQTT” and copy down your Project MQTT ID for later use.
Go to “Manage Users” and click “Add New User”.
Give your new user a username and password. You will want to copy these down for later use as well. Then click “Save”. You will also want to copy down the user MQTT ID that shows up after you click Save.
Go to “Manage API Keys”, click “Add New API Key”, give your API Key a description, and click “Save”. You will want to copy down the API Key for later use.
Step 2. Set up 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 Username, Password, and API Key from the account set up. Be sure to select "Pro". Then press “Done”.
Press “+Add New Widget”.
Press the power icon on the left-hand side of the switch to access the settings. (on Android, swipe your finger across the widget to the right 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.
Go to your Medium One account and go to the “Dashboard” from the left-hand sidebar.
Click “Single User Real Time Events Stream”.
Select your user in the right hand corner of the widget.
Now, on the app, click on the switch to turn it on.
You should see an event show up on the widget.
Click the save icon (floppy disk) in the top right corner of the dashboard.
Step 4. Set up the Wemos Board
Open Arduino and go to File -> Preferences.
Paste http://arduino.esp8266.com/stable/package_esp8266com_index.json into the Additional Board Manager URLs section and press OK.
Go to Tools > Board > Boards Manager …
Search for “esp8266” and install the boards.
Go to Tools -> Board:”WeMos D1 R2 & mini” -> select “Wemos D1 R2 & mini.”
Go to Sketch -> Include Library -> Manage Libraries.
Copy and paste the code here into your project.
Fill in your account information where necessary in the code.
Scroll down to the setup function and fill in your wifi information.
Plug in your WeMos board and go to Tools -> Port. Make sure that the port the WeMos is plugged into is selected.
Then click on the upload arrow in the top left corner.
Then go back to your Medium One Dashboard, where the Real Time Events Stream should be open. You should eventually receive an event from your WeMos board within a minute.
You should go to Tools -> Serial Monitor to see print statements from the board, so that you can see when the board connects to the WiFi.
You will also receive a heartbeat event from the board every minute.
Unplug your WeMos board.
Step 5. Write Workflow 1: Switch LED
Go to “Config” from the left-hand sidebar on your Medium One account and click “Data Streams”.
Click “raw” and then click the active checkboxes 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. We named ours “switch led”.
Click the “Tags and Triggers” icon, which is the first icon on the right-hand sidebar.
Click “raw” and drag the “switch” tag into the main area of 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.
Connect the bottom end of the switch tag to the “in1” circle on the Base Python module.
Double-click on the Base Python module and copy and paste the code here into the Script section, replacing any code that is originally there.
Now click “Save and Activate”.
Plug your WeMos board in and open the IoT Controller app.
After the board is done setting up (within a minute), turn your switch on the app on and off. You should see the LED on the board turn on and off.
Unplug your WeMos board.
Step 6. Write Workflow 2: Get Location
Create a new workflow, name it, and drag the raw ip_address tag into the workflow.
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 code here into the Script area, replacing any code that was previously there. Then click “Save”.
Now connect the Base Python module to its input and outputs as shown in the picture.
Now click on the “Revisions” icon (second from the bottom of the sidebar).
Click the checkmark under the latest revision to activate the workflow.
Go to your Dashboard and plug in the WeMos board.
In addition to the WeMos event, you should get two GPS events in your Events Stream.
Step 7. Map Location
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.
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.
Also, if you open up your IoT Controller app, you will see this point marked on your map widget.
Congrats! You have finished the tutorial.
Want to learn more about what Medium One can do?