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 Jul 14 06:49:43 2014 +0000
Revision:
10:6497effa1a26
Parent:
8:a0edf4bce160
Child:
13:ab5db87a253a
change DS18B20 Library.; and try "comile All", success

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