beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

gpsmon

Sun Jun 04, 2017 9:10 pm

My Pi only works with the command:
"gpsmon /dev/serial0" in which case it gives all the data i.e. lat, lon and time and updates regularly. However, it gives a blank table with "cgps -s" - no lat, lon etc. Most of the tutorials say to use cgps but I tried without success. Any idea why?

User avatar
topguy
Posts: 7078
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: gpsmon

Sun Jun 04, 2017 11:15 pm

Yes because gpsmon is a program that reads data directly from the serial port, but cgps is a program that read GPS positions from the GPSD service.
https://www.systutorials.com/docs/linux/man/1-cgps/

If your GPSD service was correctly set-up it would read the data from the serialport, and cgps would work and gpsmon would fail.

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Mon Jun 05, 2017 1:22 am

Thanks.
Tried this - no luck! Not sure what to use for localhost (in the description based on the link you sent). I used the file name i.e. gpsdDATA and port # 2947
gpsdData:2947/dev/ttyS1 #error "invalid syntax"

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Mon Jun 05, 2017 1:34 am

I then tried:
[python]
pi@raspberrypi:~ $ cgps 192.168.0.11:2947/ttyS0
cgps: no gpsd running or network error: -2, can't get host entry
[/python]

User avatar
bensimmo
Posts: 5269
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: gpsmon

Mon Jun 05, 2017 6:53 am

No, go back to some things you did a long while back.

Setup gpsd on the Pi.
Leave the port alone.
It is /dev/serial0
NOT tty0/AMA0 or anything else serial0 sorts it all out for you.

Assuming you installed gpsd and it's tools.

sudo killall gpsd
sudo gpsd /dev/serial0 -F /var/run/gpsd.sock

Then
cgps -s
Or in in pixel you can try
xgps

If that is not working then you may need to stop a gpsd service.

sudo systemctl stop gpsd.socket
sudo systemctl disable gpsd.socket

Try again.

If that doesn't work you config file may be messed up.
sudo leafpad /etc/default/gpsd

Check it's pointing to /dev/serial0

So it may be something like
START_DAEMON="true"
GPSD_OPTIONS="-n"
DEVICES="/dev/serial0"
GPSD_SOCKET="/var/run/gpsd.sock"

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Mon Jun 05, 2017 12:35 pm

Thanks a lot! Works like a charm.

Now have to put it in a .csv file to import into google maps.

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Mon Jun 05, 2017 8:24 pm

While trying to write into a .csv file, noticed that it does not write the lat, lon values to the .csv file but prints to the python shell. Tried this script for writing to the file but this just does not execute. The print statements work fine and print lat, lon in the Python shell but file write does not work.

Code: Select all

 while True:
            f.write(str(gpsd.fix.longitude) + "," + str(gpsd.fix.latitude) + "\n") 
         

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Tue Jun 06, 2017 4:44 pm

Got some useful replies - but still am unable to write to the file i.e. "f.write" just does not work!

pcmanbob
Posts: 11064
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: gpsmon

Tue Jun 06, 2017 8:37 pm

As all ways please post your code, make sure you include the print line you were using as well so we know at what point you program was able to see the variables.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Tue Jun 06, 2017 9:33 pm

The 2 prints work fine and print lat, lon; just the f.write does not work!
[python]
from gps import *
import time
import threading
f = open("locations.csv","w")
gpsd = None
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
global gpsd
gpsd=gps(mode=WATCH_ENABLE)
self.current_value = None
self.running = True

def run(self):
global gpsd
while gpsp.running:
gpsd.next()
print (gpsd.fix.longitude)
print (gpsd.fix.latitude)

if __name__ == '__main__':

gpsp=GpsPoller()
try:
gpsp.start()

while True:
f.write(str(gpsd.fix.longitude) + "," + str(gpsd.fix.latitude) + "\n")

time.sleep(30)
except(KeyboardInterrupt,SystemExit):
f.close()
gpsp.running = False
gpsp.join()
[/python]

pcmanbob
Posts: 11064
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: gpsmon

Tue Jun 06, 2017 10:11 pm

beatsal wrote:The 2 prints work fine and print lat, lon; just the f.write does not work!
[python]
from gps import *
import time
import threading
f = open("locations.csv","w")
gpsd = None
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
global gpsd
gpsd=gps(mode=WATCH_ENABLE)
self.current_value = None
self.running = True

def run(self):
global gpsd
while gpsp.running:
gpsd.next()
print (gpsd.fix.longitude)
print (gpsd.fix.latitude)

if __name__ == '__main__':

gpsp=GpsPoller()
try:
gpsp.start()

