def features(on=None): if on is None: print("heartbeat ", pycom.heartbeat_on_boot()) print("lte ", pycom.lte_modem_en_on_boot()) try: print("pybytes ", pycom.pybytes_on_boot()) except: pass try: print("smart_config", pycom.smart_config_on_boot()) except: pass print("wdt ", pycom.wdt_on_boot()) print("wifi ", pycom.wifi_on_boot()) else: print("configure all features as", on) pycom.heartbeat_on_boot(on) pycom.lte_modem_en_on_boot(on) try: pycom.pybytes_on_boot(on) except: pass try: pycom.smart_config_on_boot(on) except: pass pycom.wdt_on_boot(on) pycom.wifi_on_boot(on) features(None)
def power_off_lte_modem(self): """ We don't use LTE yet. https://community.hiveeyes.org/t/lte-modem-des-pycom-fipy-komplett-stilllegen/2161 https://forum.pycom.io/topic/4877/deepsleep-on-batteries/10 """ import pycom """ if not pycom.lte_modem_en_on_boot(): log.info('Skip turning off LTE modem') return """ log.info('Turning off LTE modem') try: from network import LTE # Invoking this will cause `LTE.deinit()` to take around 6(!) seconds. #log.info('Enabling LTE modem on boot') #pycom.lte_modem_en_on_boot(True) log.info('Turning off LTE modem on boot') pycom.lte_modem_en_on_boot(False) log.info('Invoking LTE.deinit()') lte = LTE() lte.deinit() except: log.exception('Shutting down LTE modem failed')
def set_persistent_settings(): _logger.info("Setting persistent settings...") pycom.wifi_on_boot(False) pycom.lte_modem_en_on_boot(False) pycom.heartbeat_on_boot(False) pycom.wdt_on_boot(True) pycom.wdt_on_boot_timeout(1000 * 30)
def info(verbose=False, debug=False, retry=5): print_welcome() import pycom count = 0 sqnup = sqnsupgrade() while count < retry: count += 1 if verbose: print('Trying to detect modem state [{}/{}]'.format(count, retry)) state = sqnup.detect_modem_state(debug=debug) if debug: print('State: {} at count: {}'.format(state, count)) if state is not None: break if state is not None: if state == 2: print('Your modem is in application mode. Here is the current version:') sqnup.show_version(verbose=verbose, debug=debug) elif state == 1: print('Your modem is in mTools mode.') elif state == 0: print('Your modem is in recovery mode! Use firmware.dup and updater.elf to flash new firmware.') elif state == 4: print('Your modem is in upgrade mode! Use firmware.dup to flash new firmware.') elif state == -1: print('Cannot determine modem state!') if hasattr(pycom, 'lte_modem_en_on_boot') and verbose: print('LTE autostart {}.'.format('enabled' if pycom.lte_modem_en_on_boot() else 'disabled')) else: print('Cannot determine modem state!') reconnect_uart()
def info(verbose=False, debug=False, hangup=True): print_welcome() import pycom state = None sqnup = sqnsupgrade() if verbose: print('Trying to detect modem state...') state = sqnup.detect_modem_state(debug=debug, hangup=hangup) if debug: print('Modem state: {}'.format(state)) if state is not None: if state == 2: print('Your modem is in application mode. Here is the current version:') sqnup.show_info(verbose=verbose, debug=debug) elif state == 1: print('Your modem is in mTools mode.') elif state == 0: print('Your modem is in recovery mode! Use firmware.dup and updater.elf to flash new firmware.') elif state == 4: print('Your modem is in upgrade mode! Use firmware.dup to flash new firmware.') elif state == -1: print('Cannot determine modem state!') if hasattr(pycom, 'lte_modem_en_on_boot') and verbose: print('LTE autostart {}.'.format('enabled' if pycom.lte_modem_en_on_boot() else 'disabled')) else: print('Cannot determine modem state!') reconnect_uart()
def power_off_lte_modem(self): """ We don't use LTE yet. Important ========= Once the LTE radio is initialized, it must be de-initialized before going to deepsleep in order to ensure minimum power consumption. This is required due to the LTE radio being powered independently and allowing use cases which require the system to be taken out from deepsleep by an event from the LTE network (data or SMS received for instance). Note ==== When using the expansion board and the FiPy together, the RTS/CTS jumpers MUST be removed as those pins are being used by the LTE radio. Keeping those jumpers in place will lead to erratic operation and higher current consumption specially while in deepsleep. -- https://forum.pycom.io/topic/3090/fipy-current-consumption-analysis/17 See also ======== - https://community.hiveeyes.org/t/lte-modem-des-pycom-fipy-komplett-stilllegen/2161 - https://forum.pycom.io/topic/4877/deepsleep-on-batteries/10 """ log.info('Turning off LTE modem') try: import pycom from network import LTE log.info('Turning off LTE modem on boot') pycom.lte_modem_en_on_boot(False) # Disables LTE modem completely. This presumably reduces the power # consumption to the minimum. Call this before entering deepsleep. log.info('Invoking LTE.deinit()') lte = LTE() lte.deinit(detach=False, reset=True) except Exception as ex: log.exc(ex, 'Shutting down LTE modem failed')
def show_boot_flags(): _logger.info("pycom.wifi_on_boot(): %s", pycom.wifi_on_boot()) with CheckStep(FLAG_LTE_FW_API, suppress_exception=True): # These methods are not available on old firmware versions # If they are missing, we need to upgrade the Pycom firmware _logger.info("pycom.lte_modem_en_on_boot(): %s", pycom.lte_modem_en_on_boot()) _logger.info("pycom.heartbeat_on_boot(): %s", pycom.heartbeat_on_boot()) _logger.info("pycom.wdt_on_boot(): %s", pycom.wdt_on_boot()) _logger.info("pycom.wdt_on_boot_timeout(): %s", pycom.wdt_on_boot_timeout())
# boot.py -- run on boot-up from network import LoRa import pycom import ubinascii import socket import time import lora_keys as keys # Disable LTE radio if pycom.lte_modem_en_on_boot(): print("LTE is enabled. Disabling...") pycom.lte_modem_en_on_boot(False) # Join LoRa network lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868) lora.set_battery_level( 255) # We are on battery but have no way to measure this. # Try to read state from nvram otherwise join a network using OTAA lora.nvram_restore() if not lora.has_joined(): lora.join(activation=LoRa.OTAA, auth=(ubinascii.unhexlify(keys.dev_eui), ubinascii.unhexlify(keys.app_eui), ubinascii.unhexlify(keys.app_key)), timeout=0) # wait until network joined while not lora.has_joined(): time.sleep(2.5) print("Waiting to join...")
if __name__ == '__main__': import binascii import machine uid = binascii.hexlify(machine.unique_id()).decode("utf-8") name = os.uname().sysname.lower() + '-' + uid[-4:] print(name, uid) features() if False: features(True) # turn everything on features(False) # turn everything off # print import pycom print('heartbeat', pycom.heartbeat_on_boot()) print('lte', pycom.lte_modem_en_on_boot()) print('pybytes', pycom.pybytes_on_boot()) print('smart_config', pycom.smart_config_on_boot()) print('wdt', pycom.wdt_on_boot()) print('wifi', pycom.wifi_on_boot()) # off pycom.heartbeat_on_boot(False) import pycom pycom.lte_modem_en_on_boot(False) pycom.wdt_on_boot(False) pycom.wifi_on_boot(False) pycom.smart_config_on_boot(False) pycom.pybytes_on_boot(False) # on pycom.heartbeat_on_boot(True) pycom.lte_modem_en_on_boot(True)