def mem(verbose=False): if verbose: print("{:18} {:9}".format("GC total ", gc.mem_alloc() + gc.mem_free())) micropython.mem_info() print("{:18} {:9}".format("mp stack use", micropython.stack_use())) print("{:18} {:9}".format("GC free", gc.mem_free())) print("{:18} {:9}".format("heap internal free", pycom.get_free_heap()[0])) print("{:18} {:9}".format("heap external free", pycom.get_free_heap()[1]))
def mem(): global mpy_heap_free, mpy_stack_used, internal_heap_free, external_heap_free # machine.info() #print("MPy heap free=", gc.mem_free(), "alloc=", gc.mem_alloc(), "total=", gc.mem_alloc() + gc.mem_free(), "diff=", mpy_heap_free - gc.mem_free()) # micropython.mem_info() print("MPy heap free= {:>8} diff={:>6}".format( gc.mem_free(), gc.mem_free() - mpy_heap_free)) print("MPy stack used= {:>8} diff={:>6}".format( micropython.stack_use(), micropython.stack_use() - mpy_stack_used)) print("internal heap free={:>8} diff={:>6}".format( pycom.get_free_heap()[0], pycom.get_free_heap()[0] - internal_heap_free)) print("external heap free={:>8} diff={:>6}".format( pycom.get_free_heap()[1], pycom.get_free_heap()[1] - external_heap_free)) mpy_heap_free = gc.mem_free() mpy_stack_used = micropython.stack_use() internal_heap_free = pycom.get_free_heap()[0] external_heap_free = pycom.get_free_heap()[1]
def print_bootscreen(self): """Print bootscreen. This contains important details about your device and the operating system running on it. """ if not self.settings.get('main.logging.enabled', False): return # Todo: Maybe refactor to TerkinDatalogger. from uio import StringIO buffer = StringIO() def add(item=''): """ :param item: (Default value = '') """ buffer.write(item) buffer.write('\n') # Program name and version. title = '{} {}'.format(self.name, self.version) add() add('=' * len(title)) add(title) add('=' * len(title)) # Machine runtime information. frequency = machine.freq() / 1000000 add('Device id {}'.format(self.device_id)) add() add('CPU freq {} MHz'.format(frequency)) try: import pycom free_heap = pycom.get_free_heap() add('{:13}{:>7} {}'.format('Free heap', free_heap[0] / 1000.0, 'kB')) add('{:13}{:>7} {}'.format('Free PSRAM', free_heap[1] / 1000.0, 'kB')) except: pass add() # System memory info (in bytes). """ if hasattr(machine, 'info'): machine.info() add() """ # TODO: Python runtime information. add('{:8}: {}'.format('Python', sys.version.replace('\n', ''))) add('{:8}: {}'.format('platform', sys.platform)) """ >>> import os; os.uname() (sysname='FiPy', nodename='FiPy', release='1.20.0.rc7', version='v1.9.4-2833cf5 on 2019-02-08', machine='FiPy with ESP32', lorawan='1.0.2', sigfox='1.0.1') """ runtime_info = os.uname() #print(dir(runtime_info)) for key in dir(runtime_info): if key.startswith('__') or key.startswith('n_'): continue value = getattr(runtime_info, key) if callable(value): continue #print('value:', value) add('{:8}: {}'.format(key, value)) add() # Todo: Add program authors, contributors and credits. log.info('\n' + buffer.getvalue())
print("done Pymesh init, forever loop, exit/stop with Ctrl+C multiple times") # set BR with callback if pybytes is not None and pybytes.isconnected(): pybytes.send_signal(1, "RESTART") pyb_port = pymesh.mac() & 0xFFFF pyb_ip = '1:2:3::' + hex(pyb_port)[2:] pkt_start = "Hello, from " + str(pymesh.mac()) + ", time " br_enabled = False while True: # add current node as Border Router, with a priority and a message handler callback free_mem = pycom.get_free_heap() if pymesh.mac() in MAC_BR: if pybytes is not None and pybytes.isconnected(): if not br_enabled: br_enabled = True print("Set as BR") pymesh.br_set(PymeshConfig.BR_PRIORITY_NORM, new_br_message_cb) pybytes.send_signal(1, str(pymesh.mac()) +" : " + str(time.time()) + "s, "+ str(free_mem)) print("Send to Pyb,", free_mem) else: # not connected anymore to pybytes if br_enabled: br_enabled = False print("Remove as BR") pymesh.br_remove()
elif mwr[0] == machine.RTC_WAKE: print("RTC_WAKE") # from deepsleep elif mwr[0] == machine.ULP_WAKE: print("ULP_WAKE") print("===== os =========================================") print("sysname", os.uname().sysname) # e.g., GPy print("release", os.uname().release) # e.g., 1.20.1.r1 print("release", os.uname().version) print("uname", os.uname()) import pycom print("===== pycom ======================================") try: print("free_heap", pycom.get_free_heap()) # print("bootmgr", pycom.bootmgr()) print("partition", pycom.bootmgr()[0]) print("fs_type", pycom.bootmgr()[1]) print("free", os.getfree('/flash')) print(pycom.bootmgr()[2]) # safeboot print(pycom.bootmgr()[3]) # status print("ota_slot", hex(pycom.ota_slot())) if (pycom.ota_slot() == 0x210000): print("ota_slot is", "'ota_0' in 'new' 8MB layout") elif (pycom.ota_slot() == 0x1A0000): print("ota_slot is", "'ota_0' in 'old' 4MB layout") elif (pycom.ota_slot() == 0x10000): print("ota_slot is", "'Factory'") else: raise Exception("Unkown ota_slot"+ str(pycom.ota_slot()))
pymesh.send_mess(5, "Hello World") # def new_br_message_cb(rcv_ip, rcv_port, rcv_data, dest_ip, dest_port): # ''' callback triggered when a new packet arrived for the current Border Router, # having destination an IP which is external from Mesh ''' # print('Incoming %d bytes from %s (port %d), to external IPv6 %s (port %d)' % # (len(rcv_data), rcv_ip, rcv_port, dest_ip, dest_port)) # print(rcv_data) # # user code to be inserted, to send packet to the designated Mesh-external interface # # ... # return # add current node as Border Router, with a priority and a message handler callback # pymesh.br_set(PymeshConfig.BR_PRIORITY_NORM, new_br_message_cb) # remove Border Router function from current node #pymesh.br_remove() # send data for Mesh-external, basically to the BR # ip = "1:2:3::4" # port = 5555 # pymesh.send_mess_external(ip, port, "Hello World") print("done Pymesh init, forever loop, exit/stop with Ctrl+C multiple times") # set BR with callback while True: print("Heap:", pycom.get_free_heap()) time.sleep(3)
import _thread import time import machine import gc import micropython import pycom keep_going = True mpy_heap_free = gc.mem_free() mpy_stack_used = micropython.stack_use() internal_heap_free = pycom.get_free_heap()[0] external_heap_free = pycom.get_free_heap()[1] def mem(): global mpy_heap_free, mpy_stack_used, internal_heap_free, external_heap_free # machine.info() #print("MPy heap free=", gc.mem_free(), "alloc=", gc.mem_alloc(), "total=", gc.mem_alloc() + gc.mem_free(), "diff=", mpy_heap_free - gc.mem_free()) # micropython.mem_info() print("MPy heap free= {:>8} diff={:>6}".format( gc.mem_free(), gc.mem_free() - mpy_heap_free)) print("MPy stack used= {:>8} diff={:>6}".format( micropython.stack_use(), micropython.stack_use() - mpy_stack_used)) print("internal heap free={:>8} diff={:>6}".format( pycom.get_free_heap()[0], pycom.get_free_heap()[0] - internal_heap_free))