YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

GPS/GRPS tracking help

Mon May 13, 2019 7:58 pm

https://www.amazon.co.uk/gp/product/B07 ... _qh_dp_hza -

Have purchased this for a play around with a project i would like to do just a simple tracker that i could remote access to pull the data and track in real time.

I also have a raspberry pi zero to use with it.

A couple of questions though as my knowledge of linux is so so i can get by from tutorials.

I had first initially thought GPS was not free but from my researching it seems it is widely free is that correct?

The add on hat has a coin cell battery - Does this mean that it could sit in a state of low power and only activate if i were to wake up the pi zero?

I have read a few guides on GPS and found the scripts that it takes to run so that shouldn't be too much of a headache * Famous last words.*

The part of the GSM is where i am struggling to get to terms with.

Since this part will only function over 2G in my country from what i gather (UK) will i still be able to remotely access the device this way and what software would i use to be able to do this?

Will i be limted by 2G speeds when downloading this data?
What will the real time tracking be using to track the device from home? GSM or GPS? i.e would i need to send a call to the device to wake it up?

I plan on running this from a powerbank will this be OK? Since i only want to activate the device and send a wake up script and a shutdown script when i am finished. (currently the 20,000mah battery i used for a pi 3+ lasted around 3 days give or take)

Is there a better alternative like those batteries you can attach direct to the pi.


Sorry my questions are a little out of frame.

Hopefully someone may understand!

Thank You.

User avatar
omegaman477
Posts: 148
Joined: Tue Feb 28, 2017 1:13 pm
Location: Sydney, Australia

Re: GPS/GRPS tracking help

Tue May 14, 2019 7:14 am

YitEarp wrote:
Mon May 13, 2019 7:58 pm
https://www.amazon.co.uk/gp/product/B07 ... _qh_dp_hza -

Have purchased this for a play around with a project i would like to do just a simple tracker that i could remote access to pull the data and track in real time.

I also have a raspberry pi zero to use with it.

A couple of questions though as my knowledge of linux is so so i can get by from tutorials.

I had first initially thought GPS was not free but from my researching it seems it is widely free is that correct?

The add on hat has a coin cell battery - Does this mean that it could sit in a state of low power and only activate if i were to wake up the pi zero?

I have read a few guides on GPS and found the scripts that it takes to run so that shouldn't be too much of a headache * Famous last words.*

The part of the GSM is where i am struggling to get to terms with.

Since this part will only function over 2G in my country from what i gather (UK) will i still be able to remotely access the device this way and what software would i use to be able to do this?

Will i be limted by 2G speeds when downloading this data?
What will the real time tracking be using to track the device from home? GSM or GPS? i.e would i need to send a call to the device to wake it up?

I plan on running this from a powerbank will this be OK? Since i only want to activate the device and send a wake up script and a shutdown script when i am finished. (currently the 20,000mah battery i used for a pi 3+ lasted around 3 days give or take)

Is there a better alternative like those batteries you can attach direct to the pi.


Sorry my questions are a little out of frame.

Hopefully someone may understand!

