Pelion Device Management example over 15.4 Thread for Thunderboard Sense 2 board

Dependencies:   ICM20648 BMP280 Si1133 Si7210 AMS_CCS811_gas_sensor SI7021

DEPRECATED

This example application is not maintained and not recommended. It uses an old version of Mbed OS, Pelion DM, and Arm toolchain. It doesn't work with Mbed Studio.

Please use: https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-pelion/

This example is known to work great on the following platforms:

Follow the Quick-Start instructions: https://cloud.mbed.com/quick-start

Thunderboard Sense 2

Example functionality

This example showcases the following device functionality:

  • Read onboard sensors, and report them as Pelion LWM2M resources:
    • Barometric Pressure and Temperature (BMP280)
    • Relative Humidity and Temperature (Si7021)
    • Air quality - CO2 and tVOC (CCS811)
    • Light intensity and UV level (Si1133)
    • Hall effect and Temperature (Si7210)
    • Accelerometer and Gyroscope (ICM20648)
  • It also exposes the RGB LEDs for triggering flashes in a specific color
  • On user button click, increment Pelion LWM2M button resource.

/media/uploads/screamer/pelion_st_humidity_reading.png?v=2

15.4 Thread setup

This example program requires that a Thread Border Router is available. A Border Router is a network gateway between a wireless 6LoWPAN mesh network and a backhaul network. It controls and relays traffic between the two networks. In a typical setup, a 6LoWPAN border router is connected to another router in the backhaul network (over Ethernet or a serial line) which in turn forwards traffic to/from the internet or a private company LAN, for instance.

https://raw.githubusercontent.com/ARMmbed/nanostack-border-router/f8bf21aac12c9926afba252187e2adf2525bf1eb/images/br_role.png

Instructions how to set up a Thread Border Router

Use this example with Mbed CLI

1. Import the application into your desktop:

mbed import https://os.mbed.com/teams/SiliconLabs/code/pelion-example-tbsense2

cd pelion-example-tbsense2

2. Install the CLOUD_SDK_API_KEY

mbed config -G CLOUD_SDK_API_KEY <PELION_DM_API_KEY>

For instructions on how to generate your API key, please see the documentation.

3. Initialize firmware credentials (done once per repository). You can use the following command:

mbed dm init -d "<your company name in Pelion DM>" --model-name "<product model identifier>" -q --force

If above command do not work for your Mbed CLI, please consider upgrading Mbed CLI to version 1.8.x or above.

4. Compile and program:

mbed compile -t <toolchain> -m TB_SENSE_2

(supported toolchains : GCC_ARM / ARM / IAR)

5. You can connect on a virtual terminal/COM port to the platform using:

mbed sterm -b 115200

This should give you an output similar to:

[BOOT] Mbed Bootloader
[BOOT] ARM: 00000000000000000000
[BOOT] OEM: 00000000000000000000
[BOOT] Layout: 0 90AC
[BOOT] Active firmware integrity check:
[BOOT] SHA256: 615A11A7F03B1F048573E2CB51D8C9A5DD4E6F17A7F8E79C4B64E3241FF78974
[BOOT] Version: 1553594998
[BOOT] Slot 0 is empty
[BOOT] Active firmware up-to-date
[BOOT] Application's start address: 0x10400
[BOOT] Application's jump address: 0x10FBD
[BOOT] Application's stack address: 0x20040000
[BOOT] Forwarding to application...


Starting Simple Pelion Device Management Client example
You can hold the user button during boot to format the storage and change the device identity.
Connecting to the network using 802.15.4...
Connected to the network successfully. IP address: 2001:****:****:****:****:****:****:73bc
Initializing Pelion Device Management Client...
Si7021 Electronic Serial Number:                0         15b5ffff, firmware rev 20
Registered to Pelion Device Management. Endpoint Name: 0169b91a********************01a0
                                                                 
