Matt Nelson
Published © GPL3+

Onion Omega2 GPS Info to OLED + Losant map

Display GPS info on the OLED and put it on a map dashboard at Losant. The map is much more detailed than what's shown here (privacy).

IntermediateShowcase (no instructions)1 hour2,053
Onion Omega2 GPS Info to OLED + Losant map

Things used in this project

Hardware components

Omega2 Plus
Onion Corporation Omega2 Plus
×1
OLED Expansion
Onion Corporation OLED Expansion
Optional
×1
Expansion Dock
Onion Corporation Expansion Dock
×1
GPS receiver (generic)
×1

Software apps and online services

Losant Platform
Losant Platform

Story

Read more

Code

getgps.sh

SH
Modified version of Brad Buskey's script to send GPS Info to the OLED. You can just "chmod +x getgps.sh" and run it. You could "./getgps.sh &" and run it in the background, you could link to it in /etc/rc.local to run it at bootup.....
#!/bin/ash

# Run the loop to send it
while true; do

# Get updated gps info and write it to the nema file.
awk '/GPGLL/ {print}' /dev/ttyACM0 > gpsnema.txt &
sleep 1
killall awk
sleep 1

# Build the json string.
output="$(tail -1 gpsnema.txt)"
output="{\"data\":{\"gps\":\"${output}\"}}"

# write the json string to a file.
echo $output > /root/gpsmqtt.txt

# Write file for output to oled
ubus -S call gps info > /root/gpsinfo.txt


# Send the json data to losant.  You'll need to put your Losant device ID here.
mosquitto_pub -f /root/gpsmqtt.txt -t 'losant/xxxxxxxxxxxxxxxxxxxxxxxxx/state'

# call python script to write the data to the oled
python /root/showgps.py

# Exit the script
sleep 60
done
exit 0

showgps.py

Python
This is called by getgps.sh to send the data to the OLED
#!/usr/bin/env python

#======================================================
# Show GPS Location on the OLED Screen on the Omega 2+
# Written By: Brad Buskey
# Contact Me: deckyon@gmail.com
#======================================================

#Initialize the script and pull in the required libraries.
from OmegaExpansion import oledExp
import time
import json
import os

# Initialize and clear the OLED screen
oledExp.setVerbosity(0)
oledExp.setTextColumns()
oledExp.driverInit()

# Draw the header for the display
oledExp.setCursor(0, 0)
oledExp.write("__Current GPS Info__")
oledExp.setCursor(1, 0)
oledExp.write("====================")

# Check fo the file size of gpsinfo.txt and exit if < 1
if os.path.getsize('/root/gpsinfo.txt') == 0:
	# File is empty or doesnt exist
	oledExp.setCursor(3, 0)
	oledExp.write("GPS Info doesnt seem")
	oledExp.setCursor(4, 0)
	oledExp.write("to exist.")
	oledExp.setCursor(6, 0)
	oledExp.write("Check GPSInfo file.")
	exit()

# Get the data fro mthe file written to in the shell script.
with file('/root/gpsinfo.txt', 'r') as gpsfile:
	gpsinfo = json.load(gpsfile)
	
# Pause the script and pretend to look stuff up.
time.sleep(2)

# Test for the existence of a GPS signal
if gpsinfo.has_key('signal'):
	# No GPS Signal, let the OLED reflect that
	oledExp.setCursor(3, 0)
	oledExp.write("No GPS signal found")
	oledExp.setCursor(4, 0)
	oledExp.write("Please try later!")
elif gpsinfo.has_key('latitude'):
	# Pull out the data from the desired fields in the dictionary 'gpsinfo'
	lat=gpsinfo['latitude']
	lon=gpsinfo['longitude']
	elv=gpsinfo['elevation']
	cou=gpsinfo['course']
	spd=gpsinfo['speed']
	# Build the data strings to be written to the OLED
	lat="Latitude : "+lat
	lon="Longitude: "+lon
	elv="Elevation: "+elv
	cou="Course   : "+cou
	spd="Speed    : "+spd
	# Draw out the rest of the information gathered from 'gpsinfo'
	oledExp.setCursor(2, 0)
	oledExp.write(lat)
	oledExp.setCursor(3, 0)
	oledExp.write(lon)
	oledExp.setCursor(4, 0)
	oledExp.write(elv)
	oledExp.setCursor(5, 0)
	oledExp.write(cou)
	oledExp.setCursor(6, 0)
	oledExp.write(spd)
	
# Exit the script cleanly
exit()

Onion to Losant Setup Script

Follow the directions at https://onion.io/2bt-single-command-losantomega/

Credits

Matt Nelson

Matt Nelson

0 projects • 2 followers

Comments