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@9:c5dc85d192e2, 2013-10-14 (annotated)
- Committer:
- Ilya Dmitrichenko
- Date:
- Mon Oct 14 11:58:41 2013 +0100
- Revision:
- 9:c5dc85d192e2
- Parent:
- 8:81743e1228a7
- Child:
- 10:86ffba646df1
Add user config header as it's now required
(see https://github.com/xively/libxively/issues/51)
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 |
| xively | 7:0eff5db44b8b | 5 | #define XI_API_KEY "T4KXAH_dasgw1PWBPc3fdsfsdgsdy-dUc4ND0g" // set Xively API key (double-quoted string) |
| xively | 7:0eff5db44b8b | 6 | |
| xively | 0:efdea27c3b81 | 7 | #include "xively.h" |
| xively | 0:efdea27c3b81 | 8 | #include "xi_err.h" |
| xively | 0:efdea27c3b81 | 9 | |
| xively | 0:efdea27c3b81 | 10 | MMA7660 axl(p28, p27); |
| xively | 3:7ad3f6543b6e | 11 | LM75B tmp(p28, p27); |
| xively | 0:efdea27c3b81 | 12 | |
| xively | 0:efdea27c3b81 | 13 | int main() { |
| xively | 0:efdea27c3b81 | 14 | |
| xively | 0:efdea27c3b81 | 15 | EthernetInterface eth; |
| xively | 0:efdea27c3b81 | 16 | |
| xively | 0:efdea27c3b81 | 17 | int s = eth.init(); //Use DHCP |
| xively | 0:efdea27c3b81 | 18 | |
| xively | 0:efdea27c3b81 | 19 | if( s != NULL ) |
| xively | 0:efdea27c3b81 | 20 | { |
| xively | 7:0eff5db44b8b | 21 | lcd_printf( "Could not initialise. Will halt!\n" ); |
| xively | 0:efdea27c3b81 | 22 | exit( 0 ); |
| xively | 0:efdea27c3b81 | 23 | } |
| xively | 0:efdea27c3b81 | 24 | |
| xively | 0:efdea27c3b81 | 25 | s = eth.connect(); |
| xively | 0:efdea27c3b81 | 26 | |
| xively | 0:efdea27c3b81 | 27 | if( s != NULL ) |
| xively | 0:efdea27c3b81 | 28 | { |
| xively | 7:0eff5db44b8b | 29 | lcd_printf( "Could not connect. Will halt!\n" ); |
| xively | 0:efdea27c3b81 | 30 | exit( 0 ); |
| xively | 0:efdea27c3b81 | 31 | } |
| xively | 0:efdea27c3b81 | 32 | else |
| xively | 0:efdea27c3b81 | 33 | { |
| xively | 7:0eff5db44b8b | 34 | lcd_printf( "IP: %s\n", eth.getIPAddress() ); |
| xively | 0:efdea27c3b81 | 35 | } |
| xively | 0:efdea27c3b81 | 36 | |
| xively | 0:efdea27c3b81 | 37 | xi_feed_t feed; |
| xively | 0:efdea27c3b81 | 38 | memset( &feed, NULL, sizeof( xi_feed_t ) ); |
| xively | 0:efdea27c3b81 | 39 | |
| xively | 0:efdea27c3b81 | 40 | feed.feed_id = XI_FEED_ID; |
| xively | 3:7ad3f6543b6e | 41 | feed.datastream_count = 3; |
| xively | 0:efdea27c3b81 | 42 | |
| xively | 0:efdea27c3b81 | 43 | feed.datastreams[0].datapoint_count = 1; |
| xively | 0:efdea27c3b81 | 44 | xi_datastream_t* orientation_datastream = &feed.datastreams[0]; |
| xively | 0:efdea27c3b81 | 45 | strcpy( orientation_datastream->datastream_id, "orientation" ); |
| xively | 0:efdea27c3b81 | 46 | xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0]; |
| xively | 0:efdea27c3b81 | 47 | |
| xively | 0:efdea27c3b81 | 48 | feed.datastreams[1].datapoint_count = 1; |
| xively | 0:efdea27c3b81 | 49 | xi_datastream_t* side_rotation_datastream = &feed.datastreams[1]; |
| xively | 0:efdea27c3b81 | 50 | strcpy( side_rotation_datastream->datastream_id, "side_rotation" ); |
| xively | 0:efdea27c3b81 | 51 | xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0]; |
| xively | 0:efdea27c3b81 | 52 | |
| xively | 3:7ad3f6543b6e | 53 | feed.datastreams[2].datapoint_count = 1; |
| xively | 3:7ad3f6543b6e | 54 | xi_datastream_t* temperature_datastream = &feed.datastreams[2]; |
| xively | 3:7ad3f6543b6e | 55 | strcpy( temperature_datastream->datastream_id, "temperature" ); |
| xively | 3:7ad3f6543b6e | 56 | xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0]; |
| xively | 3:7ad3f6543b6e | 57 | |
| xively | 0:efdea27c3b81 | 58 | // create the cosm library context |
| xively | 0:efdea27c3b81 | 59 | xi_context_t* xi_context |
| xively | 0:efdea27c3b81 | 60 | = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id ); |
| xively | 0:efdea27c3b81 | 61 | |
| xively | 0:efdea27c3b81 | 62 | // check if everything works |
| xively | 0:efdea27c3b81 | 63 | if( xi_context == NULL ) |
| xively | 0:efdea27c3b81 | 64 | { |
| xively | 0:efdea27c3b81 | 65 | return -1; |
| xively | 0:efdea27c3b81 | 66 | } |
| xively | 0:efdea27c3b81 | 67 | |
| xively | 7:0eff5db44b8b | 68 | lcd_printf("feed:%d datastreams:[%s,%s]\n", feed.feed_id, |
| xively | 0:efdea27c3b81 | 69 | orientation_datastream->datastream_id, |
| xively | 0:efdea27c3b81 | 70 | side_rotation_datastream->datastream_id); |
| xively | 0:efdea27c3b81 | 71 | |
| xively | 0:efdea27c3b81 | 72 | while(1) { |
| xively | 0:efdea27c3b81 | 73 | |
| xively | 0:efdea27c3b81 | 74 | switch( axl.getSide() ) { |
| xively | 0:efdea27c3b81 | 75 | case MMA7660::Front: |
| xively | 0:efdea27c3b81 | 76 | xi_set_value_str( current_side_rotation, "front" ); |
| xively | 0:efdea27c3b81 | 77 | break; |
| xively | 0:efdea27c3b81 | 78 | case MMA7660::Back: |
| xively | 0:efdea27c3b81 | 79 | xi_set_value_str( current_side_rotation, "back" ); |
| xively | 0:efdea27c3b81 | 80 | break; |
| xively | 0:efdea27c3b81 | 81 | default: |
| xively | 0:efdea27c3b81 | 82 | xi_set_value_str( current_side_rotation, "unknown" ); |
| xively | 0:efdea27c3b81 | 83 | break; |
| xively | 0:efdea27c3b81 | 84 | } |
| xively | 0:efdea27c3b81 | 85 | |
| xively | 0:efdea27c3b81 | 86 | switch( axl.getOrientation() ) { |
| xively | 0:efdea27c3b81 | 87 | case MMA7660::Down: |
| xively | 7:0eff5db44b8b | 88 | lcd_printf("down %s\n", |
| xively | 0:efdea27c3b81 | 89 | (axl.getSide() == MMA7660::Front ? "front" : "back")); |
| xively | 0:efdea27c3b81 | 90 | xi_set_value_str( current_orientation, "down" ); |
| xively | 0:efdea27c3b81 | 91 | break; |
| xively | 0:efdea27c3b81 | 92 | case MMA7660::Up: |
| xively | 7:0eff5db44b8b | 93 | lcd_printf("up %s\n", |
| xively | 0:efdea27c3b81 | 94 | (axl.getSide() == MMA7660::Front ? "front" : "back")); |
| xively | 0:efdea27c3b81 | 95 | xi_set_value_str( current_orientation, "up" ); |
| xively | 0:efdea27c3b81 | 96 | break; |
| xively | 0:efdea27c3b81 | 97 | case MMA7660::Right: |
| xively | 7:0eff5db44b8b | 98 | lcd_printf("right %s\n", |
| xively | 0:efdea27c3b81 | 99 | (axl.getSide() == MMA7660::Front ? "front" : "back")); |
| xively | 0:efdea27c3b81 | 100 | xi_set_value_str( current_orientation, "right" ); |
| xively | 0:efdea27c3b81 | 101 | break; |
| xively | 0:efdea27c3b81 | 102 | case MMA7660::Left: |
| xively | 7:0eff5db44b8b | 103 | lcd_printf("left %s\n", |
| xively | 0:efdea27c3b81 | 104 | (axl.getSide() == MMA7660::Front ? "front" : "back")); |
| xively | 0:efdea27c3b81 | 105 | xi_set_value_str( current_orientation, "left" ); |
| xively | 0:efdea27c3b81 | 106 | break; |
| xively | 0:efdea27c3b81 | 107 | default: |
| xively | 0:efdea27c3b81 | 108 | xi_set_value_str( current_orientation, "unknown" ); |
| xively | 0:efdea27c3b81 | 109 | break; |
| xively | 0:efdea27c3b81 | 110 | } |
| xively | 3:7ad3f6543b6e | 111 | |
| xively | 3:7ad3f6543b6e | 112 | xi_set_value_f32( current_temperature, tmp.read() ); |
| xively | 4:e7ca62a11595 | 113 | |
| xively | 7:0eff5db44b8b | 114 | lcd_printf( "update...\n" ); |
| xively | 0:efdea27c3b81 | 115 | xi_feed_update(xi_context, &feed); |
| xively | 7:0eff5db44b8b | 116 | lcd_printf( "done...\n" ); |
| xively | 3:7ad3f6543b6e | 117 | |
| xively | 3:7ad3f6543b6e | 118 | wait( 15.0 ); |
| xively | 0:efdea27c3b81 | 119 | } |
| Ilya Dmitrichenko |
6:9e4f4a8c1829 | 120 | } |
Austin Blackstone
