Full declaration of Data.data dict to "reserve" the RAM

This commit is contained in:
Pierrick C 2018-08-03 12:09:55 +02:00
parent bb88522d51
commit 280823577c

View File

@ -22,12 +22,13 @@ Use with:
* Adafruit Ultimate GPS FeatherWing * Adafruit Ultimate GPS FeatherWing
* Bosch BME280 sensor (air temperature, humidity, atmospheric pressure) on I2C * Bosch BME280 sensor (air temperature, humidity, atmospheric pressure) on I2C
https://framagit.org/arofarn/Cameteo
TODO for v1 : TODO for v1 :
* write data on flash drive (work-in-progress) * write data on flash drive (work-in-progress)
* send data through UART (one more !) * send data through UART (one more !)
""" """
__version__ = 0.1 __version__ = 0.1
__repo__ = "https://framagit.org/arofarn/Cameteo"
########## ##########
# config # # config #
@ -61,42 +62,47 @@ import neopixel
class Data: class Data:
"""Class for handling data""" """Class for handling data"""
def __init__(self): def __init__(self):
self.data = {'SYS': {}, self.data = {'SYS': {'time': {'val': "2000/01/01_00:00:00", 'unit': '' },
'BME280': {}, 'vbat': {'val': int(), 'unit': 'V' },
'GPS': {} '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): def update(self):
"""Read the data from various sensors and update the data dict variable""" """Read the data from various sensors and update the data dict variable"""
#Data from Feather board #Data from Feather board
self.data['SYS'] = {'time': {'val': datetime_format.format(*clock.datetime[0:6]), self.data['SYS']['time']['val'] = datetime_format.format(*clock.datetime[0:6])
'unit': '' }, self.data['SYS']['vbat']['val'] = round(measure_vbat(), 3)
'v_bat': {'val': measure_vbat(), self.data['SYS']['CPUtemp']['val'] = round(microcontroller.cpu.temperature, 2)
'unit': 'V' },
'CPU_temp': {'val': microcontroller.cpu.temperature,
'unit': '°C' }}
#Data from BME280 #Data from BME280
self.data['BME280'] = {'temp': { 'val': round(bme280.temperature, 1), 'unit': '°C' }, self.data['BME280']['temp']['val'] = round(bme280.temperature, 1)
'hum': { 'val': int(bme280.humidity), 'unit': '%' }, self.data['BME280']['hum']['val'] = int(bme280.humidity)
'press': { 'val': round(bme280.pressure, 2), 'unit': 'hPa' }} self.data['BME280']['press']['val'] = round(bme280.pressure, 2)
if gps_enable: if gps_enable:
if gps.has_fix: if gps.has_fix:
self.data['GPS'] = {'timestamp': {'val': datetime_format.format(gps.timestamp_utc.tm_year, self.data['GPS']['timestamp']['val'] = datetime_format.format(gps.timestamp_utc.tm_year,
gps.timestamp_utc.tm_mon, gps.timestamp_utc.tm_mon,
gps.timestamp_utc.tm_mday, gps.timestamp_utc.tm_mday,
gps.timestamp_utc.tm_hour, gps.timestamp_utc.tm_hour,
gps.timestamp_utc.tm_min, gps.timestamp_utc.tm_min,
gps.timestamp_utc.tm_sec), gps.timestamp_utc.tm_sec)
'unit': ''}, self.data['GPS']['lat']['val'] = gps.latitude
'lat': {'val': gps.latitude, 'unit': 'deg'}, self.data['GPS']['lon']['val'] = gps.longitude
'lon': {'val': gps.longitude, 'unit': 'deg'}, self.data['GPS']['alt']['val'] = gps.altitude_m
'alt': {'val': gps.altitude_m, 'unit': 'm'}, self.data['GPS']['qual']['val'] = gps.fix_quality
'qual': {'val': gps.fix_quality, 'unit': ''}}
else: else:
self.data['GPS'] = {'lat': {'val': None, 'unit': 'deg'}, self.data['GPS']['lat']['val'] = None
'lon': {'val': None, 'unit': 'deg'}, self.data['GPS']['lon']['val'] = None
'alt': {'val': None, 'unit': 'm'}} self.data['GPS']['alt']['val'] = None
else: else:
self.data['GPS'] = None self.data['GPS'] = None
@ -274,6 +280,7 @@ while True:
data.write_on_flash() data.write_on_flash()
if data_to_neopixel: if data_to_neopixel:
pixel[0] = update_neopixel(data.data) pixel[0] = update_neopixel(data.data)
gc.collect() gc.collect()
# micropython.mem_info(1) # micropython.mem_info(1)
# print('Memory free: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc())) # print('Memory free: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc()))