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:
14:5a9ba3d8c9ca
Parent:
13:ab5db87a253a
--- a/main.cpp	Mon Sep 01 01:48:53 2014 +0000
+++ b/main.cpp	Mon Oct 13 10:29:06 2014 +0000
@@ -1,83 +1,66 @@
 #include "mbed.h"
-//#include "WiflyInterface.h"
-#include "EthernetInterfaceW5500.h"
+#include "W5500Interface/EthernetInterface.h"
 #include "xively.h"
 #include "xi_err.h"
 
-//#define XI_FEED_ID 273104668 // set Xively Feed ID (numerical, no quoutes)
-//#define XI_API_KEY "Your API Key" // set Xively API key (double-quoted string)
-#define XI_FEED_ID 614972906 // set Xively Feed ID (numerical, no quoutes)
-#define XI_API_KEY "Z2CG4NytDaxrk2LRSViyVVvi4kpWPH3bnrHeby24k8JCBZp1" // set Xively API key (double-quoted string)
+#define XI_FEED_ID YOUR-FEED-ID // set Xively Feed ID (numerical, no quoutes)
+#define XI_API_KEY "Your API Key" // set Xively API key (double-quoted string)
 
 //Serial pc(USBTX, USBRX);
 DigitalOut myled(LED1);
-#define _SENSOR
+
+#define _SENSOR_DS18B20
 
-#ifdef _SENSOR // if there is sensor.
+#ifdef _SENSOR_DS18B20 // if there is sensor.
 #include "DS18B20.h"
-//DS18B20Sensor sensor(P1_25);
-DS18B20 sensor(P1_25, DS18B20::RES_12_BIT); // Dallas 1-wire
 #endif
 
-//#define _DHCP
+#define _DHCP
 
-/* wifly object where:
-*     - p9 and p10 are for the serial communication
-*     - p25 is for the reset pin
-*     - p26 is for the connection status
-*     - "mbed" is the ssid of the network
-*     - "password" is the password
-*     - WPA is the security
-*/
-//WiflyInterface eth(p9, p10, p25, p26, "ssid", "passwd", WPA);
 
 int main()
 {
 #if defined(TARGET_LPC1114)
     SPI spi(dp2, dp1, dp6); // mosi, miso, sclk
-    EthernetInterfaceW5500 eth(&spi, dp25, dp26); // spi, cs, reset
-
+    EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset
+    DS18B20 sensor(D3, DS18B20::RES_12_BIT); // Dallas 1-wire
 #elif defined(TARGET_LPC1768)
     SPI spi(p11, p12, p13); // mosi, miso, sclk
-    EthernetInterfaceW5500 eth(&spi, p14, p15); // spi, cs, reset
-
+    EthernetInterface eth(&spi, p14, p15); // spi, cs, reset
 #elif defined(TARGET_LPC11U68)
     SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk
-//WIZnetInterface eth(&spi, P0_2, P1_25); // spi, cs, reset
-//SPI spi(p5, p6, p7); // mosi, miso, sclk
-    EthernetInterfaceW5500 eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io
+    EthernetInterface eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io
     spi.format(8,0); // 8bit, mode 0
     spi.frequency(7000000); // 7MHz
     wait(1); // 1 second for stable state
-
+    DS18B20 sensor(P1_25, DS18B20::RES_12_BIT); // Dallas 1-wire
+#elif defined(TARGET_KL25Z)
+    Serial pc(USBTX, USBRX);
+    pc.baud(115200);
+    printf("spi init\r\n");
+    SPI spi(D11, D12, D13); // mosi, miso, sclk
+    wait(1); // 1 second for stable state
+    EthernetInterface eth(&spi, D10, D9);//scs(D10), nRESET(PTA20)
+    printf("App Start\r\n");
+    wait(1); // 1 second for stable state
+    DS18B20 sensor(D3, DS18B20::RES_12_BIT); // Dallas 1-wire
+#elif defined(TARGET_NUCLEO_F030R8)    
+    Serial pc(USBTX, USBRX);
+    pc.baud(115200);
+    printf("spi init\r\n");
+    SPI spi(D11, D12, D13); // mosi, miso, sclk
+    wait(1); // 1 second for stable state
+    EthernetInterface eth(&spi, D10, D9);//scs(D10), nRESET(PTA20)
+    printf("App Start\r\n");
+    wait(1); // 1 second for stable state
 #endif
-/*
-    int s = eth.init(); //Use DHCP
-
-    if( s != NULL ) {
-        printf( "Could not initialise. Will halt!\n" );
-        exit( 0 );
-    }
-
-    s = eth.connect();
-
-    if( s == false ) {
-        printf( "Could not connect. Will halt!\n" );
-        exit( 0 );
-    } else {
-        printf( "IP: %s\n", eth.getIPAddress() );
-    }
-*/
 
 #ifdef _DHCP // didn't test yet in DHCP
-
     eth.init(); //Use DHCP
     eth.connect();
-    //printf("IP Address is %s\n\r", eth.getIPAddress());
     printf("Initialized, MAC: %s\n", eth.getMACAddress());
     printf("Connected, IP: %s, MASK: %s, GW: %s\n",
            eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
-
 #else
     // as your env. change to real IP address and so on.
     int ret = eth.init("222.98.173.211", "255.255.255.192", "222.98.173.254");
@@ -92,12 +75,10 @@
 #endif
 
 // Sensor variables
-#ifdef _SENSOR // if there is sensor.
+#ifdef _SENSOR_DS18B20 // 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();
    printf("DS18B20 Configuration\n\r");
    DS18B20::ROM_Code_t ROM_Code;
    sensor.ReadROM(&ROM_Code);
@@ -137,7 +118,7 @@
     }
 
     while(1) {
-#ifdef _SENSOR // if there is sensor.
+#ifdef _SENSOR_DS18B20 // if there is sensor.
 /*
         if (sensor_cnt) {
             result = sensor.startReading(true);     // start sensor readings and wait
@@ -156,8 +137,8 @@
 */
         // use New library for DS18B20
         sprintf(sensorBuf,"%4.2f", sensor.GetTemperature());
+        printf("Sensor Buf : %s\r\n",sensorBuf);
         xi_set_value_str( current_orientation, sensorBuf );
-
 #else
         xi_set_value_str( current_orientation, "27" );
 #endif
@@ -165,7 +146,7 @@
         printf( "update..." );
         // send to xively server
         xi_feed_update( xi_context, &feed );
-        printf( "done...\n" );
+        printf( "done...\r\n" );
         wait( 5.0 );
     }
 }