Xively Demo - WIZ550io, W5500 (WIZnet) + Temperature Sensor (DS18B20) EthernetInterfaceW5500 + LPC11U68 Xpresso v2 used

Dependencies:   DS18B20_1wire W5500Interface libxively mbed

Fork of WIZ550io_Xively_Demo by Bongjun Hur

Xively Demo

Board Pic

LPC11U68 + WIZ550io (WIZnet) + DS18B20 Temp Sensor https://31.media.tumblr.com/d63982be5ee62cb7889cde9e685ee757/tumblr_n8s27sY62b1sama12o1_500.jpg

PC Screenshot

/media/uploads/Bongjun/img135.png

Revision:
10:6497effa1a26
Parent:
8:a0edf4bce160
Child:
13:ab5db87a253a
--- a/main.cpp	Wed Jul 09 06:54:05 2014 +0000
+++ b/main.cpp	Mon Jul 14 06:49:43 2014 +0000
@@ -1,7 +1,6 @@
 #include "mbed.h"
 //#include "WiflyInterface.h"
 #include "EthernetInterfaceW5500.h"
-#include "DS18B20Sensor.h"
 #include "xively.h"
 #include "xi_err.h"
 
@@ -12,7 +11,13 @@
 
 //Serial pc(USBTX, USBRX);
 DigitalOut myled(LED1);
-DS18B20Sensor sensor(P1_25);
+#define _SENSOR
+
+#ifdef _SENSOR // if there is sensor.
+#include "DS18B20.h"
+//DS18B20Sensor sensor(P1_25);
+DS18B20 sensor(P1_25, DS18B20::RES_12_BIT); // Dallas 1-wire
+#endif
 
 /* wifly object where:
 *     - p9 and p10 are for the serial communication
@@ -85,12 +90,29 @@
 #endif
 
 // Sensor variables
+#ifdef _SENSOR // if there is sensor.
     char sensorBuf[25];
-    uint8_t result;
-    uint8_t sensor_cnt;
-
-    //Before using this sensor, should called sensor.count() once.
-    sensor_cnt = sensor.count();
+//    uint8_t result;
+//    uint8_t sensor_cnt;
+//Before using this sensor, should called sensor.count() once.
+//    sensor_cnt = sensor.count();
+   printf("DS18B20 Configuration\n\r");
+   DS18B20::ROM_Code_t ROM_Code;
+   sensor.ReadROM(&ROM_Code);
+   printf("Family code: 0x%X\n\r", ROM_Code.BYTES.familyCode);
+   printf("Serial Number: ");
+   for (unsigned i = 6; i != 0; --i) {
+       printf("%02X%s", ROM_Code.BYTES.serialNo[i-1], (i != 1)?":":"\r\n");
+   }
+   printf("CRC: 0x%X\r\n", ROM_Code.BYTES.CRC);
+/*
+   printf("\n\rRunning temperature conversion...\n\r");
+   while (1) {
+       printf("Temperature is: %.4fC\n\r", sensor.GetTemperature());
+       wait(10);
+   }
+*/    
+#endif
 
     xi_feed_t feed;
     memset( &feed, NULL, sizeof( xi_feed_t ) );
@@ -113,6 +135,8 @@
     }
 
     while(1) {
+#ifdef _SENSOR // if there is sensor.
+/*
         if (sensor_cnt) {
             result = sensor.startReading(true);     // start sensor readings and wait
             if (result == DS18X20_OK) {
@@ -127,11 +151,19 @@
         } else {
             printf("No Sensor");
         }
+*/
+        // use New library for DS18B20
+        sprintf(sensorBuf,"%4.2f", sensor.GetTemperature());
+        xi_set_value_str( current_orientation, sensorBuf );
+
+#else
+        xi_set_value_str( current_orientation, "27" );
+#endif
 
         printf( "update..." );
         // send to xively server
         xi_feed_update( xi_context, &feed );
         printf( "done...\n" );
-        wait( 10.0 );
+        wait( 15.0 );
     }
 }