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

Files at this revision

API Documentation at this revision

Comitter:
Bongjun
Date:
Wed Jul 09 04:20:16 2014 +0000
Parent:
6:3c44af154da8
Child:
8:a0edf4bce160
Commit message:
Xively Demo - WIZ550io(W5500) + Temperature Sensor; use EthernetInterfaceW5500

Changed in this revision

DS18B20Sensor.lib Show annotated file Show diff for this revision Revisions of this file
EthernetInterfaceW5500.lib Show annotated file Show diff for this revision Revisions of this file
WiflyInterface.lib Show diff for this revision Revisions of this file
libxively.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS18B20Sensor.lib	Wed Jul 09 04:20:16 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Bongjun/code/DS18B20Sensor/#0bcc4e42fec0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterfaceW5500.lib	Wed Jul 09 04:20:16 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Bongjun/code/EthernetInterfaceW5500/#c3e1a015e0f5
--- a/WiflyInterface.lib	Sat Nov 09 01:02:05 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/lz307/code/WiflyInterface/#3152fcc74390
--- a/libxively.lib	Sat Nov 09 01:02:05 2013 +0000
+++ b/libxively.lib	Wed Jul 09 04:20:16 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/xively/code/libxively/#4ce6299f7535
+http://mbed.org/users/xively/code/libxively/#1208875310d3
--- a/main.cpp	Sat Nov 09 01:02:05 2013 +0000
+++ b/main.cpp	Wed Jul 09 04:20:16 2014 +0000
@@ -1,12 +1,16 @@
 #include "mbed.h"
-#include "WiflyInterface.h"
+//#include "WiflyInterface.h"
+#include "EthernetInterfaceW5500.h"
+#include "DS18B20Sensor.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)
 
-Serial pc(USBTX, USBRX);
+//Serial pc(USBTX, USBRX);
+DigitalOut myled(LED1);
+DS18B20Sensor sensor(P1_25);
 
 /* wifly object where:
 *     - p9 and p10 are for the serial communication
@@ -16,10 +20,29 @@
 *     - "password" is the password
 *     - WPA is the security
 */
-WiflyInterface eth(p9, p10, p25, p26, "ssid", "passwd", WPA);
+//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
+
+#elif defined(TARGET_LPC1768)
+    SPI spi(p11, p12, p13); // mosi, miso, sclk
+    EthernetInterfaceW5500 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
+    spi.format(8,0); // 8bit, mode 0
+    spi.frequency(7000000); // 7MHz
+    wait(1); // 1 second for stable state
+
+#endif
+/*
     int s = eth.init(); //Use DHCP
 
     if( s != NULL ) {
@@ -35,6 +58,40 @@
     } 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("YourIP", "YourNetmask", "YourGateway");
+    // example..
+    //int ret = eth.init("xxx.xxx.xxx.xxx", "255.255.255.0", "xxx.xxx.xxx.xxx");
+
+    if (!ret) {
+        printf("Initialized, MAC: %s\n", eth.getMACAddress());
+        printf("Connected, IP: %s, MASK: %s, GW: %s\n",
+               eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
+    } else {
+        printf("Error eth.init() - ret = %d\n", ret);
+        return -1;
+    }
+#endif
+
+// Sensor variables
+    char sensorBuf[25];
+    uint8_t result;
+    uint8_t sensor_cnt;
+
+    //Before using this sensor, should called sensor.count() once.
+    sensor_cnt = sensor.count();
 
     xi_feed_t feed;
     memset( &feed, NULL, sizeof( xi_feed_t ) );
@@ -44,7 +101,7 @@
 
     feed.datastreams[0].datapoint_count = 1;
     xi_datastream_t* orientation_datastream = &feed.datastreams[0];
-    strcpy( orientation_datastream->datastream_id, "orientation" );
+    strcpy( orientation_datastream->datastream_id, "Channel_Test1" );
     xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0];
 
     // create the cosm library context
@@ -57,15 +114,25 @@
     }
 
     while(1) {
-        time_t seconds = time(NULL);
-        char buffer[32];
-        // get the current time
-        strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
-        xi_set_value_str( current_orientation, buffer );
+        if (sensor_cnt) {
+            result = sensor.startReading(true);     // start sensor readings and wait
+            if (result == DS18X20_OK) {
+                sensor.getReading(sensorBuf, 0);         // get result into buf
+                xi_set_value_str( current_orientation, sensorBuf );
+            }
+            else
+            {
+                xi_set_value_str( current_orientation, "0" );
+                }
+            
+        } else {
+            printf("No Sensor");
+        }
+
         printf( "update...\n" );
         // send to xively server
         xi_feed_update( xi_context, &feed );
         printf( "done...\n" );
-        wait( 1.0 );
+        wait( 10.0 );
     }
 }
--- a/mbed.bld	Sat Nov 09 01:02:05 2013 +0000
+++ b/mbed.bld	Wed Jul 09 04:20:16 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae
\ No newline at end of file