Spivey
Published © MIT

Build an End-to-End Sigfox GPS Tracker Using Wia and Pycom

Create a Sigfox GPS tracker using Wia and the Pycom SiPy in a few easy steps.

BeginnerFull instructions provided1 hour2,183
Build an End-to-End Sigfox GPS Tracker Using Wia and Pycom

Things used in this project

Hardware components

SiPy
Pycom SiPy
×1
Pycom Pytrack Expansion Board
×1

Software apps and online services

Wia
Wia

Story

Read more

Schematics

SiPy

Code

boot.py

Python
from machine import UART
from network import Sigfox
import binascii
import machine
import os

# initalise Sigfox for RCZ1 (Europe) (You may need a different RCZ Region)
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1)

# print Sigfox Device ID
print("ID: ", binascii.hexlify(sigfox.id()))

# print Sigfox PAC number
print("PAC: ", binascii.hexlify(sigfox.pac()))

uart = UART(0, baudrate=115200)
os.dupterm(uart)

machine.main('main.py')

Flow Studio

JavaScript
if (input.body) {
  let latLong = parseSigfoxLocation(input.body.data.sigfoxData);
  output.body.latitude = latLong.latitude;
  output.body.longitude = latLong.longitude;
}

function parseSigfoxLocation(sigfoxData) {
  let latHex = sigfoxData.slice(0, 8);
  let longHex = sigfoxData.slice(8);
  let result = {
    latitude: Buffer(latHex, 'hex').readFloatLE(0).toFixed(6),
    longitude: Buffer(longHex, 'hex').readFloatLE(0).toFixed(6)
  };

  return result;
}

main.py

Python
from network import Sigfox
from pytrack import Pytrack
import urequests as requests
from L76GNSS import L76GNSS
import socket
import time
import pycom
import struct

py = Pytrack()
gps = L76GNSS(py, timeout=60)

init_timer = time.time()

print("connecting to Sigfox")
# init Sigfox for RCZ1 (Europe)
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1)

# create a Sigfox socket
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
# make the socket blocking
s.setblocking(True)

s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False)

# Post an location to the Wia cloud via Sigfox backend
def post_location(latitude, longitude):
    try:
        print(str(latitude), ":", str(longitude))
        s.send(struct.pack('f',float(latitude)) + struct.pack('f',float(longitude)))
    except:
        pass

# main loop
while True:
    final_timer = time.time()
    diff = final_timer - init_timer
    # Get coordinates from pytrack
    coord = gps.coordinates()

    # If the GPS has coordinates and 15 minites has past. Post the location data
    if not coord == (None, None) and diff < 900:
        lat, lng = coord
        post_location(lat, lng))
        init_timer = time.time()

Credits

Spivey

Spivey

82 projects • 59 followers
Tourist in a Tutu || US Born || Melbourne/Mexico/California Raised || New Yorker at ❤️ || SF to Dublin to be COO of Wia the best IoT startup
Thanks to Alan Donoghue.

Comments