0

Working on a data acquisition project where I am trying to send GPS data to cloud.

Board: Customised board based on the schematics of Raspberry Pi Compute Module 3 Lite and I/O baord. Have added GSM and GPS modules to it for my requirements.

OS : Raspbian Stretch Lite (June 2018 release, latest one)

GPS Module used: Ublox EVAM8M

My code:

from systemd import journal
import gps
import time
import threading
import datetime

# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

while True:
    try:
        report = session.next()
        # Wait for a 'TPV' report and display the current time
        # To see all report data, uncomment the line below
        #   print report
        if report['class'] == 'TPV':
            if hasattr(report, 'time'):
                timestamp = report.time
                print timestamp
                journal.send(
                channel='gps',
                priority=journal.Priority.INFO,
                timestamp="%f" % (time.time()*1000),
                )

           if report['class'] == 'TPV':
            if hasattr(report, 'lat'):
                lat = report.lat
                print lat
                journal.send(
                channel='gps',
                priority=journal.Priority.INFO,
                lat='lat',
                )  

        if report['class'] == 'TPV':
            if hasattr(report, 'lon'):
                long = report.lon
                print long
                journal.send(
                channel='gps',
                priority=journal.Priority.INFO,
                long='long',
                )

        if report['class'] == 'TPV':
            if hasattr(report, 'alt'):
                altitude = report.alt
                print altitude
                journal.send(
                channel='gps',
                priority=journal.Priority.INFO,
                altitude='altitude',
                )


    except KeyError:
        pass
    except KeyboardInterrupt:
        quit()
    except StopIteration:
        session = None
        print "GPSD has terminated"

I got this code from an Adafruit tutorial: https://learn.adafruit.com/adafruit-ult ... i?view=all and I installed systemd from pypi: https://pypi.org/project/systemd/ . While I am able to perfectly display timestamp, lat, lon and alt on the terminal, I am not able to send this data to the cloud. I know this because I receive the timestamp alone on the journal but not the other values. I also have another python code which does the exact same thing, and I am able to see all the data on the website. I am using python3 and not python to run that code. But the problem with that code is that, it causes the CPU to get really hot (that's another story altogether) hence I cannot use that code.

Coming back to the code here, what am I missing? I am not getting any error. Just that, I see nothing on the website.

  • Please clarify what you are trying to do. You are using a module to write to the log on the local Pi. So what do you mean by sending it to the cloud? Where exactly do you want your data to go? And your code will not run with python 3; all print statements are not compatible – Dirk Aug 22 '18 at 12:47
  • How do you know the problem is with your script writing to the journal, not the website code reading from it? Also, if you have code that works, why aren't you working on that? – Dmitry Grigoryev Aug 24 '18 at 8:17
  • @DmitryGrigoryev I know that the website code is working fine because all the other codes work on it perfectly. I am not using the other python code as it causes one the cores of the Pi to touch to 100% and that makes it hot. I already mentioned that in my post. – Sohil Mehta Aug 28 '18 at 14:28
0

Problem solved!! I wasn't seeing any data on the website because, I need to send the entire data packet together. What I am trying to do is send all the data to the journal and from there I have a pipeline that takes all the data to an interactive tool that displays it in the form of graphs and all. So this is what I modified in my code:

while True:
    try:
        report = session.next()
        # Wait for a 'TPV' report and display the current time
        # To see all report data, uncomment the line below
        #print report
        if report['class'] == 'TPV':
            if hasattr(report, 'time'):
                timestamp = report.time
                print timestamp

            if hasattr(report, 'lat'):
               latitude = report.lat
               print latitude

            if hasattr(report, 'lon'):
               longitude = report.lon
               print longitude    

            if hasattr(report, 'alt'):
               altitude = report.alt
               print altitude

           journal.send(
           channel = 'gps',
           priority = journal.Priority.INFO,
           timestamp = "%f" % (time.time()*1000),
           latitude = "%f" % (latitude),
           longitude = "%f" % (longitude), 
           altitude = "%f" % (altitude),
           )
  • Is this your answer? Does it work? In a few days you will have the option of accepting this answer. – NomadMaker Aug 22 '18 at 17:49
  • Yes. It works now. And yeah I am aware of accepting the answer in two days. – Sohil Mehta Aug 23 '18 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.