BMP280 temp:     32.750 C,   pressure: 1030.750 [mbar]            
Si7021 temp:     27.529 C,   humidity:   24.842 %                 
Si7210 temp:     34.484 C,   field:      -0.076 [mT]              
Si1133 light:  1258.574 lux, UV level:    0.031                       
CCS811 CO2:           0 ppm, VoC:             0 ppb                   
ICM20648 acc:    -0.093 x,  -0.057 y,     0.969 z [mg]            
ICM20648 gyro:   -1.503 x,   0.122 y,    -0.771 z [mdps]          
    
Revision:
1:cf0bd0446785
Parent:
0:3853978178c0
Child:
2:8d3f3f35f089
--- a/main.cpp	Fri Mar 22 00:58:50 2019 +0000
+++ b/main.cpp	Mon Mar 25 22:47:24 2019 +0000
@@ -7,28 +7,22 @@
 #include "Nanostack.h"
 #include "ns_file_system.h"
 
-#define TRACE_GROUP "APP"
-
-// Thunderboard Sense 2 connects over 802.15.4 by default. Since the mesh
-// stack is a bit iffy, we'll register a 'network down' handler to act as
-// a kind of watchdog for the Pelion DM Client.
+// Thunderboard Sense 2 connects over 802.15.4 by default. Since the mesh stack is a bit iffy.
+// We'll register a 'network down' handler to act as a kind of watchdog for the Pelion DM Client.
 NetworkInterface *net = NetworkInterface::get_default_instance();
 
-// Thunderboard Sense 2 has a 1M external flash, which is being shared
-// between upgrade storage and LittleFS. LittleFS is instantiated at the
-// start of storage, until the start address for upgrade storage.
+// Thunderboard Sense 2 has a 1M external flash, which is being shared between upgrade storage and LittleFS.
+// LittleFS is instantiated at the start of storage, until the start address for upgrade storage.
 // Currently, this split is at 256/768 for FS/upgrade.
 BlockDevice* bd = BlockDevice::get_default_instance();
 SlicingBlockDevice sd(bd, 0, MBED_CONF_UPDATE_CLIENT_STORAGE_ADDRESS);
 LittleFileSystem fs("fs", &sd);
 
-// An event queue is a very useful structure to debounce information between
-// contexts (e.g. ISR and normal threads)
-// This is great because things such as network operations are illegal in ISR,
-// so updating a resource in a button's fall() function is not allowed.
+// An event queue is a very useful structure to debounce information between contexts (e.g. ISR and normal threads)
+// This is great because things such as network operations are illegal in ISR, so updating a resource in a button's fall() function is not allowed.
 EventQueue eventQueue;
 
-DigitalIn rst_btn(BTN0);
+InterruptIn button(BTN0);
 
 //------------------------------------------------------------------------------
 // Includes and declarations for our sensor array
@@ -38,10 +32,8 @@
 #include "AMS_CCS811.h"
 
 // Define measurement intervals in seconds
-#define LIGHT_MEASURING_INTERVAL        (600)
-#define RHT_MEASURING_INTERVAL          (600)
-#define BAROMETER_MEASURING_INTERVAL    (600)
-#define AQ_AVERAGING_SAMPLES            (10)
+#define SENSORS_POLL_INTERVAL 1.0
+#define SEND_ALL_SENSORS
 
 /* Turn on power supply to ENV sensor suite */
 DigitalOut env_en(PF9, 1);
@@ -56,81 +48,22 @@
 I2C ccs_i2c(PB6, PB7);
 AMS_CCS811 aqs(&ccs_i2c, PF15);
 
