def set_gps_state(state): global gps_state prev_state = gps_state if state and (not gps_state): gps.on(0, 1 | 2) else: if not state and gps_state: print("Switchng off gps!") gps.off() gps_state = state return prev_state
async def upload_gps(): global c while True: gps.on() location = None while location is None: location = get_gps() await uasyncio.sleep(10) gps.off() # G0纬度,G1经度 location_str0 = 'G0\t' + str(location[0]) location_str1 = 'G1\t' + str(location[1]) c.publish(b'gps_node',location_str0) c.publish(b'gps_node',location_str1) await uasyncio.sleep(3600)
# Micropython a9g example # Source: https://github.com/pulkin/micropython # Author: pulkin # Demonstrates how to retrieve GPS coordinates from the built-in GPS module import gps gps.on() print("Location", gps.get_location()) print("Satellites (tracked, visible)", gps.get_satellites()) gps.off()
print("Files:", ls) assert len(ls) == 0 os.rmdir("/" + test_dir1 + "/" + test_dir2) ls = os.listdir("/" + test_dir1) print("Files:", ls) assert len(ls) == 0 os.rmdir("/" + test_dir1) print("================") print("GPS") print("================") import gps gps.on() fw = gps.get_firmware_version() 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