From fe009f6116d196d17791a099537ce50b35aaec3e Mon Sep 17 00:00:00 2001 From: Pierrick C Date: Wed, 15 Aug 2018 18:59:03 +0200 Subject: [PATCH] Add different interval of time for sending data to Rpi and backup on flash memory --- circuitpython/code/main.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/circuitpython/code/main.py b/circuitpython/code/main.py index 9beb7a3..18d0822 100644 --- a/circuitpython/code/main.py +++ b/circuitpython/code/main.py @@ -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()))