
demo of the murata wifi chip. This demo tries to connect to an open wifi access point and prints out all the relevant information about the connection. It then scans all wifi access points nearby and reports their information.
Dependencies: SNICInterface mbed-rtos mbed
Fork of SNIC-xively-jumpstart-demo by
main.cpp@11:bdf601a405fc, 2013-10-14 (annotated)
- Committer:
- errordeveloper
- Date:
- Mon Oct 14 13:33:04 2013 +0000
- Revision:
- 11:bdf601a405fc
- Parent:
- 10:86ffba646df1
- Child:
- 12:27471bb09274
- Child:
- 14:6d58d3855feb
Improve a few things about the LCD output:; ; * don't output debug logs; * show Xively logo on boot;
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 | |
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; |
errordeveloper | 11:bdf601a405fc | 19 | |
errordeveloper | 11:bdf601a405fc | 20 | #include "logo.h" |
xively | 0:efdea27c3b81 | 21 | |
xively | 0:efdea27c3b81 | 22 | int main() { |
errordeveloper | 11:bdf601a405fc | 23 | lcd_print_xively_logo(); |
xively | 0:efdea27c3b81 | 24 | EthernetInterface eth; |
xively | 0:efdea27c3b81 | 25 | |
xively | 0:efdea27c3b81 | 26 | int s = eth.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 | |
xively | 0:efdea27c3b81 | 34 | s = eth.connect(); |
xively | 0:efdea27c3b81 | 35 | |
xively | 0:efdea27c3b81 | 36 | if( s != NULL ) |
xively | 0:efdea27c3b81 | 37 | { |
xively | 7:0eff5db44b8b | 38 | lcd_printf( "Could not connect. Will halt!\n" ); |
xively | 0:efdea27c3b81 | 39 | exit( 0 ); |
xively | 0:efdea27c3b81 | 40 | } |
xively | 0:efdea27c3b81 | 41 | else |
xively | 0:efdea27c3b81 | 42 | { |
xively | 7:0eff5db44b8b | 43 | lcd_printf( "IP: %s\n", eth.getIPAddress() ); |
xively | 0:efdea27c3b81 | 44 | } |
xively | 0:efdea27c3b81 | 45 | |
xively | 0:efdea27c3b81 | 46 | xi_feed_t feed; |
xively | 0:efdea27c3b81 | 47 | memset( &feed, NULL, sizeof( xi_feed_t ) ); |
xively | 0:efdea27c3b81 | 48 | |
xively | 0:efdea27c3b81 | 49 | feed.feed_id = XI_FEED_ID; |
xively | 3:7ad3f6543b6e | 50 | feed.datastream_count = 3; |
xively | 0:efdea27c3b81 | 51 | |
xively | 0:efdea27c3b81 | 52 | feed.datastreams[0].datapoint_count = 1; |
xively | 0:efdea27c3b81 | 53 | xi_datastream_t* orientation_datastream = &feed.datastreams[0]; |
xively | 0:efdea27c3b81 | 54 | strcpy( orientation_datastream->datastream_id, "orientation" ); |
xively | 0:efdea27c3b81 | 55 | xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0]; |
xively | 0:efdea27c3b81 | 56 | |
xively | 0:efdea27c3b81 | 57 | feed.datastreams[1].datapoint_count = 1; |
xively | 0:efdea27c3b81 | 58 | xi_datastream_t* side_rotation_datastream = &feed.datastreams[1]; |
xively | 0:efdea27c3b81 | 59 | strcpy( side_rotation_datastream->datastream_id, "side_rotation" ); |
xively | 0:efdea27c3b81 | 60 | xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0]; |
xively | 0:efdea27c3b81 | 61 | |
xively | 3:7ad3f6543b6e | 62 | feed.datastreams[2].datapoint_count = 1; |
xively | 3:7ad3f6543b6e | 63 | xi_datastream_t* temperature_datastream = &feed.datastreams[2]; |
xively | 3:7ad3f6543b6e | 64 | strcpy( temperature_datastream->datastream_id, "temperature" ); |
xively | 3:7ad3f6543b6e | 65 | xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0]; |
xively | 3:7ad3f6543b6e | 66 | |
xively | 0:efdea27c3b81 | 67 | // create the cosm library context |
xively | 0:efdea27c3b81 | 68 | xi_context_t* xi_context |
xively | 0:efdea27c3b81 | 69 | = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id ); |
xively | 0:efdea27c3b81 | 70 | |
xively | 0:efdea27c3b81 | 71 | // check if everything works |
xively | 0:efdea27c3b81 | 72 | if( xi_context == NULL ) |
xively | 0:efdea27c3b81 | 73 | { |
xively | 0:efdea27c3b81 | 74 | return -1; |
xively | 0:efdea27c3b81 | 75 | } |
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 | 0:efdea27c3b81 | 93 | xi_set_value_str( current_orientation, "down" ); |
xively | 0:efdea27c3b81 | 94 | break; |
xively | 0:efdea27c3b81 | 95 | case MMA7660::Up: |
xively | 0:efdea27c3b81 | 96 | xi_set_value_str( current_orientation, "up" ); |
xively | 0:efdea27c3b81 | 97 | break; |
xively | 0:efdea27c3b81 | 98 | case MMA7660::Right: |
xively | 0:efdea27c3b81 | 99 | xi_set_value_str( current_orientation, "right" ); |
xively | 0:efdea27c3b81 | 100 | break; |
xively | 0:efdea27c3b81 | 101 | case MMA7660::Left: |
xively | 0:efdea27c3b81 | 102 | xi_set_value_str( current_orientation, "left" ); |
xively | 0:efdea27c3b81 | 103 | break; |
xively | 0:efdea27c3b81 | 104 | default: |
xively | 0:efdea27c3b81 | 105 | xi_set_value_str( current_orientation, "unknown" ); |
xively | 0:efdea27c3b81 | 106 | break; |
xively | 0:efdea27c3b81 | 107 | } |
xively | 3:7ad3f6543b6e | 108 | |
xively | 3:7ad3f6543b6e | 109 | xi_set_value_f32( current_temperature, tmp.read() ); |
xively | 4:e7ca62a11595 | 110 | |
xively | 7:0eff5db44b8b | 111 | lcd_printf( "update...\n" ); |
errordeveloper | 11:bdf601a405fc | 112 | xi_feed_update( xi_context, &feed ); |
xively | 7:0eff5db44b8b | 113 | lcd_printf( "done...\n" ); |
xively | 3:7ad3f6543b6e | 114 | |
xively | 3:7ad3f6543b6e | 115 | wait( 15.0 ); |
xively | 0:efdea27c3b81 | 116 | } |
Ilya Dmitrichenko |
6:9e4f4a8c1829 | 117 | } |