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

Committer:
Bongjun
Date:
Mon Sep 01 01:48:53 2014 +0000
Revision:
13:ab5db87a253a
Parent:
10:6497effa1a26
Child:
14:5a9ba3d8c9ca
Update Ethernet Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 0:90ba0f51aa64 1 #include "mbed.h"
Bongjun 7:5ce11b80fb04 2 //#include "WiflyInterface.h"
Bongjun 7:5ce11b80fb04 3 #include "EthernetInterfaceW5500.h"
lz307 6:3c44af154da8 4 #include "xively.h"
lz307 6:3c44af154da8 5 #include "xi_err.h"
lz307 6:3c44af154da8 6
Bongjun 8:a0edf4bce160 7 //#define XI_FEED_ID 273104668 // set Xively Feed ID (numerical, no quoutes)
Bongjun 8:a0edf4bce160 8 //#define XI_API_KEY "Your API Key" // set Xively API key (double-quoted string)
Bongjun 8:a0edf4bce160 9 #define XI_FEED_ID 614972906 // set Xively Feed ID (numerical, no quoutes)
Bongjun 8:a0edf4bce160 10 #define XI_API_KEY "Z2CG4NytDaxrk2LRSViyVVvi4kpWPH3bnrHeby24k8JCBZp1" // set Xively API key (double-quoted string)
samux 1:49e1e9ed6e39 11
Bongjun 7:5ce11b80fb04 12 //Serial pc(USBTX, USBRX);
Bongjun 7:5ce11b80fb04 13 DigitalOut myled(LED1);
Bongjun 10:6497effa1a26 14 #define _SENSOR
Bongjun 10:6497effa1a26 15
Bongjun 10:6497effa1a26 16 #ifdef _SENSOR // if there is sensor.
Bongjun 10:6497effa1a26 17 #include "DS18B20.h"
Bongjun 10:6497effa1a26 18 //DS18B20Sensor sensor(P1_25);
Bongjun 10:6497effa1a26 19 DS18B20 sensor(P1_25, DS18B20::RES_12_BIT); // Dallas 1-wire
Bongjun 10:6497effa1a26 20 #endif
samux 1:49e1e9ed6e39 21
Bongjun 13:ab5db87a253a 22 //#define _DHCP
Bongjun 13:ab5db87a253a 23
samux 1:49e1e9ed6e39 24 /* wifly object where:
samux 1:49e1e9ed6e39 25 * - p9 and p10 are for the serial communication
samux 3:3b84102f022e 26 * - p25 is for the reset pin
samux 3:3b84102f022e 27 * - p26 is for the connection status
samux 1:49e1e9ed6e39 28 * - "mbed" is the ssid of the network
samux 1:49e1e9ed6e39 29 * - "password" is the password
samux 5:867d16e948eb 30 * - WPA is the security
samux 1:49e1e9ed6e39 31 */
Bongjun 7:5ce11b80fb04 32 //WiflyInterface eth(p9, p10, p25, p26, "ssid", "passwd", WPA);
lz307 6:3c44af154da8 33
lz307 6:3c44af154da8 34 int main()
lz307 6:3c44af154da8 35 {
Bongjun 7:5ce11b80fb04 36 #if defined(TARGET_LPC1114)
Bongjun 7:5ce11b80fb04 37 SPI spi(dp2, dp1, dp6); // mosi, miso, sclk
Bongjun 7:5ce11b80fb04 38 EthernetInterfaceW5500 eth(&spi, dp25, dp26); // spi, cs, reset
Bongjun 7:5ce11b80fb04 39
Bongjun 7:5ce11b80fb04 40 #elif defined(TARGET_LPC1768)
Bongjun 7:5ce11b80fb04 41 SPI spi(p11, p12, p13); // mosi, miso, sclk
Bongjun 7:5ce11b80fb04 42 EthernetInterfaceW5500 eth(&spi, p14, p15); // spi, cs, reset
Bongjun 7:5ce11b80fb04 43
Bongjun 7:5ce11b80fb04 44 #elif defined(TARGET_LPC11U68)
Bongjun 7:5ce11b80fb04 45 SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk
Bongjun 7:5ce11b80fb04 46 //WIZnetInterface eth(&spi, P0_2, P1_25); // spi, cs, reset
Bongjun 7:5ce11b80fb04 47 //SPI spi(p5, p6, p7); // mosi, miso, sclk
Bongjun 7:5ce11b80fb04 48 EthernetInterfaceW5500 eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io
Bongjun 7:5ce11b80fb04 49 spi.format(8,0); // 8bit, mode 0
Bongjun 7:5ce11b80fb04 50 spi.frequency(7000000); // 7MHz
Bongjun 7:5ce11b80fb04 51 wait(1); // 1 second for stable state
Bongjun 7:5ce11b80fb04 52
Bongjun 7:5ce11b80fb04 53 #endif
Bongjun 7:5ce11b80fb04 54 /*
lz307 6:3c44af154da8 55 int s = eth.init(); //Use DHCP
lz307 6:3c44af154da8 56
lz307 6:3c44af154da8 57 if( s != NULL ) {
lz307 6:3c44af154da8 58 printf( "Could not initialise. Will halt!\n" );
lz307 6:3c44af154da8 59 exit( 0 );
lz307 6:3c44af154da8 60 }
lz307 6:3c44af154da8 61
lz307 6:3c44af154da8 62 s = eth.connect();
lz307 6:3c44af154da8 63
lz307 6:3c44af154da8 64 if( s == false ) {
lz307 6:3c44af154da8 65 printf( "Could not connect. Will halt!\n" );
lz307 6:3c44af154da8 66 exit( 0 );
lz307 6:3c44af154da8 67 } else {
lz307 6:3c44af154da8 68 printf( "IP: %s\n", eth.getIPAddress() );
lz307 6:3c44af154da8 69 }
Bongjun 7:5ce11b80fb04 70 */
Bongjun 7:5ce11b80fb04 71
Bongjun 7:5ce11b80fb04 72 #ifdef _DHCP // didn't test yet in DHCP
Bongjun 7:5ce11b80fb04 73
Bongjun 7:5ce11b80fb04 74 eth.init(); //Use DHCP
Bongjun 7:5ce11b80fb04 75 eth.connect();
Bongjun 7:5ce11b80fb04 76 //printf("IP Address is %s\n\r", eth.getIPAddress());
Bongjun 7:5ce11b80fb04 77 printf("Initialized, MAC: %s\n", eth.getMACAddress());
Bongjun 7:5ce11b80fb04 78 printf("Connected, IP: %s, MASK: %s, GW: %s\n",
Bongjun 7:5ce11b80fb04 79 eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
Bongjun 7:5ce11b80fb04 80
Bongjun 7:5ce11b80fb04 81 #else
Bongjun 7:5ce11b80fb04 82 // as your env. change to real IP address and so on.
Bongjun 13:ab5db87a253a 83 int ret = eth.init("222.98.173.211", "255.255.255.192", "222.98.173.254");
Bongjun 7:5ce11b80fb04 84 if (!ret) {
Bongjun 7:5ce11b80fb04 85 printf("Initialized, MAC: %s\n", eth.getMACAddress());
Bongjun 7:5ce11b80fb04 86 printf("Connected, IP: %s, MASK: %s, GW: %s\n",
Bongjun 7:5ce11b80fb04 87 eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
Bongjun 7:5ce11b80fb04 88 } else {
Bongjun 7:5ce11b80fb04 89 printf("Error eth.init() - ret = %d\n", ret);
Bongjun 7:5ce11b80fb04 90 return -1;
Bongjun 7:5ce11b80fb04 91 }
Bongjun 7:5ce11b80fb04 92 #endif
Bongjun 7:5ce11b80fb04 93
Bongjun 7:5ce11b80fb04 94 // Sensor variables
Bongjun 10:6497effa1a26 95 #ifdef _SENSOR // if there is sensor.
Bongjun 7:5ce11b80fb04 96 char sensorBuf[25];
Bongjun 10:6497effa1a26 97 // uint8_t result;
Bongjun 10:6497effa1a26 98 // uint8_t sensor_cnt;
Bongjun 10:6497effa1a26 99 //Before using this sensor, should called sensor.count() once.
Bongjun 10:6497effa1a26 100 // sensor_cnt = sensor.count();
Bongjun 10:6497effa1a26 101 printf("DS18B20 Configuration\n\r");
Bongjun 10:6497effa1a26 102 DS18B20::ROM_Code_t ROM_Code;
Bongjun 10:6497effa1a26 103 sensor.ReadROM(&ROM_Code);
Bongjun 10:6497effa1a26 104 printf("Family code: 0x%X\n\r", ROM_Code.BYTES.familyCode);
Bongjun 10:6497effa1a26 105 printf("Serial Number: ");
Bongjun 10:6497effa1a26 106 for (unsigned i = 6; i != 0; --i) {
Bongjun 10:6497effa1a26 107 printf("%02X%s", ROM_Code.BYTES.serialNo[i-1], (i != 1)?":":"\r\n");
Bongjun 10:6497effa1a26 108 }
Bongjun 10:6497effa1a26 109 printf("CRC: 0x%X\r\n", ROM_Code.BYTES.CRC);
Bongjun 10:6497effa1a26 110 /*
Bongjun 10:6497effa1a26 111 printf("\n\rRunning temperature conversion...\n\r");
Bongjun 10:6497effa1a26 112 while (1) {
Bongjun 10:6497effa1a26 113 printf("Temperature is: %.4fC\n\r", sensor.GetTemperature());
Bongjun 10:6497effa1a26 114 wait(10);
Bongjun 10:6497effa1a26 115 }
Bongjun 10:6497effa1a26 116 */
Bongjun 10:6497effa1a26 117 #endif
lz307 6:3c44af154da8 118
lz307 6:3c44af154da8 119 xi_feed_t feed;
lz307 6:3c44af154da8 120 memset( &feed, NULL, sizeof( xi_feed_t ) );
lz307 6:3c44af154da8 121
lz307 6:3c44af154da8 122 feed.feed_id = XI_FEED_ID;
lz307 6:3c44af154da8 123 feed.datastream_count = 1;
samux 0:90ba0f51aa64 124
lz307 6:3c44af154da8 125 feed.datastreams[0].datapoint_count = 1;
lz307 6:3c44af154da8 126 xi_datastream_t* orientation_datastream = &feed.datastreams[0];
Bongjun 7:5ce11b80fb04 127 strcpy( orientation_datastream->datastream_id, "Channel_Test1" );
lz307 6:3c44af154da8 128 xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0];
lz307 6:3c44af154da8 129
lz307 6:3c44af154da8 130 // create the cosm library context
lz307 6:3c44af154da8 131 xi_context_t* xi_context
lz307 6:3c44af154da8 132 = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
lz307 6:3c44af154da8 133
lz307 6:3c44af154da8 134 // check if everything works
lz307 6:3c44af154da8 135 if( xi_context == NULL ) {
lz307 6:3c44af154da8 136 return -1;
lz307 6:3c44af154da8 137 }
lz307 6:3c44af154da8 138
lz307 6:3c44af154da8 139 while(1) {
Bongjun 10:6497effa1a26 140 #ifdef _SENSOR // if there is sensor.
Bongjun 10:6497effa1a26 141 /*
Bongjun 7:5ce11b80fb04 142 if (sensor_cnt) {
Bongjun 7:5ce11b80fb04 143 result = sensor.startReading(true); // start sensor readings and wait
Bongjun 7:5ce11b80fb04 144 if (result == DS18X20_OK) {
Bongjun 7:5ce11b80fb04 145 sensor.getReading(sensorBuf, 0); // get result into buf
Bongjun 7:5ce11b80fb04 146 xi_set_value_str( current_orientation, sensorBuf );
Bongjun 7:5ce11b80fb04 147 }
Bongjun 7:5ce11b80fb04 148 else
Bongjun 7:5ce11b80fb04 149 {
Bongjun 7:5ce11b80fb04 150 xi_set_value_str( current_orientation, "0" );
Bongjun 7:5ce11b80fb04 151 }
Bongjun 7:5ce11b80fb04 152
Bongjun 7:5ce11b80fb04 153 } else {
Bongjun 7:5ce11b80fb04 154 printf("No Sensor");
Bongjun 7:5ce11b80fb04 155 }
Bongjun 10:6497effa1a26 156 */
Bongjun 10:6497effa1a26 157 // use New library for DS18B20
Bongjun 10:6497effa1a26 158 sprintf(sensorBuf,"%4.2f", sensor.GetTemperature());
Bongjun 10:6497effa1a26 159 xi_set_value_str( current_orientation, sensorBuf );
Bongjun 10:6497effa1a26 160
Bongjun 10:6497effa1a26 161 #else
Bongjun 10:6497effa1a26 162 xi_set_value_str( current_orientation, "27" );
Bongjun 10:6497effa1a26 163 #endif
Bongjun 7:5ce11b80fb04 164
Bongjun 8:a0edf4bce160 165 printf( "update..." );
lz307 6:3c44af154da8 166 // send to xively server
lz307 6:3c44af154da8 167 xi_feed_update( xi_context, &feed );
lz307 6:3c44af154da8 168 printf( "done...\n" );
Bongjun 13:ab5db87a253a 169 wait( 5.0 );
lz307 6:3c44af154da8 170 }
lz307 6:3c44af154da8 171 }