#!/usr/bin/env python3 import argparse from m2m.nbiot import factory from m2m.utils import encode_psm_timer def run_low_power_location(port): module = factory('BG95', port) with module: # 1. Configure Power Saving Mode # Example: 1 minute Active Time (T3324) and 24 hours Periodic TAU (T3412) t3324_bin = encode_psm_timer(60, is_t3324=True) t3412_bin = encode_psm_timer(24 * 3600, is_t3324=False) print(f"Setting PSM: T3324={t3324_bin}, T3412={t3412_bin}") module.set_psm_settings(mode=1, tau=t3412_bin, active_time=t3324_bin) # 2. GNSS Location print("Enabling GNSS...") if module.enable_gnss(True): print("Waiting for fix (may take up to 60s)...") # Poll location until success for i in range(10): import time time.sleep(5) loc = module.get_gnss_location() if loc: print(f"Location Found: {loc}") break else: print(f"Attempt {i+1}: No fix yet...") module.enable_gnss(False) # Save power if __name__ == "__main__": parser = argparse.ArgumentParser(description="Run PSM and GNSS demo.") parser.add_argument("port", nargs="?", default="/dev/ttyUSB0", help="Serial port (e.g. /dev/ttyUSB0 or MOCK)") args = parser.parse_args() run_low_power_location(args.port)