# limit feed updates to every 3 seconds, avoid IO throttle loop_delay = 5 # We dont' have a GPS hooked up, but let's fake it for the example/test: # (replace this data with values from a GPS hardware module) value = 0 lat = 40.726190 lon = -74.005334 ele = 6 # elevation above sea level (meters) while True: print('\nSending Values to location feed...\n') print('\tValue: ', value) print('\tLat: ', lat) print('\tLon: ', lon) print('\tEle: ', ele) # Send location data to Adafruit IO aio.send_location_data(location.key, value, lat, lon, ele) # shift all values (for test/demo purposes) value += 1 lat -= 0.01 lon += -0.02 ele += 1 # Read the location data back from IO print('\nData Received by Adafruit IO Feed:\n') data = aio.receive(location.key) print('\tValue: {0}\n\tLat: {1}\n\tLon: {2}\n\tEle: {3}'.format( data.value, data.lat, data.lon, data.ele)) # wait loop_delay seconds to avoid api throttle time.sleep(loop_delay)
#Check if sending GPS is possible: if (gps.initialized): #Check if GPS has a fix: if (gps.check_gps()): #value, lat, long, alt latitude = gps.read_gps_latitude() longitude = gps.read_gps_longitude() altitude = gps.read_gps_altitude() print('\nSending GPS Infos to location feed...\n') print('\tLat: ', latitude) print('\tLon: ', longitude) print('\tAlt: ', altitude) #Sending Data to Adafruit: ## 1. Directly send to Adafruit.IO if (useAIO): aio.send_location_data(locationFeed.key, value, latitude, longitude, altitude) ## 2. Send to Lora if (useLORA): _call_lora( "'gps:" + str(value) + "," + str(latitude) + "," + str(longitude) + "," + str(altitude) + "'" ) #message need to be encapsulated " ' message ' " #time.sleep(3) # Adafruit: 3s timeout. time.sleep( loraTimer) # Adafruit: 3s timeout |Lora: 5s timeout else: print('No GPS Signal... sending no Data') else: print('GPS not initialized!')
rssifeed = aio.create_feed(Feed(name='rssi')) while True: line = gps.readline() match = re.search(r'Got: (NODE\d) (\d+) RSSI (-\d+) Location (-?\d+\.\d+) (-?\d+\.\d+) (\d+\.\d+) at (\d{1,2}:\d{1,2}:\d{1,2}) .*', line) if match: lat = float(match.group(4)) lon = float(match.group(5)) alt = float(match.group(6)) rssi = match.group(3) name = "%s-%s-%s" % (rssi, match.group(2), match.group(7)) print "%f, %f, %f, %s" % (lat, lon, alt, name) # Send location data to Adafruit IO aio.send_location_data(location.key, name, lat, lon, alt) aio.send(rssifeed.key, rssi) # Read the location data back from IO print('\nData Received by Adafruit IO Feed:\n') data = aio.receive(location.key) print('\tValue: {0}\n\tLat: {1}\n\tLon: {2}\n\tEle: {3}' .format(data.value, data.lat, data.lon, data.ele)) else: match = re.search(r'Got: (NODE\d) - (\d+) RSSI (-\d+) GPS no fix', line) if match: rssi = march.group(3) aio.send(rssifeed.key, rssi) data = aio.receive(rssifeed.key) print('\Rssi: {0}'.format(data.rssi))