Dana Mah
Published © GPL3+

Cellular SOS Button Tracker

A device similar to a medical alert button that can be use anywhere where cellular service is available.

IntermediateFull instructions provided10 hours1,661
Cellular SOS Button Tracker

Things used in this project

Hardware components

Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
×1
GPS receiver (generic)
×1
Huawei 3G USB Dongle
×1
SORACOM Air Global IoT SIM
SORACOM Air Global IoT SIM
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Story

Read more

Schematics

GPS sensor to Pi

This is the diagram I used to connect the GPS sensor to the Raspberry Pi

Code

gps.py

Python
This is the code I used from lokesh chandak. I modified it to fit my needs. This will read the GPS sensor data, find the #GPGGA NMEA message and process it to produce the JSON output I needed.
import serial               #import serial pacakge
from time import sleep
import webbrowser           #import package for opening link in browser
import sys                  #import system package

def GPS_Info():
    global NMEA_buff
    global lat_in_degrees
    global long_in_degrees
    nmea_time = []
    nmea_latitude = []
    nmea_longitude = []
    nmea_time = NMEA_buff[0]                    #extract time from GPGGA string
    nmea_latitude = NMEA_buff[1]                #extract latitude from GPGGA string
    nmea_longitude = NMEA_buff[3]               #extract longitude from GPGGA string

    lat = float(nmea_latitude)                  #convert string into float for calculation
    longi = float(nmea_longitude)               #convertr string into float for calculation

    lat_in_degrees = convert_to_degrees(lat)    #get latitude in degree decimal format
    long_in_degrees = convert_to_degrees(longi) #get longitude in degree decimal format

#convert raw NMEA string into degree decimal format
def convert_to_degrees(raw_value):
    decimal_value = raw_value/100.00
    degrees = int(decimal_value)
    mm_mmmm = (decimal_value - int(decimal_value))/0.6
    position = degrees + mm_mmmm
    position = "%.4f" %(position)
    return position

gpgga_info = "GPGGA"
ser = serial.Serial ("/dev/ttyS0")              #Open port with baud rate
GPGGA_data_available = 0
GPGGA_buffer = 0
NMEA_buff = 0
lat_in_degrees = 0
long_in_degrees = 0

try:
        while GPGGA_data_available < 1:
                received_data = (str)(ser.readline())                   #read NMEA string received
                # Sample data below was used because GPS sensor wouldn't work inside.
                #received_data = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"
                print("in while loop")
                GPGGA_data_available = received_data.find(gpgga_info)   #check for NMEA GPGGA string

        GPGGA_buffer = received_data.split("$GPGGA,",1)[1]  #store data coming after "$GPGGA," string
        NMEA_buff = (GPGGA_buffer.split(','))               #store comma separated data in buffer
        GPS_Info()                                          #get time, latitude, longitude

        print "{ 'latitude' :", lat_in_degrees, ", 'longitude':", long_in_degrees, " }"


except KeyboardInterrupt:
    webbrowser.open(map_link)        #open current position information in google map
    sys.exit(0)

cron job

Plain text
This is the cron job setting I used to execute my getdata.sh script. It will run every 5 mins, but it can be set to anything you need.
*/5 * * * * /home/pi/gps/getdata.sh

getdata.sh

SH
This is the shell script that the cron job will run. it will call the python gps.py script and set the output to a variable. Then it will send that output to Soracom's harvest.
#!/bin/sh
coords=$(python /home/pi/gps/gps.py 1>&1)
#echo "$coords"
curl -v POST  -H 'content-type:application/json'  -d "$coords" http://harvest.soracom.io

Credits

Dana Mah

Dana Mah

12 projects • 27 followers
I'm a hobbyist interested in microcontroller solutions to simple problems.
Thanks to lokesh chandak .

Comments