pelion-example-common

Dependencies:   ublox-at-cellular-interface ublox-cellular-base

Revision:
1:a50c1e691ff1
Parent:
0:a076a1bbe630
Child:
3:3b2db67b206e
--- a/main.cpp	Mon Dec 10 21:58:43 2018 +0000
+++ b/main.cpp	Tue Dec 11 00:39:31 2018 +0000
@@ -35,21 +35,26 @@
 LittleFileSystem fs("fs", &sd);
 
 // Default User button for GET example
-InterruptIn button(USER_BUTTON);
+InterruptIn button(BUTTON1);
 // Default LED to use for PUT/POST example
 DigitalOut led(LED1);
+
+#ifdef ENABLE_SENSORS
 // Default temperature reading from microcontroller
 AnalogIn adc_temp(ADC_TEMP);
 // Voltage reference from microcontroller
 AnalogIn adc_vref(ADC_VREF);
 
 #define SENSORS_POLL_INTERVAL 1.0
+#endif /* ENABLE_SENSORS */
 
 // Declaring pointers for access to Pelion Client resources outside of main()
 MbedCloudClientResource *res_button;
 MbedCloudClientResource *res_led;
+#ifdef ENABLE_SENSORS
 MbedCloudClientResource *res_temperature;
 MbedCloudClientResource *res_voltage;
+#endif /* ENABLE_SENSORS */
 
 // When the device is registered, this variable will be used to access various useful information, like device ID etc.
 static const ConnectorClientEndpointInfo* endpointInfo;
@@ -107,6 +112,7 @@
  * Update sensors and report their values.
  * This function is called periodically.
  */
+#ifdef ENABLE_SENSORS
 void sensors_update() {
     float temp = adc_temp.read()*100;
     float vref = adc_vref.read();
@@ -116,6 +122,7 @@
         res_voltage->set_value(vref);
     }
 }
+#endif /* ENABLE_SENSORS */
 
 
 int main(void) {
@@ -123,7 +130,7 @@
 
     // If the User button is pressed ons start, then format storage.
     const int PRESSED = 1;
-    DigitalIn *user_button = new DigitalIn(USER_BUTTON);
+    DigitalIn *user_button = new DigitalIn(BUTTON1);
     if (user_button->read() == PRESSED) {
         printf("User button is pushed on start. Formatting the storage...\n");
         int storage_status = fs.reformat(&sd);
@@ -181,6 +188,7 @@
     res_led->methods(M2MMethod::GET | M2MMethod::PUT);
     res_led->attach_put_callback(led_put_callback);
 
+#ifdef ENABLE_SENSORS
     // Sensor resources
     res_temperature = client.create_resource("3303/0/5700", "temperature");
     res_temperature->set_value(0);
@@ -191,6 +199,7 @@
     res_voltage->set_value(0);
     res_voltage->methods(M2MMethod::GET);
     res_voltage->observable(true);
+#endif /* ENABLE_SENSORS */
 
     printf("Initialized Pelion Client. Registering...\n");
 
@@ -207,9 +216,11 @@
 
     button.fall(eventQueue.event(&button_press));
 
+#ifdef ENABLE_SENSORS
     // 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);
+#endif /* ENABLE_SENSORS */
 
     // You can easily run the eventQueue in a separate thread if required
     eventQueue.dispatch_forever();