-// When called, will trigger a light sensor measurement and update the resources
-void measure_lux(MbedCloudClientResource *light_var, MbedCloudClientResource *uv_var) {
-    float light_level, uv_index;
-    bool result = light_sensor.get_light_and_uv(&light_level, &uv_index);
-    if (result) {
-        if (light_var) light_var->set_value(light_level);
-        if (uv_var) uv_var->set_value(uv_index);
-    } else {
-        tr_warn("Could not take measurement from lux sensor");
-    }
-}
-
-// When called, will trigger an RHT measurement and update the resources
-void measure_rht(MbedCloudClientResource *temperature, MbedCloudClientResource *humidity) {
-    SI7021::SI7021_status_t result = rht_sensor.SI7021_TriggerHumidity( SI7021::SI7021_NO_HOLD_MASTER_MODE );
-    if (result == SI7021::SI7021_SUCCESS) {
-        wait_ms(30);
-        SI7021::SI7021_vector_data_t result_data;
-        result = rht_sensor.SI7021_ReadHumidity( &result_data );
-        if (result == SI7021::SI7021_SUCCESS) {
-            if (humidity) humidity->set_value(result_data.RelativeHumidity);
-        } else {
-            tr_warn("Could not get humidity from RHT sensor");
-        }
-        result = rht_sensor.SI7021_ReadTemperatureFromRH( &result_data );
-        if (result == SI7021::SI7021_SUCCESS) {
-            if (temperature) temperature->set_value(result_data.Temperature);
-        } else {
-            tr_warn("Could not get temperature from RHT sensor");
-        }
-
-        aqs.env_data(result_data.RelativeHumidity, result_data.Temperature);
-    } else {
-        tr_warn("Could not take measurement from RHT sensor");
-    }
-}
+// Declaring pointers for access to Pelion Client resources outside of main()
+MbedCloudClientResource *res_button;
+MbedCloudClientResource *res_led;
 
-// When called, will trigger a barometer measurement and update the resources
-void measure_baro(MbedCloudClientResource *pressure) {
-    float result = barometer.getPressure();
-    if (result > 0) {
-        if (pressure) pressure->set_value(result);
-    } else {
-        tr_warn("Could not take measurement from barometric sensor");
-    }
-}
-
-// When called, will read out the CCS811 measurement
-void measure_airquality(MbedCloudClientResource *eco2, MbedCloudClientResource *tvoc) {
-    static uint32_t co2_buf[AQ_AVERAGING_SAMPLES] = {0};
-    static uint32_t voc_buf[AQ_AVERAGING_SAMPLES] = {0};
-    static size_t num_samples = 0;
-    static bool started = false;
+#ifdef SEND_ALL_SENSORS
+MbedCloudClientResource *res_light;
+MbedCloudClientResource *res_barometer;
+MbedCloudClientResource *res_temperature;
+MbedCloudClientResource *res_humidity;
+MbedCloudClientResource *res_co2;
+MbedCloudClientResource *res_tvoc;
+#endif /* SEND_ALL_SENSORS */
 
-    aqs.has_new_data();
-    co2_buf[num_samples] = aqs.co2_read();
-    voc_buf[num_samples] = aqs.tvoc_read();
-
-    if ((num_samples == 0) && started) {
-        int co2 = 0, voc = 0;
-        for (size_t i = 0; i < AQ_AVERAGING_SAMPLES; i++) {
-            co2 += co2_buf[i];
-            voc += voc_buf[i];
-        }
+// When the device is registered, this variable will be used to access various useful information, like device ID etc.
+static const ConnectorClientEndpointInfo* endpointInfo;
 
-        co2 = co2 / AQ_AVERAGING_SAMPLES;
-        voc = voc / AQ_AVERAGING_SAMPLES;
-
-        if (eco2) eco2->set_value(co2);
-        if (tvoc) tvoc->set_value(voc);
-    }
-
-    started = true;
-    num_samples = (num_samples + 1) % AQ_AVERAGING_SAMPLES;
-}
 
 void blink_callback(MbedCloudClientResource *resource, const uint8_t *buffer, uint16_t size) {
     static int num_count = 0;
@@ -148,10 +81,10 @@
     static DigitalOut led_rgb_en(PJ14, 0);
 
     if (buffer != NULL) {
-        tr_info("POST received. POST data: %s\n", buffer);
+        printf("POST received. POST data: %s\n", buffer);
 
         if (event > 0) {
-            tr_info("Not blinking since previous blink still in progress\n");
+            printf("Not blinking since previous blink still in progress\n");
             return;
         }
         num_count = 0;
@@ -164,32 +97,32 @@
             if (buffer[i] >= '0' && buffer[i] <= '9') {
                 switch (num_arg) {
                     case 0:
-                    if (buffer[i] == '1') {
-                        led_ch_red = 1;
-                    } else {
-                        led_ch_red = 0;
-                    }
-                    break;
+                        if (buffer[i] == '1') {
+                            led_ch_red = 1;
+                        } else {
+                            led_ch_red = 0;
+                        }
+                        break;
                     case 1:
-                    if (buffer[i] == '1') {
-                        led_ch_green = 1;
-                    } else {
-                        led_ch_green = 0;
-                    }
-                    break;
+                        if (buffer[i] == '1') {
+                            led_ch_green = 1;
+                        } else {
+                            led_ch_green = 0;
+                        }
+                        break;
                     case 2:
-                    if (buffer[i] == '1') {
-                        led_ch_blue = 1;
-                    } else {
-                        led_ch_blue = 0;
-                    }
-                    break;
+                        if (buffer[i] == '1') {
+                            led_ch_blue = 1;
+                        } else {
+                            led_ch_blue = 0;
+                        }
+                        break;
                     case 3:
-                    num_count = ((buffer[i] - 0x30) * 2) - 1;
-                    tr_info("blinking %d\n", num_count);
-                    break;
+                        num_count = ((buffer[i] - 0x30) * 2) - 1;
+                        printf("blinking %d\n", num_count);
+                        break;
                     default:
-                    break;
+                        break;
                 }
             } else {
                 //garbage...
@@ -211,7 +144,6 @@
             }
         }
     } else {
-        tr_info("blink cb\n");
         num_count--;
         led_com_0 = (num_count & 1);
         led_com_1 = (num_count & 1);
@@ -229,15 +161,138 @@
     }
 }
 
