Hi All,
Today we're going to look at publishing data from a Pycom device to Wia. To do so, you'll need one of Pycom's development boards (go here to see them). For this tutorial, we will be connecting the devices via WiFi. Other options are available such as Sigfox, LoRa and Bluetooth. You can see the example code for these here.
If you haven't already got one, click here to sign up.
Once logged in, setup a new Space for your devices. I'm going to call mine My Devices
. When your Space is ready, you should see a screen like the one below.
Create a new Device by entering it's name in the panel. You will then be redirected to the Device Overview page. Here you will see the Device's secret key (it should start with d_sk
). Keep note of this, we're going to use it later.
We'll be using Atom as our development environment. You can download the latest version from here. Once you've got it setup, install the Pymakr plugin. Follow the steps in this tutorial to get it setup.
There are two ways to connect your board to your computer. You can do so either via the USB port on the Expansion Board or Pysense/Pytrack boards (more on that here). Alternatively you can connect it via a USB to TTL cable.
Once you've got it connected to your computer, get the name of your device using one of the following steps:
- Open a terminal window and run the command
ls /dev/tty.*
- Look for a device with the name that begins with
/dev/tty.usbmodem
e.g./dev/tty.usbmodemPy343431
.
- Download and install the FTDI drivers from here.
- Open the Windows start menu and search for 'Device Manager'
- The COM port for the Pycom device will be listed as 'USB Serial Device' or something similar
- Keep note of the COM port (e.g. COM4)
- Create a new folder for your project. I'm going to call mine
publish-pycom-event
. - In Atom, go to File > New Window to open a new window.
- Add your newly created folder by clicking File > Add Project Folder and navigating to it.
- If the Pymakr plugin is not open at the bottom of your Atom window, click on the arrow on the right hand side to open it.
- Select Settings > Project Settings. In the
address
field replace the value with the device name from the step above e.g./dev/tty.usbmodemPy343431
(Linux/Mac OS X),COM3
(Windows) then save the file.
- Right click on the folder name in Atom and click Add Folder. Enter
lib
as the folder name. - Right click on the
lib
folder and click New File. Enterurequests.py
as the file name. - Click on the file then copy and paste the code from here into that file then save it.
- In Atom, right click on your project and click New File. Enter
boot.py
as the filename. - Copy and paste the code below into the file. (It's also available here on GitHub).
https://gist.github.com/1e82c77b5df2364b3098f21cb9c505d6
- Right click on your project and click New File. Enter
main.py
as the filename. - Copy and paste the code below into the file. (It's also available here on GitHub).
https://gist.github.com/eab0dcc22b17bca017615b194c77a108
Replace the following values of the following variables:
WIFI_SSID
with your WiFi network name.WIFI_KEY
with your WiFi network password.DEVICE_SECRET_KEY
with your device secret key from earlier (the one that begins withd_sk
).
Your folder structure should now look like this:
- lib
- urequests.py
- boot.py
- main.py
If all looks good, then click Upload in the Pymakr plugin at the bottom of your window in Atom and send the code to your Pycom board. Now go to the Wia dashboard and you should see it appearing in your device overview.
Note: If your board gets stuck with the message "Uploading project (main folder)...", try updating the firmware. For the development board click here. For additional firmware for the Pysense/Pytrack board click here.
There are a few more steps required to capture the data from your Pysense board.
- Navigate to the Wia Pysense example code on GitHub here.
- Copy the additional files in the
lib
folder to your locallib
folder. - Replace your
main.py
file with themain.py
file in the GitHub repository. Remember to change the WIFI_SSID, WIFI_KEY and DEVICE_SECRET_KEY variables.
Your folder structure should be:
- lib
- urequests.py
- LIS2HH12.py
- LTR329ALS01.py
- MPL3115A2.py
- SI7006A20.py
- pysense.py
- urequests.py
- boot.py
- main.py
Upload the code to your device and see the data coming through to the Wia dashboard.
That's all folks!
References
Pycom brings world firsts in no less than five modules, sensor shields and equivalent OEM solutions. Whatever network takes your fancy, we have all you need. Choose out of WiFi, Bluetooth, LoRa, Sigfox, LTE CAT M1 / NB1, or have them all