Remote monitoring IoTHub device sample Added real SHTx sensor to get temperature and humidity Added new command to set temperature scale change Removed "mock" commands to set temperature and humidity values It's configured to work on FRDM-K64F board

Dependencies:   EthernetInterface NTPClient SHTx iothub_amqp_transport iothub_client mbed-rtos mbed proton-c-mbed serializer wolfSSL

Fork of remote_monitoring by Azure IoT

Revision:
23:e37e4e321690
Parent:
22:afe08a0ed332
--- a/remote_monitoring.c	Fri Nov 13 16:08:20 2015 -0800
+++ b/remote_monitoring.c	Sun Nov 15 15:34:16 2015 +0000
@@ -12,10 +12,19 @@
 #include "certs.h"
 #endif // MBED_BUILD_TIMESTAMP
 
+#include "SHTx/sht15_export.h"
+
+/*
 static const char* deviceId = "[Device Id]";
 static const char* deviceKey = "[Device Key]";
 static const char* hubName = "[IoTHub Name]";
 static const char* hubSuffix = "[IoTHub Suffix, i.e. azure-devices.net]";
+*/
+
+static const char* deviceId = "frdm-k64f";
+static const char* deviceKey = "BoiNPBlt1odSFfl/wQQtrrzuBLBGeqTqpiOsRKBecus=";
+static const char* hubName = "ppatiernoiothub";
+static const char* hubSuffix = "azure-devices.net";
 
 // Define the Model
 BEGIN_NAMESPACE(Contoso);
@@ -46,12 +55,23 @@
     WITH_DATA(ascii_char_ptr_no_quotes, Commands),
 
     /* Commands implemented by the device */
-    WITH_ACTION(SetTemperature, double, temperature),
-	WITH_ACTION(SetHumidity, double, humidity)
+    //WITH_ACTION(SetTemperature, double, temperature),
+	//WITH_ACTION(SetHumidity, double, humidity)
+	WITH_ACTION(SetScale, bool, scale)
 );
 
 END_NAMESPACE(Contoso);
 
+// { "Name" : "SetScale", "Parameters": { "scale" : false } }
+EXECUTE_COMMAND_RESULT SetScale(Thermostat* thermostat, bool scale)
+{
+	(void)printf("Received scale %d\r\n", scale);
+	SHT15_setScale(scale);
+	return EXECUTE_COMMAND_SUCCESS;
+}
+
+/*
+// { "Name" : "SetTemperature", "Parameters": { "temperature" : 10 } }
 EXECUTE_COMMAND_RESULT SetTemperature(Thermostat* thermostat, double temperature)
 {
     (void)printf("Received temperature %.02fs\r\n", temperature);
@@ -59,12 +79,14 @@
     return EXECUTE_COMMAND_SUCCESS;
 }
 
+// { "Name" : "SetHumidity", "Parameters": { "humidity" : 20 } }
 EXECUTE_COMMAND_RESULT SetHumidity(Thermostat* thermostat, double humidity)
 {
 	(void)printf("Received humidity %.02fs\r\n", humidity);
 	thermostat->Humidity = humidity;
 	return EXECUTE_COMMAND_SUCCESS;
 }
+*/
 
 static void sendMessage(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const unsigned char* buffer, size_t size)
 {
@@ -217,10 +239,18 @@
 					thermostat->Humidity = 50.0;
 					thermostat->DeviceId = (char*)deviceId;
 
+					SHT15_init();
+
                     while (1)
                     {
                         unsigned char*buffer;
                         size_t bufferSize;
+                        
+                        SHT15_update();
+                        
+                        thermostat->Temperature = SHT15_getTemperature();
+                        thermostat->ExternalTemperature = SHT15_getTemperature();
+                        thermostat->Humidity = SHT15_getHumidity();
 
 						(void)printf("Sending sensor value Temperature = %02f, Humidity = %02f\r\n", thermostat->Temperature, thermostat->Humidity);