Updates to OICSensorboard example
authorJuliet Cai <juliet.z.cai@intel.com>
Mon, 8 Jun 2015 20:50:47 +0000 (13:50 -0700)
committerErich Keane <erich.keane@intel.com>
Tue, 30 Jun 2015 16:48:02 +0000 (16:48 +0000)
* Updated OICSensorBoard client to work with the latest API
* Modified the server code for temperature conversion to reflect a minor circuit change
* Deleted OICSensorBoardREADME.pdf
* Added README and point to wiki page

Change-Id: Iab74e08f934e2a2c7c50c015b43e8fde8651bc85
Signed-off-by: Juliet Cai <juliet.z.cai@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1221
Reviewed-by: Erich Keane <erich.keane@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
examples/OICSensorBoard/OICSensorBoardREADME.pdf [deleted file]
examples/OICSensorBoard/README [new file with mode: 0644]
examples/OICSensorBoard/client.cpp
examples/OICSensorBoard/sensors.h
examples/OICSensorBoard/server.cpp

diff --git a/examples/OICSensorBoard/OICSensorBoardREADME.pdf b/examples/OICSensorBoard/OICSensorBoardREADME.pdf
deleted file mode 100644 (file)
index e98506b..0000000
Binary files a/examples/OICSensorBoard/OICSensorBoardREADME.pdf and /dev/null differ
diff --git a/examples/OICSensorBoard/README b/examples/OICSensorBoard/README
new file mode 100644 (file)
index 0000000..c941e9a
--- /dev/null
@@ -0,0 +1,14 @@
+//******************************************************************
+//
+// This example includes
+// - Server application for Edison which demonstrates Iotivity server
+//   capabilities through the integration of an add-on breadboard that
+//   hosts temperature, ambient light and LED resources.
+// - Client application to test server functionality, discovering and
+//   communicating with these resources.
+//
+// See complete documentation at
+//        https://wiki.iotivity.org/_media/oicsensorboardreadme.pdf
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
index 096fa85..47485b6 100644 (file)
@@ -42,7 +42,7 @@ void IoTClient::initializePlatform()
 
 void IoTClient::findResource()
 {
-    string coap_multicast_discovery = string(OC_WELL_KNOWN_QUERY "?if=" EDISON_RESOURCE_INTERFACE);
+    string coap_multicast_discovery = string(OC_MULTICAST_DISCOVERY_URI "?if=" EDISON_RESOURCE_INTERFACE);
     OCPlatform::findResource("", coap_multicast_discovery.c_str(),  OC_ALL, m_resourceDiscoveryCallback,
                              OC::QualityOfService::LowQos);
 }
@@ -148,7 +148,7 @@ void TemperatureSensor::onObserve(const HeaderOptions headerOptions, const OCRep
     {
         double value;
         rep.getValue(TEMPERATURE_RESOURCE_KEY, value);
-        cout << "Observing TemperatureSensor: Current temperature reading is " << value << endl;
+        cout << "Observing TemperatureSensor: Current temperature reading in Celsius is " << value << endl;
         cout << "Sequence number: " << sequenceNumber << endl;
     }
     else
@@ -170,7 +170,7 @@ void TemperatureSensor::onGet(const HeaderOptions& headerOptions,
     {
         double value;
         representation.getValue(TEMPERATURE_RESOURCE_KEY, value);
-        cout << endl << endl << "Current temperature reading: " << value << endl;
+        cout << endl << endl << "Current temperature reading in Celsius: " << value << endl;
     }
     else {
         cerr << endl << endl << "Error in GET response from temperature sensor resource" << endl;
index 44ad441..aecbf4c 100644 (file)
@@ -25,6 +25,7 @@
 #define ONBOARD_LED_PIN 13
 #define TEMPERATURE_AIO_PIN 0
 #define LIGHT_SENSOR_AIO_PIN 2
+#define SAMPLE_NUM 5
 
 namespace Sensors
 {
@@ -60,20 +61,40 @@ inline void SetOnboardLed(int on)
         mraa_gpio_write(led_gpio, on); // Writes into GPIO
 }
 
-inline float GetTemperatureInC()
+inline float GetAverageTemperatureRaw()
 {
-    float ret = 0;
     if (tmp_aio == NULL)
     {
         tmp_aio = mraa_aio_init(TEMPERATURE_AIO_PIN); // initialize pin 0
     }
-    if (tmp_aio != NULL)
-    {
-        uint16_t adc_value = mraa_aio_read(tmp_aio); // read the raw value
-        //convert reading to temperature
-        float beta = 4090.0; //the beta of the thermistor, magic number
-        ret = beta / (log((4095.0 * 10 / adc_value - 10) / 10) + beta / 298.0) - 273.0;
-    }
+    
+    uint16_t adc_value = 0;
+    for (int i=0; i< SAMPLE_NUM; i++)
+        adc_value += mraa_aio_read(tmp_aio);           // read the raw value
+    
+    float average = (float)adc_value/SAMPLE_NUM;
+    cout << "Temperature reading raw ..."  << average << endl;
+    
+    return average;
+}
+
+inline float GetTemperatureInC()
+{
+    // Temperature calculation using simpilfy Steinhart-Hart equation
+    //
+    //          1/T = 1/T0 + 1/beta*ln (R/R0)
+    //
+    // where T0 = 25C room temp, R0 = 10000 ohms
+    //
+    float beta = 4090.0;            //the beta of the thermistor, magic number
+    float t_raw = GetAverageTemperatureRaw();
+    float R = 1023.0/t_raw -1;      // 
+    R = 10000.0/R;                  // 10K resistor divider circuit
+        
+    float T1 = log(R/10000.0)/beta; // natural log 
+    float T2 = T1 + 1.0/298.15;     // room temp 25C= 298.15K
+    float ret = 1.0/T2 - 273.0;
     return ret;
 }
 
index 598e370..a8b7a23 100644 (file)
@@ -20,6 +20,7 @@
 #include <signal.h>
 #include <thread>
 #include <functional>
+
 #include "server.h"
 #include "sensors.h"
 #include "namedefs.h"