+/**
+ * Button function triggered by the physical button press.
+ */
+void button_press() {
+    int v = res_button->get_value_int() + 1;
+    res_button->set_value(v);
+    printf("*** Button clicked %d times                                 \n", v);
+}
+
+/**
+ * Notification callback handler
+ * @param resource The resource that triggered the callback
+ * @param status The delivery status of the notification
+ */
+void button_callback(MbedCloudClientResource *resource, const NoticationDeliveryStatus status) {
+    printf("*** Button notification, status %s (%d)                     \n", MbedCloudClientResource::delivery_status_to_string(status), status);
+}
+
+/**
+ * Registration callback handler
+ * @param endpoint Information about the registered endpoint such as the name (so you can find it back in portal)
+ */
+void registered(const ConnectorClientEndpointInfo *endpoint) {
+    printf("Registered to Pelion Device Management. Endpoint Name: %s\n", endpoint->internal_endpoint_name.c_str());
+    endpointInfo = endpoint;
+}
+
+/**
+ * Initialize sensors
+ */
+void sensors_init() {
+    barometer.initialize();
+
+    light_sensor.open();
+
+    SI7021::SI7021_status_t result = rht_sensor.SI7021_SoftReset();
+    if (result == SI7021::SI7021_SUCCESS) {
+        wait_ms(15);
+        SI7021::SI7021_vector_data_t result_data;
+        result = rht_sensor.SI7021_Conf(SI7021::SI7021_RESOLUTION_RH_11_TEMP_11,
+                                        SI7021::SI7021_HTRE_DISABLED);
+        result = rht_sensor.SI7021_GetElectronicSerialNumber(&result_data);
+        result = rht_sensor.SI7021_GetFirmwareRevision(&result_data);
+        printf("Si7021 Electronic Serial Number: %16x %16x, firmware rev %02x\n",
+                result_data.ElectronicSerialNumber_MSB,
+                result_data.ElectronicSerialNumber_LSB,
+                result_data.FirmwareRevision);
+    }
+
+    if(!aqs.init()) {
+        printf("CCS811: Failed init()\n");
+    } else {
+        if(!aqs.mode(AMS_CCS811::SIXTY_SECOND)) {
+            printf("CCS811: Failed to set mode\n");
+        }
+//        aqs.enable_interupt(true);
+    }
+}
+
+/**
+ * Update sensors and report their values.
+ * This function is called periodically.
+ */
+void sensors_update() {
+    static size_t CCS811_samples = 0;
+    SI7021::SI7021_status_t rht_reading, humidity_reading, temp_reading;
+    SI7021::SI7021_vector_data_t humidity_data, temp_data;
+
+    float val_barometer = barometer.getPressure();
+
+    float light_level, uv_index;
+    bool light_reading = light_sensor.get_light_and_uv(&light_level, &uv_index);
+
+    rht_reading = rht_sensor.SI7021_TriggerHumidity(SI7021::SI7021_NO_HOLD_MASTER_MODE);
+    if (rht_reading == SI7021::SI7021_SUCCESS) {
+        wait_ms(30);
+        humidity_reading = rht_sensor.SI7021_ReadHumidity(&humidity_data);
+        temp_reading = rht_sensor.SI7021_ReadTemperatureFromRH(&temp_data);
+        aqs.env_data(humidity_data.RelativeHumidity, temp_data.Temperature);
+    }
+
+    aqs.has_new_data();
+    int co2 = aqs.co2_read();
+    int tvoc = aqs.tvoc_read();
+
+    printf("                                                             \n");
+    printf("Si1133 light: %7.2f lux, UV level: %7.2f            \n", light_level, uv_index);
+    printf("SI7021 temp:  %7.2f C,   humidity: %7.2f %%         \n", temp_data.Temperature, humidity_data.RelativeHumidity);
+    printf("CCS811 CO2:   %7d ppm, TVOC:     %7d ppm        \n", co2, tvoc);
+    printf("BMP280 pressure: %7.2f hPa       \n", val_barometer);
+
+    printf("\r\033[5A");
+
+    if (endpointInfo) {
+#ifdef SEND_ALL_SENSORS
+        res_barometer->set_value(val_barometer);
+        if (light_reading) {
+            res_light->set_value(light_level);
+        }
+        if (humidity_reading == SI7021::SI7021_SUCCESS) {
+            res_humidity->set_value(humidity_data.RelativeHumidity);
+        }
+        if (temp_reading == SI7021::SI7021_SUCCESS) {
+            res_temperature->set_value(temp_data.Temperature);
+        }
+        res_co2->set_value(co2);
+        res_tvoc->set_value(tvoc);
+#endif /* SEND_ALL_SENSORS */
+    }
+}
+
 int main() {
+    printf("\nStarting Simple Pelion Device Management Client example\n");
+
+    int storage_status = fs.mount(&sd);
+    if (storage_status != 0) {
+        printf("Storage mounting failed.\n");
+    }
+
+#if USE_BUTTON == 1
     // If the User button is pressed ons start, then format storage.
-    if (rst_btn == 0) {
-        printf("User button is pushed on start. Formatting the storage...\n");
-        int storage_status = bd->erase(0, bd->size());
-        if (storage_status != 0) {
-            printf("ERROR: Failed to erase the storage (%d).\n", storage_status);
-        }
-        storage_status = StorageHelper::format(&fs, &sd);
+    bool btn_pressed = (button.read() == MBED_CONF_APP_BUTTON_PRESSED_STATE);
+    if (btn_pressed) {
+        printf("User button is pushed on start...\n");
+    }
+#else
+    bool btn_pressed = FALSE;
+#endif /* USE_BUTTON */
+
+    if (storage_status || btn_pressed) {
+        printf("Formatting the storage...\n");
+        int storage_status = StorageHelper::format(&fs, &sd);
         if (storage_status != 0) {
             printf("ERROR: Failed to reformat the storage (%d).\n", storage_status);
         }
@@ -248,107 +303,94 @@
     Nanostack::get_instance(); // ensure Nanostack is initialised
     ns_file_system_set_root_path("/fs/");
 
-    /* Initialize connectivity */
-    net->connect();
+    // Connect to the internet (DHCP is expected to be on)
+    printf("Connecting to the network using 802.15.4...\n");
+
+    nsapi_error_t net_status = -1;
+    for (int tries = 0; tries < 3; tries++) {
+        net_status = net->connect();
+        if (net_status == NSAPI_ERROR_OK) {
+            break;
+        } else {
+            printf("Unable to connect to network. Retrying...\n");
+        }
+    }
+
+    if (net_status != NSAPI_ERROR_OK) {
+        printf("ERROR: Connecting to the network failed (%d)!\n", net_status);
+        return -1;
+    }
+
+    printf("Connected to the network successfully. IP address: %s\n", net->get_ip_address());
+
+    printf("Initializing Pelion Device Management Client...\n");
 
     /* Initialize Simple Pelion DM Client */
     SimpleMbedCloudClient client(net, &sd, &fs);
-    client.init();
+    int client_status = client.init();
+    if (client_status != 0) {
+        printf("ERROR: Pelion Client initialization failed (%d)\n", client_status);
+        return -1;
+    }
 
     /* Create resources */
+    res_led = client.create_resource("3201/0/5853", "LED blinking (R:G:B:cnt)");
+    res_led->observable(false);
+    res_led->set_value("0:0:0:0");
+    res_led->attach_post_callback(blink_callback);
+    res_led->methods(M2MMethod::POST);
 
-    /* Thunderboard Sense 2 has *A LOT* of sensors. This demo app will expose:
-     * * Temperature
-     * * Relative Humidity
-     * * CO2
-     * * tVOC
-     * * light intensity (lux)
-     * * barometric pressure
-     * It also exposes the RGB LEDs for triggering flashes in a specific color
-     */
-    MbedCloudClientResource *variable;
-    variable = client.create_resource("3201/0/5853", "LED blinking (R:G:B:cnt)");
-    variable->observable(false);
-    variable->set_value("0:0:0:0");
-    variable->attach_post_callback(blink_callback);
-    variable->methods(M2MMethod::POST);
+    res_button = client.create_resource("3200/0/5501", "button_count");
+    res_button->set_value(0);
+    res_button->methods(M2MMethod::GET);
+    res_button->observable(true);
+    res_button->attach_notification_callback(button_callback);
 
-    MbedCloudClientResource *lux_res;
-    lux_res = client.create_resource("3301/0/5853", "LightIntensity (lux)");
-    lux_res->observable(true);
-    lux_res->methods(M2MMethod::GET);
+#ifdef SEND_ALL_SENSORS
+    res_light = client.create_resource("3301/0/5853", "LightIntensity (lux)");
+    res_light->set_value(0);
+    res_light->observable(true);
+    res_light->methods(M2MMethod::GET);
+
+    res_temperature = client.create_resource("3303/0/5853", "Temperature (C)");
+    res_temperature->set_value(0);
+    res_temperature->observable(true);
+    res_temperature->methods(M2MMethod::GET);
 
-    MbedCloudClientResource *baro_res;
-    baro_res = client.create_resource("3323/0/5853", "Barometric pressure (hPa)");
-    baro_res->observable(true);
-    baro_res->methods(M2MMethod::GET);
+    res_humidity = client.create_resource("3304/0/5853", "Humidity (%)");
+    res_humidity->set_value(0);
+    res_humidity->observable(true);
+    res_humidity->methods(M2MMethod::GET);
 
-    MbedCloudClientResource *temperature_res;
-    temperature_res = client.create_resource("3303/0/5853", "Temperature (C)");
-    temperature_res->observable(true);
-    temperature_res->methods(M2MMethod::GET);
+    res_barometer = client.create_resource("3323/0/5853", "Barometric pressure (hPa)");
+    res_barometer->set_value(0);
+    res_barometer->observable(true);
+    res_barometer->methods(M2MMethod::GET);
 
-    MbedCloudClientResource *humidity_res;
-    humidity_res = client.create_resource("3304/0/5853", "Humidity (%)");
-    humidity_res->observable(true);
-    humidity_res->methods(M2MMethod::GET);
+    res_co2 = client.create_resource("33255/0/5853", "CO2 (ppm)");
+    res_co2->set_value(0);
+    res_co2->observable(true);
+    res_co2->methods(M2MMethod::GET);
 
-    MbedCloudClientResource *co2_res;
-    co2_res = client.create_resource("33255/0/5853", "CO2 (ppm)");
-    co2_res->observable(true);
-    co2_res->methods(M2MMethod::GET);
+    res_tvoc = client.create_resource("33256/0/5853", "VOC (ppm)");
+    res_tvoc->set_value(0);
+    res_tvoc->observable(true);
+    res_tvoc->methods(M2MMethod::GET);
+#endif /* SEND_ALL_SENSORS */
 
-    MbedCloudClientResource *voc_res;
-    voc_res = client.create_resource("33256/0/5853", "VOC (ppm)");
-    voc_res->observable(true);
-    voc_res->methods(M2MMethod::GET);
+    sensors_init();
+
+    // Callback that fires when registering is complete
+    client.on_registered(&registered);
 
     /* Register the device */
     client.register_and_connect();
 
-    /* Set up measurements */
-    barometer.initialize();
-    eventQueue.call_every(BAROMETER_MEASURING_INTERVAL * 1000,
-                          measure_baro, baro_res);
-    measure_baro(baro_res);
-
-    if (light_sensor.open()) {
-        measure_lux(lux_res, (MbedCloudClientResource *)NULL);
-        eventQueue.call_every(LIGHT_MEASURING_INTERVAL * 1000,
-                              measure_lux, lux_res,
-                              (MbedCloudClientResource *)NULL);
-    } else {
-        tr_err("Disabling Si1133 because we can't find it on the bus");
-    }
+    button.fall(eventQueue.event(&button_press));
 
-    SI7021::SI7021_status_t result = rht_sensor.SI7021_SoftReset();
-    if (result == SI7021::SI7021_SUCCESS) {
-        wait_ms ( 15 );
-        SI7021::SI7021_vector_data_t result_data;
-        result = rht_sensor.SI7021_Conf(SI7021::SI7021_RESOLUTION_RH_11_TEMP_11,
-                                        SI7021::SI7021_HTRE_DISABLED);
-        result = rht_sensor.SI7021_GetElectronicSerialNumber(&result_data);
-        result = rht_sensor.SI7021_GetFirmwareRevision(&result_data);
-        tr_info("Si7021 Electronic Serial Number: %16x %16x\n",
-                result_data.ElectronicSerialNumber_MSB,
-                result_data.ElectronicSerialNumber_LSB);
-        tr_info("Firmware Revision: %02x\r\n", result_data.FirmwareRevision);
-
-        measure_rht(temperature_res, humidity_res);
-        eventQueue.call_every(RHT_MEASURING_INTERVAL * 1000,
-                              measure_rht, temperature_res, humidity_res);
-    }
-
-    /* Initialize air quality sensor */
-    if(!aqs.init()) {
-        tr_err("Failed CCS811 init\r\n");
-    } else {
-        if(!aqs.mode(AMS_CCS811::SIXTY_SECOND)) {
-            tr_err("Failed to set CCS811 mode\r\n");
-        }
-        ccs_int.fall(eventQueue.event(measure_airquality, co2_res, voc_res));
-        aqs.enable_interupt(true);
-    }
+    // The timer fires on an interrupt context, but debounces it to the eventqueue, so it's safe to do network operations
+    Ticker timer;
+    timer.attach(eventQueue.event(&sensors_update), SENSORS_POLL_INTERVAL);
 
     eventQueue.dispatch_forever();
-}
\ No newline at end of file
+}