Dreameforce 2013 giveaway demo
Dependencies: C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed
Fork of xively-dreamforce by
main.cpp@10:86ffba646df1, 2013-10-14 (annotated)
- Committer:
- errordeveloper
- Date:
- Mon Oct 14 12:08:18 2013 +0000
- Revision:
- 10:86ffba646df1
- Parent:
- 9:c5dc85d192e2
- Child:
- 11:bdf601a405fc
Updated all dependencies and fixed issue with mixing C and C++
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xively | 0:efdea27c3b81 | 1 | #include "mbed.h" |
xively | 0:efdea27c3b81 | 2 | #include "EthernetInterface.h" |
xively | 7:0eff5db44b8b | 3 | |
xively | 7:0eff5db44b8b | 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 | 10:86ffba646df1 | 14 | |
xively | 0:efdea27c3b81 | 15 | MMA7660 axl(p28, p27); |
xively | 3:7ad3f6543b6e | 16 | LM75B tmp(p28, p27); |
xively | 0:efdea27c3b81 | 17 | |
xively | 0:efdea27c3b81 | 18 | int main() { |
xively | 0:efdea27c3b81 | 19 | |
xively | 0:efdea27c3b81 | 20 | EthernetInterface eth; |
xively | 0:efdea27c3b81 | 21 | |
xively | 0:efdea27c3b81 | 22 | int s = eth.init(); //Use DHCP |
xively | 0:efdea27c3b81 | 23 | |
xively | 0:efdea27c3b81 | 24 | if( s != NULL ) |
xively | 0:efdea27c3b81 | 25 | { |
xively | 7:0eff5db44b8b | 26 | lcd_printf( "Could not initialise. Will halt!\n" ); |
xively | 0:efdea27c3b81 | 27 | exit( 0 ); |
xively | 0:efdea27c3b81 | 28 | } |
xively | 0:efdea27c3b81 | 29 | |
xively | 0:efdea27c3b81 | 30 | s = eth.connect(); |
xively | 0:efdea27c3b81 | 31 | |
xively | 0:efdea27c3b81 | 32 | if( s != NULL ) |
xively | 0:efdea27c3b81 | 33 | { |
xively | 7:0eff5db44b8b | 34 | lcd_printf( "Could not connect. Will halt!\n" ); |
xively | 0:efdea27c3b81 | 35 | exit( 0 ); |
xively | 0:efdea27c3b81 | 36 | } |
xively | 0:efdea27c3b81 | 37 | else |
xively | 0:efdea27c3b81 | 38 | { |
xively | 7:0eff5db44b8b | 39 | lcd_printf( "IP: %s\n", eth.getIPAddress() ); |
xively | 0:efdea27c3b81 | 40 | } |
xively | 0:efdea27c3b81 | 41 | |
xively | 0:efdea27c3b81 | 42 | xi_feed_t feed; |
xively | 0:efdea27c3b81 | 43 | memset( &feed, NULL, sizeof( xi_feed_t ) ); |
xively | 0:efdea27c3b81 | 44 | |
xively | 0:efdea27c3b81 | 45 | feed.feed_id = XI_FEED_ID; |
xively | 3:7ad3f6543b6e | 46 | feed.datastream_count = 3; |
xively | 0:efdea27c3b81 | 47 | |
xively | 0:efdea27c3b81 | 48 | feed.datastreams[0].datapoint_count = 1; |
xively | 0:efdea27c3b81 | 49 | xi_datastream_t* orientation_datastream = &feed.datastreams[0]; |
xively | 0:efdea27c3b81 | 50 | strcpy( orientation_datastream->datastream_id, "orientation" ); |
xively | 0:efdea27c3b81 | 51 | xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0]; |
xively | 0:efdea27c3b81 | 52 | |
xively | 0:efdea27c3b81 | 53 | feed.datastreams[1].datapoint_count = 1; |
xively | 0:efdea27c3b81 | 54 | xi_datastream_t* side_rotation_datastream = &feed.datastreams[1]; |
xively | 0:efdea27c3b81 | 55 | strcpy( side_rotation_datastream->datastream_id, "side_rotation" ); |
xively | 0:efdea27c3b81 | 56 | xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0]; |
xively | 0:efdea27c3b81 | 57 | |
xively | 3:7ad3f6543b6e | 58 | feed.datastreams[2].datapoint_count = 1; |
xively | 3:7ad3f6543b6e | 59 | xi_datastream_t* temperature_datastream = &feed.datastreams[2]; |
xively | 3:7ad3f6543b6e | 60 | strcpy( temperature_datastream->datastream_id, "temperature" ); |
xively | 3:7ad3f6543b6e | 61 | xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0]; |
xively | 3:7ad3f6543b6e | 62 | |
xively | 0:efdea27c3b81 | 63 | // create the cosm library context |
xively | 0:efdea27c3b81 | 64 | xi_context_t* xi_context |
xively | 0:efdea27c3b81 | 65 | = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id ); |
xively | 0:efdea27c3b81 | 66 | |
xively | 0:efdea27c3b81 | 67 | // check if everything works |
xively | 0:efdea27c3b81 | 68 | if( xi_context == NULL ) |
xively | 0:efdea27c3b81 | 69 | { |
xively | 0:efdea27c3b81 | 70 | return -1; |
xively | 0:efdea27c3b81 | 71 | } |
xively | 0:efdea27c3b81 | 72 | |
xively | 7:0eff5db44b8b | 73 | lcd_printf("feed:%d datastreams:[%s,%s]\n", feed.feed_id, |
xively | 0:efdea27c3b81 | 74 | orientation_datastream->datastream_id, |
xively | 0:efdea27c3b81 | 75 | side_rotation_datastream->datastream_id); |
xively | 0:efdea27c3b81 | 76 | |
xively | 0:efdea27c3b81 | 77 | while(1) { |
xively | 0:efdea27c3b81 | 78 | |
xively | 0:efdea27c3b81 | 79 | switch( axl.getSide() ) { |
xively | 0:efdea27c3b81 | 80 | case MMA7660::Front: |
xively | 0:efdea27c3b81 | 81 | xi_set_value_str( current_side_rotation, "front" ); |
xively | 0:efdea27c3b81 | 82 | break; |
xively | 0:efdea27c3b81 | 83 | case MMA7660::Back: |
xively | 0:efdea27c3b81 | 84 | xi_set_value_str( current_side_rotation, "back" ); |
xively | 0:efdea27c3b81 | 85 | break; |
xively | 0:efdea27c3b81 | 86 | default: |
xively | 0:efdea27c3b81 | 87 | xi_set_value_str( current_side_rotation, "unknown" ); |
xively | 0:efdea27c3b81 | 88 | break; |
xively | 0:efdea27c3b81 | 89 | } |
xively | 0:efdea27c3b81 | 90 | |
xively | 0:efdea27c3b81 | 91 | switch( axl.getOrientation() ) { |
xively | 0:efdea27c3b81 | 92 | case MMA7660::Down: |
xively | 7:0eff5db44b8b | 93 | lcd_printf("down %s\n", |
xively | 0:efdea27c3b81 | 94 | (axl.getSide() == MMA7660::Front ? "front" : "back")); |
xively | 0:efdea27c3b81 | 95 | xi_set_value_str( current_orientation, "down" ); |
xively | 0:efdea27c3b81 | 96 | break; |
xively | 0:efdea27c3b81 | 97 | case MMA7660::Up: |
xively | 7:0eff5db44b8b | 98 | lcd_printf("up %s\n", |
xively | 0:efdea27c3b81 | 99 | (axl.getSide() == MMA7660::Front ? "front" : "back")); |
xively | 0:efdea27c3b81 | 100 | xi_set_value_str( current_orientation, "up" ); |
xively | 0:efdea27c3b81 | 101 | break; |
xively | 0:efdea27c3b81 | 102 | case MMA7660::Right: |
xively | 7:0eff5db44b8b | 103 | lcd_printf("right %s\n", |
xively | 0:efdea27c3b81 | 104 | (axl.getSide() == MMA7660::Front ? "front" : "back")); |
xively | 0:efdea27c3b81 | 105 | xi_set_value_str( current_orientation, "right" ); |
xively | 0:efdea27c3b81 | 106 | break; |
xively | 0:efdea27c3b81 | 107 | case MMA7660::Left: |
xively | 7:0eff5db44b8b | 108 | lcd_printf("left %s\n", |
xively | 0:efdea27c3b81 | 109 | (axl.getSide() == MMA7660::Front ? "front" : "back")); |
xively | 0:efdea27c3b81 | 110 | xi_set_value_str( current_orientation, "left" ); |
xively | 0:efdea27c3b81 | 111 | break; |
xively | 0:efdea27c3b81 | 112 | default: |
xively | 0:efdea27c3b81 | 113 | xi_set_value_str( current_orientation, "unknown" ); |
xively | 0:efdea27c3b81 | 114 | break; |
xively | 0:efdea27c3b81 | 115 | } |
xively | 3:7ad3f6543b6e | 116 | |
xively | 3:7ad3f6543b6e | 117 | xi_set_value_f32( current_temperature, tmp.read() ); |
xively | 4:e7ca62a11595 | 118 | |
xively | 7:0eff5db44b8b | 119 | lcd_printf( "update...\n" ); |
xively | 0:efdea27c3b81 | 120 | xi_feed_update(xi_context, &feed); |
xively | 7:0eff5db44b8b | 121 | lcd_printf( "done...\n" ); |
xively | 3:7ad3f6543b6e | 122 | |
xively | 3:7ad3f6543b6e | 123 | wait( 15.0 ); |
xively | 0:efdea27c3b81 | 124 | } |
Ilya Dmitrichenko |
6:9e4f4a8c1829 | 125 | } |