1

I'm making a project with a raspberry pi 4 and a NEO 6M gps module. I use pubnub to communicate from the raspberry pi to my self made website with a google map. The problem is that google maps crashes everytime I run the following script:

import RPi.GPIO as GPIO
import time
import board
import busio

import adafruit_gps

import pubnub
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
from pubnub.callbacks import SubscribeCallback
from pubnub.enums import PNOperationType, PNStatusCategory
def publish_callback(result, status):
        pass

pnconfig = PNConfiguration()
pnconfig.subscribe_key = ""
pnconfig.publish_key = ""
pnconfig.ssl = False
pubnub = PubNub(pnconfig)

import serial
uart = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=10)

gps = adafruit_gps.GPS(uart, debug=False)

gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0")


gps.send_command(b"PMTK220,1000")

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

last_print = time.monotonic()
while True:
        gps.update()
        current = time.monotonic()
        if current - last_print >= 1.0:
                last_print = current
        if not gps.has_fix:
                print("Waiting for fix...")
                continue
        print("=" * 40)
        print(
                "Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format(
                gps.timestamp_utc.tm_mon,
                gps.timestamp_utc.tm_mday,
                gps.timestamp_utc.tm_year,
                gps.timestamp_utc.tm_hour,
                gps.timestamp_utc.tm_min,
                gps.timestamp_utc.tm_sec,
                )
        )
        dictionary = {"latitude": gps.latitude, "longitude": gps.longitude}
        pubnub.publish().channel("CHANNEL").message(dictionary).pn_async(publish_callback)
        print("Latitude: {0:.6f} degrees".format(gps.latitude))
        print("Longitude: {0:.6f} degrees".format(gps.longitude))
        print("Fix quality: {}".format(gps.fix_quality))

        if gps.satellites is not None:
                print("# satellites: {}".format(gps.satellites))
        if gps.altitude_m is not None:
                print("Altitude: {} meters".format(gps.altitude_m))
        if gps.speed_knots is not None:
                print("Speed: {} knots".format(gps.speed_knots))
        if gps.track_angle_deg is not None:
                print("Track angle: {} degrees".format(gps.track_angle_deg))
        if gps.horizontal_dilution is not None:
                print("Horizontal dilution: {}".format(gps.horizontal_dilution))
        if gps.height_geoid is not None:
                print("Height geo ID: {} meters".format(gps.height_geoid))

What I want to do is set a delay on the lat & long that gets send to pubnub so it doesn't crash Google maps. Does anybody know how I should do that? Any help would be appreciated!

T bow
  • 33
  • 4
  • 2
    I believe you can just use a `sleep` delay in a loop to do this. See this post for answer: https://stackoverflow.com/questions/2697039/python-equivalent-of-setinterval – Craig Conover Jun 09 '21 at 16:36
  • Does this answer your question? [Python Equivalent of setInterval()?](https://stackoverflow.com/questions/2697039/python-equivalent-of-setinterval) – Craig Conover Jun 09 '21 at 16:36
  • And did you just repost the same question with different title as this one: https://stackoverflow.com/questions/67872203/add-gps-to-your-raspberry-pi-project-with-google-maps-pubnub - if so, you should delete the other one. – Craig Conover Jun 09 '21 at 16:40
  • is this resolved for you? – Craig Conover Jun 13 '21 at 22:52

0 Answers0