Thank You.
So the GPS system is free, its funded by the US Military, and a license fee for every GPS receiver chip made. Reading GPS messages is usually a very simple task, as they are usually in NMEA format which is a plain text, human readable format. There are a number of Python ( and others) libraries for complex GPS Lat/Long calculations (great circle calculation, distance between two coordinates etc.

The coin battery on the GPS hat is to power the Real Time Clock RTC, when there is no main supply to the board and Pi. It cant be used for anything else. Be sure to read up on Low Power or Standby mode with the RPI, as technically it does not have one, and even when idle/sleep they still draw considerable current. There are hats around that safely power up and down the Pi as needed. A must for battery based operations.

So the board has a basic GSM/GPRS modem. Which when properly setup with your carrier will allow you to establish a TCP/IP link to the internet. Like all mobile devices the RPI end will get a new IP address each time it connects. Depending on your carrier etc, you may be able to connect from the internet back into the RPI. So the RPI will need to regularly poll a server and upload its data. You need to experiment with the hat and your carrier, as the feature set for your arrangement may not support all features of GPRS. Start by testing the unit by trying to retrieve a simple web page. Then build from there.

GPRS over 2G usually has a max data bandwidth fo 60-80kbit/s. Slow by todays standards, but more than adequate for remote position sensing/telemetry.
..the only thing worse than a stupid question is a question not asked.

YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

Re: GPS/GRPS tracking help

Tue May 14, 2019 1:50 pm

Thank You so much that information is very helpful.

I did some more research as regards to using the sim and it seems not all carriers in fact quite a lot will use double NAT so being able to ssh to the device may require some legwork which i don't mind as i have used ssh tunnels in the past so thinking this is an option that will be open for me if i can connect it to a VPN also since i run a pi on my home network using piHole so adding a VPN should be straight forward hopefully. I am still learning.

I am stuck however on how to best track in real time the GPS data. I've browsed github and there is a plethora of information regarding this. I am not sure if i would like the device to notify me when its moving via SMS and from there i can track via googlemaps if such a feature is out there.

Any ideas on this part?

I was thinking something along the lines of this

https://github.com/pubnub/eon

However i do not know if this is a free service because it states a pubnub account must be used?

Any alternatives if so?

Final question for now i suppose is battery life.

I plan to use an external battery for now - i think the 20,000mah battery may be overkill i need to do the math really but i would like it to last 3-5 days if i could get the device to lay in a low power state and only wake up when movment is detected or i call into the device.

Your post stated there are hats to enable the device to shutdown etc. I will look into this.

EDIT: I am a little confused now as i have seen tracking devices that do not rely on a GPS attenae. How do these work? It would be great if i could perhaps remove the GPS module this device has as i would like to 3D print a case for it to go into without the mess of a long wire.

But i can't figure out if a data SIM can even do GPS. Lots of lessons to learn.


Thanks.

User avatar
omegaman477
Posts: 148
Joined: Tue Feb 28, 2017 1:13 pm
Location: Sydney, Australia

Re: GPS/GRPS tracking help

Tue May 14, 2019 5:57 pm

Your proposed comms plan seems fine. Just remember you only have 85kbit/s of bandwidth available. Although your actual GPS data payload is not large, when the VPN and SSH establish connections, they tend to exchange a lot of data during the opening. Due to the reduced bandwidth you may see some slow connection times, but I feel once you connected it should be fine.

The GPS will simply send a text string, usually every second with the current coordinates and some other data, as follows;

$GPRMC,235316.000,A,4003.9040,N,10512.5792,W,0.09,144.75,141112,,*19
$GPGGA,235317.000,4003.9039,N,10512.5793,W,1,08,1.6,1577.9,M,-20.7,M,,0000*5F
$GPGSA,A,3,22,18,21,06,03,09,24,15,,,,,2.5,1.6,1.9*3E


For example, the GPGGA sentence contains the follow:

Time: 235317.000 is 23:53 and 17.000 seconds in Greenwich mean time
Longitude: 4003.9040,N is latitude in degrees.decimal minutes, north
Latitude: 10512.5792,W is longitude in degrees.decimal minutes, west
Number of satellites seen: 08
Altitude: 1577 meters

Reading this into your application is very simple, so is carving up the message string into separate values.

I would suggest you think about what will trigger a report. A suggestion is if the RPI moves out of a designated box, or moves more than X meters in time T, then a report is made with the current lat/lon, and anything else that maybe useful (calculated speed, battery condition etc). This trigger logic is fairly basic, so I suggest you just write it, keep it simple. Do all the complex tracking, GIS etc at the other end.

This is the RTC sleep/wake hat: https://spellfoundry.com/product/sleepy-pi-2/

So the GPS system has no interrelationship with the GPRS data connection. The GPS is just a receiver sending the RPI text data, your application will then send it onto your backend. As long as the SIM supports 2G GPRS, then you can send anything over it. The SIM doesn't have anything to do with the GPS.

All GPS receivers need an antenna, but what you are referring to is receivers with an internal strip or patch antenna, usually on the PCB itself. Larger external antennas are usually needed when the GPS is inside a metal shell, car or container. Here is an article on building a simple GPS patch antenae https://www.eevblog.com/forum/rf-microw ... h-antenna/ Antenae design and location is just a function of what you are installing the RPI in. Bigger is always better of course.
..the only thing worse than a stupid question is a question not asked.

YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

Re: GPS/GRPS tracking help

Tue May 14, 2019 6:58 pm

Great you have been such a help in a stepping stone towards this project i have a lot of reading material now thanks so much!


This will simply be placed in my car mostly as a fun project but also for security should a theft happen (Nobody is desperate to steal my car but ya never know!)

So geo fencing is what i think you are refering to when it leaves an area? That is a sound plan.


I guess that battery life is such a broad subject as it can mean so many things.

I can see the pro trackers claim a 4-6 week battery life how do they achieve this and with what?

I have toyed with using a 9V battery with a step down for 5v so 9v should be enough overhead but i am yet to investigate the math until i get the device and can figure out how much/little i will want to use from it.

I need to lean a little more on leaving the device in a low power state as not to drain battery and ONLY send information when the vehicle is moving or moves out of the geo fence.

Another thought of course would be to get data on battery life etc.

As far as GPS signal goes i plan to leave the device hidden out of sight in the spare wheel compartment or in the glovebox. Since these devices work better with eye to sky signal.

So for that must i face the antenna somewhere such as the dashboard/windscreen or might it be ok tucked away out of sight?


Items arrive tomorrow i am excited to get building!

Thanks again for detailed information.

YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

Re: GPS/GRPS tracking help

Thu May 16, 2019 2:13 pm

So i now have the device

I managed to do some basic settings after lots of head scratching and wondering why the command AT would produce nothing but messes of code;

Turned out i had to disable login in interface settings of raspi-config results of interface

pi@raspitrk:~ $ dmesg | grep tty
[ 0.000000] Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 smsc95xx. vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=28ff56cf-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
[ 0.001341] console [tty1] enabled
[ 0.982526] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2
[ 0.990912] 20215040.serial: ttyS0 at MMIO 0x0 (irq = 160, base_baud = 31250000) is a 16550



Using minicom -D /dev/ttyS0 i can get responses from
AT
OK


Great i thought proof that its is working and communicating as it should.

The next part is parsing GPS data into a readable format for now i would just like to get some basic details so i can wrap my head around how things work.

Any tips or programs i could use?

EDIT** So i managed to get AT commands running and general GPS data that you had shown above (thanks for breaking that down)

Now mincom -D works perfectly

However attempting to use gpsmon or even cat /dev/ttyS0
Just does not yield any data. I am believing that the GPS isn't active since i can turn on via minicom via AT commands CGPSPWR=1 etc

I have looked through /etc/default/gpsmon and set the device as ttyS0 but i can still get no data to poll even after waiting for some time.

Any thoughts?

Thanks

User avatar
omegaman477
Posts: 148
Joined: Tue Feb 28, 2017 1:13 pm
Location: Sydney, Australia

Re: GPS/GRPS tracking help

Fri May 17, 2019 7:11 am

Minicom works because it sets the baud rate , word length and stop bits correctly. Usually NMEA interfaces operate at 9600, 8, N, 1 as default. You need your software (or a through the cmd line) to do the same before you try to read.

This will set the baud rate to 9600, 8 bits, 1 stop bit, no parity:

stty -F /dev/ttyS0 9600 cs8 -cstopb -parenb
..the only thing worse than a stupid question is a question not asked.

YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

Re: GPS/GRPS tracking help

Fri May 17, 2019 7:26 am

Yeah that makes complete sense as I noticed it defaulting to a crazy high baud rate

I have all weekend to work on this properly so hopefully with gpsmon working I can move onto ppp to make this device remote which should work fine as my carrier I believe supports all the requirements

After which the fun starts with finding how to run scripts which are readymade to automate the polling of the device and relay co ordinates back and forth via SMS

I have since ordered a ready made GPS tracking device which states a battery life of 4-5 weeks. I will be interested to maybe try and get data from it such as OS etc etc if it has a communication port. But since it’s a branded device it may be harder than I think.

@omegaman i realise you are in sydney so time zone issues as its currently early hours. Do you happen to have discord and maybe you could help me out a little there in real time since you really seem to have knowledge basis of this.

Thank You.

User avatar
omegaman477
Posts: 148
Joined: Tue Feb 28, 2017 1:13 pm
Location: Sydney, Australia

Re: GPS/GRPS tracking help

Sun May 19, 2019 3:32 am

Happy to help anytime
..the only thing worse than a stupid question is a question not asked.

YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

Re: GPS/GRPS tracking help

Sun May 19, 2019 12:01 pm

Thank You

Well i since made some progress and have learned that the serial port can only communicate one data stream at a time so my theory of using ppp dial up retrieving gps data remotely is going to take some more thought.

Thus far i have been able to setup an auto start script for the gprs hat to power on when the pi is booted and initated a dial up script to get ppp running out to the 2G network.

I have also setup a vpn on the device so it communicates through my network in the hope i can ssh to it and get around the NAT of the mobile network but i can't quite figure out how to ssh to it yet because of course bringing down the wlan0 i am using currently to ssh to the device renders it unusable.

My next thought is wondering if i can turn off the bluetooth serial device and switch the gps to that as i read some things about gpio but i am still researching this.

my discord id is #1696

if you ever use that and would be able to help me.

YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

Re: GPS/GRPS tracking help

Mon May 20, 2019 1:55 pm

edit: As i thought if i first set the buad rate to -b 9600 in mini and start AT+CGSPSTST=1

exit minicom and start Gpsmon it gets results

So something is going on where a cold boot doesn't work.

Would the RTC battery on the gprs device help with this at all? From what I understand it’s just for keeping time?

My thoughts on which serial device were wrong as stated below

end edit:

So i think i have reached a point where i might be able to understand things

I believe the reason why gpsmon can't activate and poll the connection is because the gps power isn't i am not sure if gpsmon even polls the AT+CGPSPWR=1 to start the device?

So i have concluded with that for now. My thoughts to this after much reading is that the serial0 device is taken up by ttyS0 which seems to be less powerful than ttyAMA0? Not all together sure about this and i will investigate it more as it seems people are using dtoverlay-pi3=disablebt and then taking over the AMA0 device? Not sure if this is a pi3 specific though as i use the pi zero.

attached a pic to show.
Attachments
Capture.PNG00.PNG
Capture.PNG00.PNG (2.26 KiB) Viewed 1002 times
Capture.PNG0.PNG
Capture.PNG0.PNG (4.1 KiB) Viewed 1003 times

YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

Re: GPS/GRPS tracking help

Tue May 21, 2019 3:08 am

Code: Select all

sudo dmesg | grep tty
[    0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 smsc95xx.macaddr= vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=c6a9741f-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
[    0.001426] console [tty1] enabled
[    0.529838] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2
[    0.537947] 20215040.serial: ttyS0 at MMIO 0x0 (irq = 53, base_baud = 31250000) is a 16550
[   69.618669] pps pps0: source "/dev/ttyS0" added
[  213.646566] pps pps0: source "/dev/ttyS0" added
[  483.279014] pps pps0: source "/dev/ttyS0" added
[  799.751537] pps pps0: source "/dev/ttyS0" added

pi@r:~ $ sudo lsof /dev/ttyS0
COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gpsd    832 gpsd    7u   CHR   4,64      0t0 6090 /dev/ttyS0

sudo netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      491/sshd
tcp        0      0 0.0.0.0:2947            0.0.0.0:*               LISTEN      1/init
tcp6       0      0 :::22                   :::*                    LISTEN      491/sshd
tcp6       0      0 ::1:2947                :::*                    LISTEN      1/init


 sudo lsof /dev/ttyS0
COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gpsd    832 gpsd    7u   CHR   4,64      0t0 6090 /dev/ttyS0

Does any of this look correct?

I think this may be the issue but going on from guides people have set the listen port in gpsd settings to 0.0.0.0 instead of 127.0.0.1 which i have done but i still get

Code: Select all

sudo gpsd -N -D3 -F /var/run/gpsd.sock
gpsd:INFO: launching (Version 3.16)
gpsd:ERROR: can't bind to IPv4 port gpsd, Address already in use
gpsd:ERROR: maybe gpsd is already running!
gpsd:ERROR: can't bind to IPv6 port gpsd, Address already in use
gpsd:ERROR: maybe gpsd is already running!
gpsd:INFO: command sockets creation failed, netlib errors -1, -1

YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

Re: GPS/GRPS tracking help

Wed May 22, 2019 3:00 pm

Still stumped on this any help would greatly be appreciated

My only action is to try a usb gps module but I want to avoid that.

Even running sttty command to set the baud rate yields no results in gpsmon or cat /dev/ttySO etc

It’s as though the power for GPS is off which I assume is default as they pull quite a lot?

But as soon as set the commands for power and start the AT+CGPSOUT=32 I get data with cgps-s

YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

Re: GPS/GRPS tracking help

Wed May 22, 2019 6:31 pm

Nobody?

Guess this place is dead.

Thanks anyway to those that helped.

YitEarp
Posts: 45
Joined: Mon May 13, 2019 7:44 pm

Re: GPS/GRPS tracking help

Mon May 27, 2019 2:58 pm

In the hope this may help somebody i mananged to get things working and output to pynmea to parse correctly this is my code

Now i just want to figure out how to append it to googlemaps and trigger it by a call or sms to send the location

Code: Select all

#!/usr/bin/python

import serial
import time
import pynmea2


#Enable Serial Communication
ser = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)
#Transmitting AT Commands to the Modem
#'r\n' indicates the Enter key



ser.write('AT'+'\r\n')
str = ser.readline()
print str
time.sleep(.1)

ser.write('AT+CGNSPWR=1'+'\r\n')
str = ser.readline()
print str
time.sleep(.1)

ser.write('AT+CGPSOUT=32'+'\r\n')
str = ser.readline()
print str
time.sleep(3)

ser.write('AT+CGNSTST=1'+'\r\n')
str = ser.readline()
print str
time.sleep(.1)

ser.flushInput()
ser.flushOutput()
def parseGPS(str):
    if str.find('GGA') > 0:
        msg = pynmea2.parse(str)
        print "Timestamp: %s -- Lat: %s %s -- Lon: %s %s -- Altitude: %s %s" % (msg.timestamp,msg.lat,msg.lat_dir,msg.lon,msg.lon_dir,msg.altitude,msg.altitude_units)


while True:
    str = ser.readline()
    parseGPS(str)

Return to “Other projects”