diff --git a/examples/adafruit_io_simpletest_randomizer.py b/examples/adafruit_io_simpletest_randomizer.py index 6da5741..0ef3201 100644 --- a/examples/adafruit_io_simpletest_randomizer.py +++ b/examples/adafruit_io_simpletest_randomizer.py @@ -55,9 +55,14 @@ random_data_id = 1234 while True: - print('Fetching random data from Adafruit IO...') - random_data = io.receive_random_data(random_data_id) - print('Random Data: ', random_data['value']) - print('Data Seed: ', random_data['seed']) - print('Waiting 1 minute to fetch new randomized data...') + try: + print('Fetching random data from Adafruit IO...') + random_data = io.receive_random_data(random_data_id) + print('Random Data: ', random_data['value']) + print('Data Seed: ', random_data['seed']) + print('Waiting 1 minute to fetch new randomized data...') + except (ValueError, RuntimeError) as e: + print("Failed to get data, retrying\n", e) + wifi.reset() + continue time.sleep(60) diff --git a/examples/adafruit_io_simpletest_temperature.py b/examples/adafruit_io_simpletest_temperature.py index 91d4dc8..efe6ad7 100644 --- a/examples/adafruit_io_simpletest_temperature.py +++ b/examples/adafruit_io_simpletest_temperature.py @@ -68,12 +68,17 @@ adt.high_resolution = True while True: - temperature = adt.temperature - # set temperature value to two precision points - temperature = '%0.2f'%(temperature) + try: + temperature = adt.temperature + # set temperature value to two precision points + temperature = '%0.2f'%(temperature) - print('Current Temperature: {0}*C'.format(temperature)) - print('Sending to Adafruit IO...') - io.send_data(temperature_feed['key'], temperature) - print('Data sent!') + print('Current Temperature: {0}*C'.format(temperature)) + print('Sending to Adafruit IO...') + io.send_data(temperature_feed['key'], temperature) + print('Data sent!') + except (ValueError, RuntimeError) as e: + print("Failed to get data, retrying\n", e) + wifi.reset() + continue time.sleep(0.5)