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
Xively Demo
Board Pic
LPC11U68 + WIZ550io (WIZnet) + DS18B20 Temp Sensor
PC Screenshot
main.cpp@6:3c44af154da8, 2013-11-09 (annotated)
- Committer:
- lz307
- Date:
- Sat Nov 09 01:02:05 2013 +0000
- Revision:
- 6:3c44af154da8
- Parent:
- 5:867d16e948eb
- Child:
- 7:5ce11b80fb04
Use the Seeed wifi shield and WiflyInterface to send the current time to the Xively Service.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:90ba0f51aa64 | 1 | #include "mbed.h" |
samux | 3:3b84102f022e | 2 | #include "WiflyInterface.h" |
lz307 | 6:3c44af154da8 | 3 | #include "xively.h" |
lz307 | 6:3c44af154da8 | 4 | #include "xi_err.h" |
lz307 | 6:3c44af154da8 | 5 | |
lz307 | 6:3c44af154da8 | 6 | #define XI_FEED_ID 273104668 // set Xively Feed ID (numerical, no quoutes) |
lz307 | 6:3c44af154da8 | 7 | #define XI_API_KEY "Your API Key" // set Xively API key (double-quoted string) |
samux | 1:49e1e9ed6e39 | 8 | |
samux | 1:49e1e9ed6e39 | 9 | Serial pc(USBTX, USBRX); |
samux | 1:49e1e9ed6e39 | 10 | |
samux | 1:49e1e9ed6e39 | 11 | /* wifly object where: |
samux | 1:49e1e9ed6e39 | 12 | * - p9 and p10 are for the serial communication |
samux | 3:3b84102f022e | 13 | * - p25 is for the reset pin |
samux | 3:3b84102f022e | 14 | * - p26 is for the connection status |
samux | 1:49e1e9ed6e39 | 15 | * - "mbed" is the ssid of the network |
samux | 1:49e1e9ed6e39 | 16 | * - "password" is the password |
samux | 5:867d16e948eb | 17 | * - WPA is the security |
samux | 1:49e1e9ed6e39 | 18 | */ |
lz307 | 6:3c44af154da8 | 19 | WiflyInterface eth(p9, p10, p25, p26, "ssid", "passwd", WPA); |
lz307 | 6:3c44af154da8 | 20 | |
lz307 | 6:3c44af154da8 | 21 | int main() |
lz307 | 6:3c44af154da8 | 22 | { |
lz307 | 6:3c44af154da8 | 23 | int s = eth.init(); //Use DHCP |
lz307 | 6:3c44af154da8 | 24 | |
lz307 | 6:3c44af154da8 | 25 | if( s != NULL ) { |
lz307 | 6:3c44af154da8 | 26 | printf( "Could not initialise. Will halt!\n" ); |
lz307 | 6:3c44af154da8 | 27 | exit( 0 ); |
lz307 | 6:3c44af154da8 | 28 | } |
lz307 | 6:3c44af154da8 | 29 | |
lz307 | 6:3c44af154da8 | 30 | s = eth.connect(); |
lz307 | 6:3c44af154da8 | 31 | |
lz307 | 6:3c44af154da8 | 32 | if( s == false ) { |
lz307 | 6:3c44af154da8 | 33 | printf( "Could not connect. Will halt!\n" ); |
lz307 | 6:3c44af154da8 | 34 | exit( 0 ); |
lz307 | 6:3c44af154da8 | 35 | } else { |
lz307 | 6:3c44af154da8 | 36 | printf( "IP: %s\n", eth.getIPAddress() ); |
lz307 | 6:3c44af154da8 | 37 | } |
lz307 | 6:3c44af154da8 | 38 | |
lz307 | 6:3c44af154da8 | 39 | xi_feed_t feed; |
lz307 | 6:3c44af154da8 | 40 | memset( &feed, NULL, sizeof( xi_feed_t ) ); |
lz307 | 6:3c44af154da8 | 41 | |
lz307 | 6:3c44af154da8 | 42 | feed.feed_id = XI_FEED_ID; |
lz307 | 6:3c44af154da8 | 43 | feed.datastream_count = 1; |
samux | 0:90ba0f51aa64 | 44 | |
lz307 | 6:3c44af154da8 | 45 | feed.datastreams[0].datapoint_count = 1; |
lz307 | 6:3c44af154da8 | 46 | xi_datastream_t* orientation_datastream = &feed.datastreams[0]; |
lz307 | 6:3c44af154da8 | 47 | strcpy( orientation_datastream->datastream_id, "orientation" ); |
lz307 | 6:3c44af154da8 | 48 | xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0]; |
lz307 | 6:3c44af154da8 | 49 | |
lz307 | 6:3c44af154da8 | 50 | // create the cosm library context |
lz307 | 6:3c44af154da8 | 51 | xi_context_t* xi_context |
lz307 | 6:3c44af154da8 | 52 | = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id ); |
lz307 | 6:3c44af154da8 | 53 | |
lz307 | 6:3c44af154da8 | 54 | // check if everything works |
lz307 | 6:3c44af154da8 | 55 | if( xi_context == NULL ) { |
lz307 | 6:3c44af154da8 | 56 | return -1; |
lz307 | 6:3c44af154da8 | 57 | } |
lz307 | 6:3c44af154da8 | 58 | |
lz307 | 6:3c44af154da8 | 59 | while(1) { |
lz307 | 6:3c44af154da8 | 60 | time_t seconds = time(NULL); |
lz307 | 6:3c44af154da8 | 61 | char buffer[32]; |
lz307 | 6:3c44af154da8 | 62 | // get the current time |
lz307 | 6:3c44af154da8 | 63 | strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
lz307 | 6:3c44af154da8 | 64 | xi_set_value_str( current_orientation, buffer ); |
lz307 | 6:3c44af154da8 | 65 | printf( "update...\n" ); |
lz307 | 6:3c44af154da8 | 66 | // send to xively server |
lz307 | 6:3c44af154da8 | 67 | xi_feed_update( xi_context, &feed ); |
lz307 | 6:3c44af154da8 | 68 | printf( "done...\n" ); |
lz307 | 6:3c44af154da8 | 69 | wait( 1.0 ); |
lz307 | 6:3c44af154da8 | 70 | } |
lz307 | 6:3c44af154da8 | 71 | } |