Xively Jumpstart Demo with WiFly module
Dependencies: C12832_lcd LM75B MMA7660 WiflyInterface libxively mbed-rtos mbed
Deprecated
This is an mbed 2 example. For an mbed-os WiFi example, see:
[Repository '/teams/mbed-os-examples/code/mbed-os-example-wifi/docs/tip/' not found]
main.cpp@13:b5092350e231, 2014-01-28 (annotated)
- Committer:
- MACRUM
- Date:
- Tue Jan 28 04:50:18 2014 +0000
- Revision:
- 13:b5092350e231
- Parent:
- 12:e07c2779c6fb
Fixed build error for old library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xively | 0:efdea27c3b81 | 1 | #include "mbed.h" |
MACRUM | 12:e07c2779c6fb | 2 | #include "WiflyInterface.h" |
xively | 7:0eff5db44b8b | 3 | |
errordeveloper | 11:bdf601a405fc | 4 | #define XI_FEED_ID 128488 // set Xively Feed ID (numerical, no quoutes) |
errordeveloper | 10:86ffba646df1 | 5 | #define XI_API_KEY "T4KXAH_dasgw1PWBPc3fdsfsdgsdy-dUc4ND0g" // set Xively API key (double-quoted string) |
errordeveloper | 10:86ffba646df1 | 6 | |
errordeveloper | 10:86ffba646df1 | 7 | #include "app_board_io.h" |
xively | 7:0eff5db44b8b | 8 | |
xively | 0:efdea27c3b81 | 9 | #include "xively.h" |
xively | 0:efdea27c3b81 | 10 | #include "xi_err.h" |
xively | 0:efdea27c3b81 | 11 | |
errordeveloper | 10:86ffba646df1 | 12 | #include "MMA7660.h" |
errordeveloper | 10:86ffba646df1 | 13 | #include "LM75B.h" |
errordeveloper | 11:bdf601a405fc | 14 | #include "C12832_lcd.h" |
errordeveloper | 10:86ffba646df1 | 15 | |
xively | 0:efdea27c3b81 | 16 | MMA7660 axl(p28, p27); |
xively | 3:7ad3f6543b6e | 17 | LM75B tmp(p28, p27); |
errordeveloper | 11:bdf601a405fc | 18 | C12832_LCD lcd; |
MACRUM | 12:e07c2779c6fb | 19 | WiflyInterface wifly(p9, p10, p30, p29, "ssid", "password", WPA); |
errordeveloper | 11:bdf601a405fc | 20 | |
errordeveloper | 11:bdf601a405fc | 21 | #include "logo.h" |
xively | 0:efdea27c3b81 | 22 | |
xively | 0:efdea27c3b81 | 23 | int main() { |
errordeveloper | 11:bdf601a405fc | 24 | lcd_print_xively_logo(); |
xively | 0:efdea27c3b81 | 25 | |
MACRUM | 12:e07c2779c6fb | 26 | int s = wifly.init(); //Use DHCP |
xively | 0:efdea27c3b81 | 27 | |
xively | 0:efdea27c3b81 | 28 | if( s != NULL ) |
xively | 0:efdea27c3b81 | 29 | { |
xively | 7:0eff5db44b8b | 30 | lcd_printf( "Could not initialise. Will halt!\n" ); |
xively | 0:efdea27c3b81 | 31 | exit( 0 ); |
xively | 0:efdea27c3b81 | 32 | } |
xively | 0:efdea27c3b81 | 33 | |
MACRUM | 12:e07c2779c6fb | 34 | while(!wifly.connect()) |
MACRUM | 12:e07c2779c6fb | 35 | ; |
xively | 0:efdea27c3b81 | 36 | |
MACRUM | 12:e07c2779c6fb | 37 | lcd_printf( "IP: %s\n", wifly.getIPAddress() ); |
xively | 0:efdea27c3b81 | 38 | |
xively | 0:efdea27c3b81 | 39 | xi_feed_t feed; |
xively | 0:efdea27c3b81 | 40 | memset( &feed, NULL, sizeof( xi_feed_t ) ); |
xively | 0:efdea27c3b81 | 41 | |
xively | 0:efdea27c3b81 | 42 | feed.feed_id = XI_FEED_ID; |
xively | 3:7ad3f6543b6e | 43 | feed.datastream_count = 3; |
xively | 0:efdea27c3b81 | 44 | |
xively | 0:efdea27c3b81 | 45 | feed.datastreams[0].datapoint_count = 1; |
xively | 0:efdea27c3b81 | 46 | xi_datastream_t* orientation_datastream = &feed.datastreams[0]; |
xively | 0:efdea27c3b81 | 47 | strcpy( orientation_datastream->datastream_id, "orientation" ); |
xively | 0:efdea27c3b81 | 48 | xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0]; |
xively | 0:efdea27c3b81 | 49 | |
xively | 0:efdea27c3b81 | 50 | feed.datastreams[1].datapoint_count = 1; |
xively | 0:efdea27c3b81 | 51 | xi_datastream_t* side_rotation_datastream = &feed.datastreams[1]; |
xively | 0:efdea27c3b81 | 52 | strcpy( side_rotation_datastream->datastream_id, "side_rotation" ); |
xively | 0:efdea27c3b81 | 53 | xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0]; |
xively | 0:efdea27c3b81 | 54 | |
xively | 3:7ad3f6543b6e | 55 | feed.datastreams[2].datapoint_count = 1; |
xively | 3:7ad3f6543b6e | 56 | xi_datastream_t* temperature_datastream = &feed.datastreams[2]; |
xively | 3:7ad3f6543b6e | 57 | strcpy( temperature_datastream->datastream_id, "temperature" ); |
xively | 3:7ad3f6543b6e | 58 | xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0]; |
xively | 3:7ad3f6543b6e | 59 | |
xively | 0:efdea27c3b81 | 60 | // create the cosm library context |
xively | 0:efdea27c3b81 | 61 | xi_context_t* xi_context |
xively | 0:efdea27c3b81 | 62 | = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id ); |
xively | 0:efdea27c3b81 | 63 | |
xively | 0:efdea27c3b81 | 64 | // check if everything works |
xively | 0:efdea27c3b81 | 65 | if( xi_context == NULL ) |
xively | 0:efdea27c3b81 | 66 | { |
xively | 0:efdea27c3b81 | 67 | return -1; |
xively | 0:efdea27c3b81 | 68 | } |
xively | 0:efdea27c3b81 | 69 | |
xively | 0:efdea27c3b81 | 70 | while(1) { |
xively | 0:efdea27c3b81 | 71 | |
xively | 0:efdea27c3b81 | 72 | switch( axl.getSide() ) { |
xively | 0:efdea27c3b81 | 73 | case MMA7660::Front: |
xively | 0:efdea27c3b81 | 74 | xi_set_value_str( current_side_rotation, "front" ); |
xively | 0:efdea27c3b81 | 75 | break; |
xively | 0:efdea27c3b81 | 76 | case MMA7660::Back: |
xively | 0:efdea27c3b81 | 77 | xi_set_value_str( current_side_rotation, "back" ); |
xively | 0:efdea27c3b81 | 78 | break; |
xively | 0:efdea27c3b81 | 79 | default: |
xively | 0:efdea27c3b81 | 80 | xi_set_value_str( current_side_rotation, "unknown" ); |
xively | 0:efdea27c3b81 | 81 | break; |
xively | 0:efdea27c3b81 | 82 | } |
xively | 0:efdea27c3b81 | 83 | |
xively | 0:efdea27c3b81 | 84 | switch( axl.getOrientation() ) { |
xively | 0:efdea27c3b81 | 85 | case MMA7660::Down: |
xively | 0:efdea27c3b81 | 86 | xi_set_value_str( current_orientation, "down" ); |
xively | 0:efdea27c3b81 | 87 | break; |
xively | 0:efdea27c3b81 | 88 | case MMA7660::Up: |
xively | 0:efdea27c3b81 | 89 | xi_set_value_str( current_orientation, "up" ); |
xively | 0:efdea27c3b81 | 90 | break; |
xively | 0:efdea27c3b81 | 91 | case MMA7660::Right: |
xively | 0:efdea27c3b81 | 92 | xi_set_value_str( current_orientation, "right" ); |
xively | 0:efdea27c3b81 | 93 | break; |
xively | 0:efdea27c3b81 | 94 | case MMA7660::Left: |
xively | 0:efdea27c3b81 | 95 | xi_set_value_str( current_orientation, "left" ); |
xively | 0:efdea27c3b81 | 96 | break; |
xively | 0:efdea27c3b81 | 97 | default: |
xively | 0:efdea27c3b81 | 98 | xi_set_value_str( current_orientation, "unknown" ); |
xively | 0:efdea27c3b81 | 99 | break; |
xively | 0:efdea27c3b81 | 100 | } |
xively | 3:7ad3f6543b6e | 101 | |
xively | 3:7ad3f6543b6e | 102 | xi_set_value_f32( current_temperature, tmp.read() ); |
xively | 4:e7ca62a11595 | 103 | |
xively | 7:0eff5db44b8b | 104 | lcd_printf( "update...\n" ); |
errordeveloper | 11:bdf601a405fc | 105 | xi_feed_update( xi_context, &feed ); |
xively | 7:0eff5db44b8b | 106 | lcd_printf( "done...\n" ); |
xively | 3:7ad3f6543b6e | 107 | |
MACRUM | 12:e07c2779c6fb | 108 | wait( 1.0 ); |
xively | 0:efdea27c3b81 | 109 | } |
Ilya Dmitrichenko |
6:9e4f4a8c1829 | 110 | } |