while True:
f.write(str(gpsd.fix.longitude) + "," + str(gpsd.fix.latitude) + "\n")

time.sleep(30)
except(KeyboardInterrupt,SystemExit):
f.close()
gpsp.running = False
gpsp.join()
[/python]
You have been asked before but I will ask again please post you code using code tags because as it is with out the indentation it makes no sense.

I presume that when you say the print statements work that you see the values updating ?

Edit.
So I hope I have the indenting correct but its up to you to check it.( result of not using code tags to post code )

Code: Select all

from gps import *
import time
import threading
lonvalue = "0.00"
latvalue = "0.00"

gpsd = None


class GpsPoller(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd
        gpsd=gps(mode=WATCH_ENABLE)
        self.current_value = None
        self.running = True
		
    def run(self):
        global gpsd, lonvalue, latvalue
        while gpsp.running:
            gpsd.next()
            lonvalue = str(gpsd.fix.longitude)
            latvalue = str(gpsd.fix.latitude)
            print lonvalue
            print latvalue

if __name__ == '__main__':

gpsp=GpsPoller()
try:
    gpsp.start()


    while True:
        f = open("/home/pi/locations.csv","a")
        f.write (lonvalue + "," + latvalue + "\n")
        f.close()
        time.sleep(30)

except(KeyboardInterrupt,SystemExit):
gpsp.running = False
gpsp.join()
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Tue Jun 06, 2017 11:28 pm

Thanks. the 2 prints work fine. There seems to be improvement with f.write as it wrote 0.0,0.0 once in locations.csv, but nothing after. The f.close in the loop - is it necessary in the loop?

pcmanbob
Posts: 11064
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: gpsmon

Wed Jun 07, 2017 8:35 am

beatsal wrote:Thanks. the 2 prints work fine. There seems to be improvement with f.write as it wrote 0.0,0.0 once in locations.csv, but nothing after. The f.close in the loop - is it necessary in the loop?

So from that we can get that the 2 variables lonvalue and latvalue are not being shared globally. which is why you only got the initial 0.0 values that I set. I am at a lsos at the moment as to why the variables are not being shared globally.

if you leave the program running you should get lots of 0.0,0.0 entries in the file one for each time your while true loop executes.
do your printed values change / repeat or do you only get one printed value.

I made it write the file like that so we knew the file was being opened and closed reliably.

try adding the values to global here as well.

Code: Select all

class GpsPoller(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd, lonvalue, latvalue
        gpsd=gps(mode=WATCH_ENABLE)
        self.current_value = None
        self.running = True
and please can you repost your code using code tags , just so I can check it matches what I have including indentation.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Wed Jun 07, 2017 1:50 pm

It prints this once in locations.csv:
0.0,0.0

Code: Select all

from gps import *
import time
import threading
lonvalue = "0.00"
latvalue = "0.00"

gpsd = None


class GpsPoller(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd, lonvalue, latvalue
        gpsd=gps(mode=WATCH_ENABLE)
        self.current_value = None
        self.running = True
      
    def run(self):
        global gpsd, lonvalue, latvalue
        while gpsp.running:
            gpsd.next()
            lonvalue = str(gpsd.fix.longitude)
            latvalue = str(gpsd.fix.latitude)
            print lonvalue
            print latvalue

if __name__ == '__main__':

        gpsp=GpsPoller()
        try:
            gpsp.start()


            while True:
               f = open("/home/pi/locations.csv","a")
               f.write (lonvalue + "," + latvalue + "\n")
               #f.close()
               time.sleep(30)

        except(KeyboardInterrupt,SystemExit):
               gpsp.running = False
               gpsp.join()



pcmanbob
Posts: 11064
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: gpsmon

Wed Jun 07, 2017 2:11 pm

OK did spot one error # in frount of f.close().

but lets try this

Code: Select all

from gps import *
import time
import threading
lonvalue = "0.00"
latvalue = "0.00"

gpsd = None
f = open("/home/pi/locations.csv","a")

class GpsPoller(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd, lonvalue, latvalue
        gpsd=gps(mode=WATCH_ENABLE)
        self.current_value = None
        self.running = True
     
    def run(self):
        global gpsd, lonvalue, latvalue
        while gpsp.running:
            gpsd.next()
            lonvalue = str(gpsd.fix.longitude)
            latvalue = str(gpsd.fix.latitude)
            f.write (lonvalue + "," + latvalue + "\n")
            print lonvalue
            print latvalue

if __name__ == '__main__':

        gpsp=GpsPoller()
        try:
            gpsp.start()


            while True:
               print " Loop Runing"
               time.sleep(30)

        except(KeyboardInterrupt,SystemExit):
               f.close()
               gpsp.running = False
               gpsp.join()
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Wed Jun 07, 2017 3:23 pm

Thanks; looks good.

pcmanbob
Posts: 11064
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: gpsmon

Wed Jun 07, 2017 4:23 pm

beatsal wrote:Thanks; looks good.

OK let me know if it works and if you get more than one set of results in the CSV file.

look forward to hearing the result.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Wed Jun 07, 2017 5:28 pm

Posted a few line from locations.csv. Thanks
0.0,0.0
0.0,0.0
-79.254083333,43.752078333
-79.254085,43.752078333
-79.254085,43.752078333

pcmanbob
Posts: 11064
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: gpsmon

Thu Jun 08, 2017 8:54 am

beatsal wrote:Posted a few line from locations.csv. Thanks
0.0,0.0
0.0,0.0
-79.254083333,43.752078333
-79.254085,43.752078333
-79.254085,43.752078333

That's looking good, I still don't know why it would not work with the file write in its own loop unless its a threading problem.

now because we changed the file is written to, we used a for append, once you have copied the data off you will need to delete the csv file, or you could make you program change its name on shutdown.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Fri Jun 09, 2017 12:45 pm

Yes, you are right. I tried it now and it does not write to locations.csv. Also tried writing to locations1.csv - no luck!

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Fri Jun 09, 2017 12:52 pm

Tried writing to a new file locations3.csv - again no luck!

pcmanbob
Posts: 11064
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: gpsmon

Fri Jun 09, 2017 2:09 pm

Well you need to show us what you did, just saying it did not work tells us nothing .

remember information that what we need................................. we want information..................
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Fri Jun 09, 2017 4:17 pm

Did not change anything just the file name from locations.csv to locations3.csv, nothing written in locations3.csv:

Code: Select all

from gps import *
import time
import threading
lonvalue = "0.00"
latvalue = "0.00"

gpsd = None
f = open("/home/pi/locations3.csv","a")

class GpsPoller(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd, lonvalue, latvalue
        gpsd=gps(mode=WATCH_ENABLE)
        self.current_value = None
        self.running = True
     
    def run(self):
        global gpsd, lonvalue, latvalue
        while gpsp.running:
            gpsd.next()
            lonvalue = str(gpsd.fix.longitude)
            latvalue = str(gpsd.fix.latitude)
            f.write (lonvalue + "," + latvalue + "\n")
            print lonvalue
            print latvalue

if __name__ == '__main__':

        gpsp=GpsPoller()
        try:
            gpsp.start()


            while True:
               print " Loop Runing"
               time.sleep(30)

        except(KeyboardInterrupt,SystemExit):
               f.close()
               gpsp.running = False
               gpsp.join()


pcmanbob
Posts: 11064
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: gpsmon

Fri Jun 09, 2017 4:40 pm

beatsal wrote:Did not change anything just the file name from locations.csv to locations3.csv, nothing written in locations3.csv:

Code: Select all

from gps import *
import time
import threading
lonvalue = "0.00"
latvalue = "0.00"

gpsd = None
f = open("/home/pi/locations3.csv","a")

class GpsPoller(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd, lonvalue, latvalue
        gpsd=gps(mode=WATCH_ENABLE)
        self.current_value = None
        self.running = True
     
    def run(self):
        global gpsd, lonvalue, latvalue
        while gpsp.running:
            gpsd.next()
            lonvalue = str(gpsd.fix.longitude)
            latvalue = str(gpsd.fix.latitude)
            f.write (lonvalue + "," + latvalue + "\n")
            print lonvalue
            print latvalue

if __name__ == '__main__':

        gpsp=GpsPoller()
        try:
            gpsp.start()


            while True:
               print " Loop Runing"
               time.sleep(30)

        except(KeyboardInterrupt,SystemExit):
               f.close()
               gpsp.running = False
               gpsp.join()

Sorry but I am confused , first you said it was working
Posted a few line from locations.csv. Thanks
0.0,0.0
0.0,0.0
-79.254083333,43.752078333
-79.254085,43.752078333
-79.254085,43.752078333
then you said this ?
Yes, you are right. I tried it now and it does not write to locations.csv. Also tried writing to locations1.csv - no luck!
what was I right about.

you need to explain your self better

are you now saying that the program does not work now ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: gpsmon

Fri Jun 09, 2017 5:37 pm

Right about that it did not write to locations.csv after shutdown. What I am saying now is that it does not write at all, only prints - like before. Hence, program does not work now.

Return to “Other projects”