From 280823577cca8d6449ce985bac08d2de32283f20 Mon Sep 17 00:00:00 2001 From: Pierrick C Date: Fri, 3 Aug 2018 12:09:55 +0200 Subject: [PATCH] Full declaration of Data.data dict to "reserve" the RAM --- circuitpython/code/main.py | 55 +++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/circuitpython/code/main.py b/circuitpython/code/main.py index 3e96a2f..ebfd593 100644 --- a/circuitpython/code/main.py +++ b/circuitpython/code/main.py @@ -22,12 +22,13 @@ Use with: * Adafruit Ultimate GPS FeatherWing * Bosch BME280 sensor (air temperature, humidity, atmospheric pressure) on I2C +https://framagit.org/arofarn/Cameteo + TODO for v1 : * write data on flash drive (work-in-progress) * send data through UART (one more !) """ __version__ = 0.1 -__repo__ = "https://framagit.org/arofarn/Cameteo" ########## # config # @@ -61,42 +62,47 @@ import neopixel class Data: """Class for handling data""" def __init__(self): - self.data = {'SYS': {}, - 'BME280': {}, - 'GPS': {} + self.data = {'SYS': {'time': {'val': "2000/01/01_00:00:00", 'unit': '' }, + 'vbat': {'val': int(), 'unit': 'V' }, + 'CPUtemp': {'val': float(), 'unit': '°C' }}, + 'BME280': {'temp': { 'val': float(), 'unit': '°C' }, + 'hum': { 'val': int(), 'unit': '%' }, + 'press': { 'val': float(), 'unit': 'hPa' }}, + 'GPS': {'timestamp': {'val': "2000/01/01_00:00:00", 'unit': ''}, + 'lat': {'val': float(), 'unit': 'deg'}, + 'lon': {'val': float(), 'unit': 'deg'}, + 'alt': {'val': float(), 'unit': 'm'}, + 'qual': {'val': int(), 'unit': ''}} } def update(self): """Read the data from various sensors and update the data dict variable""" #Data from Feather board - self.data['SYS'] = {'time': {'val': datetime_format.format(*clock.datetime[0:6]), - 'unit': '' }, - 'v_bat': {'val': measure_vbat(), - 'unit': 'V' }, - 'CPU_temp': {'val': microcontroller.cpu.temperature, - 'unit': '°C' }} + self.data['SYS']['time']['val'] = datetime_format.format(*clock.datetime[0:6]) + self.data['SYS']['vbat']['val'] = round(measure_vbat(), 3) + self.data['SYS']['CPUtemp']['val'] = round(microcontroller.cpu.temperature, 2) #Data from BME280 - self.data['BME280'] = {'temp': { 'val': round(bme280.temperature, 1), 'unit': '°C' }, - 'hum': { 'val': int(bme280.humidity), 'unit': '%' }, - 'press': { 'val': round(bme280.pressure, 2), 'unit': 'hPa' }} + self.data['BME280']['temp']['val'] = round(bme280.temperature, 1) + self.data['BME280']['hum']['val'] = int(bme280.humidity) + self.data['BME280']['press']['val'] = round(bme280.pressure, 2) + if gps_enable: if gps.has_fix: - self.data['GPS'] = {'timestamp': {'val': datetime_format.format(gps.timestamp_utc.tm_year, - gps.timestamp_utc.tm_mon, + self.data['GPS']['timestamp']['val'] = datetime_format.format(gps.timestamp_utc.tm_year, + gps.timestamp_utc.tm_mon, gps.timestamp_utc.tm_mday, gps.timestamp_utc.tm_hour, gps.timestamp_utc.tm_min, - gps.timestamp_utc.tm_sec), - 'unit': ''}, - 'lat': {'val': gps.latitude, 'unit': 'deg'}, - 'lon': {'val': gps.longitude, 'unit': 'deg'}, - 'alt': {'val': gps.altitude_m, 'unit': 'm'}, - 'qual': {'val': gps.fix_quality, 'unit': ''}} + gps.timestamp_utc.tm_sec) + self.data['GPS']['lat']['val'] = gps.latitude + self.data['GPS']['lon']['val'] = gps.longitude + self.data['GPS']['alt']['val'] = gps.altitude_m + self.data['GPS']['qual']['val'] = gps.fix_quality else: - self.data['GPS'] = {'lat': {'val': None, 'unit': 'deg'}, - 'lon': {'val': None, 'unit': 'deg'}, - 'alt': {'val': None, 'unit': 'm'}} + self.data['GPS']['lat']['val'] = None + self.data['GPS']['lon']['val'] = None + self.data['GPS']['alt']['val'] = None else: self.data['GPS'] = None @@ -274,6 +280,7 @@ while True: data.write_on_flash() if data_to_neopixel: pixel[0] = update_neopixel(data.data) + gc.collect() # micropython.mem_info(1) # print('Memory free: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc()))