0

More specifically, I want to get the current/latest output from my GPSd process running on my webserver (Linux/Raspberry Pi) and display the live lat/lon, speed, and course.

I've tried writing a CGI script that I can call (jquery) which tails the output of gpspipe and grabs the latest data, but that is kind of slow - up to 5 seconds per call.

Sort of similar to calling a CGI script that runs "top -b -n 1" every couple of seconds and parse the output for the data your looking for.

I thought someone would have a more efficient way.

ckroger
  • 41
  • 4
  • i thought making the call to obtain your geo coordinates is almost instant. Did you find out what is eating up your 5 seconds? Given good network quality, I cannot see why you can't make multiple calls in less than a sec – Ji_in_coding Apr 07 '16 at 18:50
  • gpspipe connects to the gpsd port and waits for data and prints it. Then I have to wait for the correct sentence type that has the data I need, then parse that line. Perhaps there is a quicker way than to use gpspipe and a shell script, like writing a python client – ckroger Apr 07 '16 at 20:44

2 Answers2

0

Depending on how long the GPS unit takes for converting the Value (usually around a sec or so) You could do a small program that reads the GPS continously and store the values in a shared memory or file and get those values when calling the Rasp. So you would get [Time+Geolocation] and it could helps depending on your application.

If you want something more responsive you could use long polling once the GPS convertion is made. That way you could register multiples clients or services to listen to the GPS convertion web service.

Alegrowin
  • 321
  • 1
  • 14
  • I like that idea... but what about this: I have an MQTT service already running to distribute sensor data. I could write a gps client (Python) that publishes gps data to an MQTT topic and then use my javascript MQTT client to listen for updates. I'm already displaying sensor data from MQTT on my web page, so this would be a simple addition, using my current technology. – ckroger Apr 07 '16 at 20:57
0

There is a Python 2.7-3.5 gpsd client that could suit you. It has a threading adaptor you use to pick up the data how and when you want it. In four lines:

from agps3threaded import AGPS3mechanism

Then engage the thread triumvirate,

agps_thread = AGPS3mechanism()  # This instantiate the mechanism, as I believe it's called.
agps_thread.stream_data()    #  Stream the data from host, port, devicepath.
agps_thread.run_thread()  #  Iterate stream as a thread with throttle control for empty look ups.

Four lines of code that lets you connect, communicate and control most of what you expect a gpsd to do.

while True:  # All data is available via instantiated thread data_stream attributes. Confur
             # lines #140-ff of the client /usr/local/lib/python3.5/dist-packages/gps3/agps.py
      print('----------------')
      print(                   agps_thread.data_stream.time)
      print('Lat:{}   '.format(agps_thread.data_stream.lat))
      print('Lon:{}   '.format(agps_thread.data_stream.lon))
      print('Speed:{} '.format(agps_thread.data_stream.speed))
      print('Course:{}'.format(agps_thread.data_stream.track))
      print('----------------')
      sleep(60)  # Sleep, or do other things for as long as you like.

Without arguments between the parentheses, the threaded client defaults to host='127.0.01', port=2947, gpsd_protocol='json', and usnap=0.2, for a respectable default of 2/10th of a second micro nap after each empty socket lookup. The rest of the project is in DESCRIPTION.rst, or documented in the files themselves.

If you're looking for a Python interface to gpsd's shared memory segment, that is available as well

Nodak
  • 929
  • 1
  • 8
  • 14
  • Thanks! That might be a better solution. Right now I'm just reading the serial port and getting the raw GPS sentences. – ckroger Apr 08 '16 at 17:44