added try except

bp-vhf
alanbjohnston 4 years ago committed by GitHub
parent 9463b7b93c
commit 44d7dfd01b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,230 +6,234 @@ import time
while (True): while (True):
print("Input telemetry string (or Control-C to exit)") try:
print("Input telemetry string (or Control-C to exit)")
# telem_string = input()
# telem_string = input()
telem_json = requests.get('https://api.aprs.fi/api/get?name=W3YP-11&what=loc&apikey=156390.XlXpKVPvnWcbNdn4&format=json', headers = {"User-Agent": "cubesatsim-aprs-tago-upload (+http://cubesatsim.org)"}).json()
telem_json = requests.get('https://api.aprs.fi/api/get?name=W3YP-11&what=loc&apikey=156390.XlXpKVPvnWcbNdn4&format=json', headers = {"User-Agent": "cubesatsim-aprs-tago-upload (+http://cubesatsim.org)"}).json()
lat = float(telem_json['entries'][0]['lat'])
lon = float(telem_json['entries'][0]['lng']) lat = float(telem_json['entries'][0]['lat'])
telem_string = telem_json['entries'][0]['comment'] lon = float(telem_json['entries'][0]['lng'])
times = int(telem_json['entries'][0]['time']) telem_string = telem_json['entries'][0]['comment']
times = int(telem_json['entries'][0]['time'])
print(lat)
print(lon) print(lat)
print(telem_string) print(lon)
print(telem_string)
chunks = telem_string.split(' ')
chunks = telem_string.split(' ')
#printchunks = str.split(' ')
#printchunks = str.split(' ')
print(chunks)
print(chunks)
temp = 0
pressure = 0 temp = 0
altitude = 0 pressure = 0
humidity = 0 altitude = 0
humidity = 0
timestamp = datetime.utcfromtimestamp(times).strftime('%Y-%m-%d %H:%M:%S')
print(timestamp) timestamp = datetime.utcfromtimestamp(times).strftime('%Y-%m-%d %H:%M:%S')
print(timestamp)
for i in range(len(chunks)):
if (chunks[i] == "BME280"): for i in range(len(chunks)):
print("Found BME280") if (chunks[i] == "BME280"):
temp = chunks[i+1] print("Found BME280")
pressure = chunks[i+2] temp = chunks[i+1]
altitude = chunks[i+3] pressure = chunks[i+2]
humidity = chunks[i+4] altitude = chunks[i+3]
print(temp) humidity = chunks[i+4]
print(humidity) print(temp)
if (chunks[i] == "MPU6050"): print(humidity)
print("Found MPU6050") if (chunks[i] == "MPU6050"):
x_rotate = chunks[i+1] print("Found MPU6050")
y_rotate = chunks[i+2] x_rotate = chunks[i+1]
z_rotate = chunks[i+3] y_rotate = chunks[i+2]
x_accel = chunks[i+4] z_rotate = chunks[i+3]
y_accel = chunks[i+5] x_accel = chunks[i+4]
z_accel = chunks[i+6] y_accel = chunks[i+5]
if (chunks[i] == "SGP30"): z_accel = chunks[i+6]
print("Found SGP30") if (chunks[i] == "SGP30"):
tvoc = chunks[i+1] print("Found SGP30")
e_co2 = chunks[i+2] tvoc = chunks[i+1]
raw_h2 = chunks[i+3] e_co2 = chunks[i+2]
raw_ethanol= chunks[i+4] raw_h2 = chunks[i+3]
raw_ethanol= chunks[i+4]
#print(telem_string)
#print(telem_string)
my_device = tago.Device('a824cdc6-dc87-4c54-a848-41dabb8873ad')
my_device = tago.Device('a824cdc6-dc87-4c54-a848-41dabb8873ad')
"""
The following code defines the set of data to be sent to TagoIO """
data fields: The following code defines the set of data to be sent to TagoIO
- variable name data fields:
- variable unit - variable name
- variable value - variable unit
- Optional: desired data timestamp - variable value
- Optional: lat/long location (associated to your data) - Optional: desired data timestamp
""" - Optional: lat/long location (associated to your data)
data = { """
'variable': 'temperature', data = {
'unit' : 'C', 'variable': 'temperature',
'value' : temp, 'unit' : 'C',
'time' : timestamp, 'value' : temp,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
}
result = my_device.insert(data)
print(result) result = my_device.insert(data)
print(result)
#print(data)
#print(data)
data = {
'variable': 'pressure', data = {
'unit' : 'hPa', 'variable': 'pressure',
'value' : pressure, 'unit' : 'hPa',
'time' : timestamp, 'value' : pressure,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
}
result = my_device.insert(data)
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'altitude', data = {
'unit' : 'm', 'variable': 'altitude',
'value' : altitude, 'unit' : 'm',
'time' : timestamp, 'value' : altitude,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
}
result = my_device.insert(data)
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'humidity', data = {
'unit' : '%', 'variable': 'humidity',
'value' : humidity, 'unit' : '%',
'time' : timestamp, 'value' : humidity,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'x_rotate', data = {
'unit' : 'dps', 'variable': 'x_rotate',
'value' : x_rotate, 'unit' : 'dps',
'time' : timestamp, 'value' : x_rotate,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'y_rotate', data = {
'unit' : 'dps', 'variable': 'y_rotate',
'value' : y_rotate, 'unit' : 'dps',
'time' : timestamp, 'value' : y_rotate,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
result = my_device.insert(data)
print(result)
print(result)
data = {
'variable': 'z_rotate', data = {
'unit' : 'dps', 'variable': 'z_rotate',
'value' : z_rotate, 'unit' : 'dps',
'time' : timestamp, 'value' : z_rotate,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'x_accel', data = {
'unit' : 'g', 'variable': 'x_accel',
'value' : x_accel, 'unit' : 'g',
'time' : timestamp, 'value' : x_accel,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'y_accel', data = {
'unit' : 'g', 'variable': 'y_accel',
'value' : y_accel, 'unit' : 'g',
'time' : timestamp, 'value' : y_accel,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'z_accel', data = {
'unit' : 'g', 'variable': 'z_accel',
'value' : z_accel, 'unit' : 'g',
'time' : timestamp, 'value' : z_accel,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'tvoc', data = {
'unit' : 'ppb', 'variable': 'tvoc',
'value' : tvoc, 'unit' : 'ppb',
'time' : timestamp, 'value' : tvoc,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'e_co2', data = {
'unit' : 'ppm', 'variable': 'e_co2',
'value' : e_co2, 'unit' : 'ppm',
'time' : timestamp, 'value' : e_co2,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'raw_h2', data = {
'unit' : 'raw', 'variable': 'raw_h2',
'value' : raw_h2, 'unit' : 'raw',
'time' : timestamp, 'value' : raw_h2,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
data = {
'variable': 'raw_ethanol', data = {
'unit' : 'raw', 'variable': 'raw_ethanol',
'value' : raw_ethanol, 'unit' : 'raw',
'time' : timestamp, 'value' : raw_ethanol,
'location': {'lat': lat, 'lng': lon} 'time' : timestamp,
} 'location': {'lat': lat, 'lng': lon}
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
data = {
"variable": "location", data = {
"value": "Villanova University HAB-2", "variable": "location",
"location": { "value": "Villanova University HAB-2",
"lat": lat, "location": {
"lng": lon "lat": lat,
} "lng": lon
} }
result = my_device.insert(data) }
print(result) result = my_device.insert(data)
print(result)
time.sleep(60)
time.sleep(60)
except:
print("There was a problem!)
time.sleep(60)

Loading…
Cancel
Save

Powered by TurnKey Linux.