Add different interval of time for sending data to Rpi and backup on flash memory

This commit is contained in:
Pierrick C 2018-08-15 18:59:03 +02:00
parent d0c130e5e6
commit fe009f6116

View File

@ -53,6 +53,8 @@ backup_data = True # Write data as CSV files on onboard SPI Flash ?
data_to_neopixel = True # Display atmospheric data as color on onboard neopixel ?
gps_enable = True # Use GPS module ?
update_interval = const(10) # Interval between data acquisition (in seconds)
write_interval = const(60) # Interval between data written on flash Memory
send_interval = const(60) # Interval between packet of data sent to Rpi
datetime_format = "{:04}/{:02}/{:02}_{:02}:{:02}:{:02}" # Date/time format
neopixel_max_value =const(70) #max value instead of brightness to spare some mem
@ -329,7 +331,7 @@ check_data_dir()
data = Data()
#Init timer
last_update = time.monotonic()
last_update = last_sent_packet = last_written_data = time.monotonic()
while True:
if gps_enable:
@ -342,14 +344,19 @@ while True:
data.update()
if print_data:
data.show()
if send_json_data:
rpi_uart.write(data.json + '\n')
print(data.json + '\n')
if backup_data:
data.write_on_flash()
if data_to_neopixel:
pixel[0] = data.rgb
if send_json_data and current - last_sent_packet >= send_interval :
last_sent_packet = current
rpi_uart.write(data.json + '\n')
print(data.json + '\n')
if backup_data and current - last_written_data >= write_interval :
last_written_data = current
print("Backup data...")
data.write_on_flash()
gc.collect()
# micropython.mem_info(1)
# print('Memory free: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc()))