This tutorial assumes that you have already connected Sigfox to Wia if you haven’t, please click here to find a tutorial for initial Sigfox setup and publishing data to Wia.
Components- Sigfox compatible antenna
- Mobile device (iOS or Android)
If you haven’t already, you’ll need to upgrade the firmware on your Pytrack Expansion Board.
You can follow the instructions here.
- Connect the SiPy to the Pytrack board (The RGB LED on the SiPy should be on the side of the usb port on the Pytrack board)
- Connect the Sigfox antenna to the SiPy (The connection is just left of RGB LED)
- Create a new folder for your project. I'm going to call mine pycom-pytrack
- 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
(Mac OS X),COM3
(Windows),/dev/ttyACM0
(Linux) then save the file
- Right click on the folder name in Atom and click
Add Folder
. Enterlib
as the folder name
- Right click on the lib folder and click New File. Enter
urequests.py
as the file name
- Click on the file then copy and paste the code from here into that file then save it
- For Pytrack, additional libraries must also be added to the lib folder, these can be found here
- We'll need two files for our application:
boot.py
which is run when the device is powered up
main.py
which is where our main code is
- In Atom, right click on your project and click New File. Enter
boot.py
as the filename
- Copy and paste the code below labeled
boot.py
into the file
- Right click on your project and click New File. Enter
main.py
as the filename
- Copy and paste the code below labeled
main.py
into the file
Your folder structure should now look like this:
lib
urequests.py
L76GNSS.py
LIS2HH12.py
pytrack.py
boot.py
main.py
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 data appearing in the debugger section of your dashboard.
Note: It may take a few minutes before the Pytrack finds a GPS signal, also the Pytrack isn't suitable for indoor use.
Parsing the DataNow for the next step, we must parse the data we received from Sigfox and do something useful with it. For this we need to build a Flow.
Head over to your Wia dashboard and in the Space where your Sigfox device is held click on the Flow icon in the left hand menu to go your Flows.
Now to create your Flow, you can name it whatever you like. Once you have created a Flow, you should be taken to the Flow studio.
In the Flow studio:
- Drag the
trigger event node
from the left hand side onto the canvas
- Click on the node and enter
sigfoxDataUplink
as the event name
- Enable your Sigfox Device as the event source
- Now add a function node from the logic section (We’ll parse the data here)
- Add a location node from the
output
section
Click on the function node and add the code below labeled Flow Studio
.
This code parses the Sigfox data from hexadecimal format to latitude and longitude in floating point.
- The Sigfox data comes in a 12 byte hexadecimal string
- Each of GPS coordinates is 32 bits or 4 bytes of data
- They are 2 characters that can fit into 1 byte of data, hence why we split our hexadecimal string by 8
Currently the Flow takes in the data from Sigfox, parses it and outputs a location. Now we are going to go one step further and get a notification of the newly created location so we can view it on a map on our phones. To do this, you will require the Wia mobile app. You can download it for iOS here and Android here.
In the Flow Studio editor:
- Drag over a location node from the trigger section now. With this we can capture the node created from the previous Flow chain
- Add the same Device as earlier to the location trigger node
- Drag over a notification node and enter the following text
Now you should receive Sigfox data to your mobile device.
Comments