gpsmon
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?
"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?
Re: gpsmon
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.
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.
Re: gpsmon
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"
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"
Re: gpsmon
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]
[python]
pi@raspberrypi:~ $ cgps 192.168.0.11:2947/ttyS0
cgps: no gpsd running or network error: -2, can't get host entry
[/python]
Re: gpsmon
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"
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"
Re: gpsmon
Thanks a lot! Works like a charm.
Now have to put it in a .csv file to import into google maps.
Now have to put it in a .csv file to import into google maps.
Re: gpsmon
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")
Re: gpsmon
Got some useful replies - but still am unable to write to the file i.e. "f.write" just does not work!
Re: gpsmon
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
The use of crystal balls & mind reading are not supported
Re: gpsmon
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]
[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]
Re: gpsmon
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.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]
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
The use of crystal balls & mind reading are not supported
Re: gpsmon
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?
Re: gpsmon
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
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported
The use of crystal balls & mind reading are not supported
Re: gpsmon
It prints this once in locations.csv:
0.0,0.0
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()
Re: gpsmon
OK did spot one error # in frount of f.close().
but lets try this
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
The use of crystal balls & mind reading are not supported
Re: gpsmon
Thanks; looks good.
Re: gpsmon
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
The use of crystal balls & mind reading are not supported
Re: gpsmon
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
0.0,0.0
0.0,0.0
-79.254083333,43.752078333
-79.254085,43.752078333
-79.254085,43.752078333
Re: gpsmon
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
The use of crystal balls & mind reading are not supported
Re: gpsmon
Yes, you are right. I tried it now and it does not write to locations.csv. Also tried writing to locations1.csv - no luck!
Re: gpsmon
Tried writing to a new file locations3.csv - again no luck!
Re: gpsmon
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..................
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
The use of crystal balls & mind reading are not supported
Re: gpsmon
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()
Re: gpsmon
Sorry but I am confused , first you said it was workingbeatsal 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()
then you said this ?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
what was I right about.Yes, you are right. I tried it now and it does not write to locations.csv. Also tried writing to locations1.csv - no luck!
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
The use of crystal balls & mind reading are not supported
Re: gpsmon
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.