Ejemplo n.º 1
0
print("GPS firmware:", fw)
assert len(fw) > 3

vis, tracked = gps.get_satellites()
print("GPS sats:", vis, tracked)
assert vis == int(vis)
assert tracked == int(tracked)
assert 0 <= tracked <= vis

lat, lng = gps.get_location()
print("GPS location:", lat, lng)
assert -90 <= lat <= 90
assert -180 <= lng <= 180

gps.off()
_lat, _lng = gps.get_last_location()
print("GPS last location:", lat, lng)
assert lat == _lat
assert lng == _lng

try:
    gps.on(0)
    raise ValueError("No GPS exception was raised")
except gps.GPSError as e:
    print("GPS error OK:", e)
gps.off()
del gps

print("================")
print("Network")
print("================")
Ejemplo n.º 2
0
# Get online
import cellular
cellular.gprs("internet", "", "")

# Import mqtt (download client if necessary)
try:
    from umqtt import simple
except ImportError:
    import upip
    upip.install("micropython-umqtt.simple")
    from umqtt import simple

# Turn GPS on
import gps
gps.on()

# Report location
name = "a9g-micropython-board"
server = "test.mosquitto.org"
topic = "a9g-micropython-board-topic"
print(
    "To track messages run, for example\n  mosquitto_sub -h {server} -t \"{topic}\" -v"
    .format(server=server, topic=topic))
import json
client = simple.MQTTClient(name, server)
client.connect()
data = json.dumps(gps.get_last_location())
print("Publishing", data)
client.publish(topic, data)