Raspberry pi gps map problem

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
matt8588
 
Posts: 12
Joined: Sat Nov 30, 2013 3:42 pm

Raspberry pi gps map problem

Post by matt8588 »

I am having a problem with a dashboard map
I am using https://github.com/adafruit/io-client-python

Code: Select all

from Adafruit_IO import Client
ADAFRUIT_IO_KEY = MYKEY
aio = Client(ADAFRUIT_IO_KEY)
aio.send('gpsmapData', str(gpsd.fix.latitude)+','+str(gpsd.fix.longitude)+','+str(gpsd.fix.altitude))
The uploaded data looks like this
41.BANNED,-70.BANNED,54.2
The data is uploaded into my feed but when I add a dashboard with a map linking to that feed nothing happens
Any help would be greatly appreciated!

User avatar
matt8588
 
Posts: 12
Joined: Sat Nov 30, 2013 3:42 pm

Re: Raspberry pi gps map problem

Post by matt8588 »

I got it working, i reverser engineered the data format and also had to change to mqtt
Here is how to format the gps data

Code: Select all

while True:
    d = OrderedDict()
    d['value'] = 23
    d['lat'] = gpsd.fix.latitude
    d['lon'] = gpsd.fix.longitude
    d['ele'] = gpsd.fix.altitude
    print "dump:",json.dumps(d)
    client.publish('gpsmapdata',json.dumps(d))
    time.sleep(10)

Here is my entire program

Code: Select all

# Example of using the MQTT client class to subscribe to and publish 
# feed values. Author: Tony DiCola

# Import standard python modules.
import random
import sys
import time
import os
from gps import *
from time import *
import time
import threading
# Import Adafruit IO MQTT client.
from Adafruit_IO import MQTTClient
import json
from collections import OrderedDict

# Set to your Adafruit IO key & username below.
ADAFRUIT_IO_KEY      = ''
ADAFRUIT_IO_USERNAME = ''  # See https://accounts.adafruit.com
                                                    # to find your username.
class GpsPoller(threading.Thread):
  def __init__(self):
    threading.Thread.__init__(self)
    global gpsd #bring it in scope
    gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
    self.current_value = None
    self.running = True #setting the thread running to true
 
  def run(self):
    global gpsd
    while gpsp.running:
      gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer

# Define callback functions which will be called when certain events happen.
def connected(client):
    # Connected function will be called when the client is connected to Adafruit IO.
    # This is a good place to subscribe to feed changes.  The client parameter
    # passed to this function is the Adafruit IO MQTT client so you can make
    # calls against it easily.
    print('Connected to Adafruit IO!  Listening for DemoFeed changes...')
    # Subscribe to changes on a feed named DemoFeed.
    #client.subscribe('DemoFeed')

def disconnected(client):
    # Disconnected function will be called when the client disconnects.
    print('Disconnected from Adafruit IO!')
    sys.exit(1)

def message(client, feed_id, payload):
    # Message function will be called when a subscribed feed has a new value.
    # The feed_id parameter identifies the feed, and the payload parameter has
    # the new value.
    print('Feed {0} received new value: {1}'.format(feed_id, payload))


# Create an MQTT client instance.
client = MQTTClient(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

# Setup the callback functions defined above.
client.on_connect    = connected
client.on_disconnect = disconnected
client.on_message    = message

# Connect to the Adafruit IO server.
client.connect()

# Now the program needs to use a client loop function to ensure messages are
# sent and received.  There are a few options for driving the message loop,
# depending on what your program needs to do.

# The first option is to run a thread in the background so you can continue
# doing things in your program.
client.loop_background()
# Now send new values every 10 seconds.
print('Publishing a new message every 10 seconds (press Ctrl-C to quit)...')
gpsp = GpsPoller() # create the thread
gpsp.start()
while True:
    d = OrderedDict()
    d['value'] = 23
    d['lat'] = gpsd.fix.latitude
    d['lon'] = gpsd.fix.longitude
    d['ele'] = gpsd.fix.altitude
    print "dump:",json.dumps(d)

    client.publish('gpsmapdata',json.dumps(d))
    time.sleep(10)

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”