Send email to gmail(trigger)

Dependencies:   C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed

Fork of xively-jumpstart-demo by Xively Official

Committer:
bhakti08
Date:
Tue Jun 03 04:07:27 2014 +0000
Revision:
14:e32799a15720
Parent:
11:bdf601a405fc
Send email to gmail

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xively 0:efdea27c3b81 1 #include "mbed.h"
xively 0:efdea27c3b81 2 #include "EthernetInterface.h"
xively 7:0eff5db44b8b 3
bhakti08 14:e32799a15720 4 #define XI_FEED_ID 1443794017 // set Xively Feed ID (numerical, no quoutes)
bhakti08 14:e32799a15720 5 #define XI_API_KEY "iydtzKtHKHNpc4mQqq5Quv8jhi5nMwg6EKXSN6UkspZcXTrI" // 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);
bhakti08 14:e32799a15720 17 //LM75B tmp(p28, p27);
bhakti08 14:e32799a15720 18 AnalogIn tmp(p19);
errordeveloper 11:bdf601a405fc 19 C12832_LCD lcd;
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 EthernetInterface eth;
xively 0:efdea27c3b81 26
xively 0:efdea27c3b81 27 int s = eth.init(); //Use DHCP
xively 0:efdea27c3b81 28
xively 0:efdea27c3b81 29 if( s != NULL )
xively 0:efdea27c3b81 30 {
xively 7:0eff5db44b8b 31 lcd_printf( "Could not initialise. Will halt!\n" );
xively 0:efdea27c3b81 32 exit( 0 );
xively 0:efdea27c3b81 33 }
xively 0:efdea27c3b81 34
xively 0:efdea27c3b81 35 s = eth.connect();
xively 0:efdea27c3b81 36
xively 0:efdea27c3b81 37 if( s != NULL )
xively 0:efdea27c3b81 38 {
xively 7:0eff5db44b8b 39 lcd_printf( "Could not connect. Will halt!\n" );
xively 0:efdea27c3b81 40 exit( 0 );
xively 0:efdea27c3b81 41 }
xively 0:efdea27c3b81 42 else
xively 0:efdea27c3b81 43 {
xively 7:0eff5db44b8b 44 lcd_printf( "IP: %s\n", eth.getIPAddress() );
xively 0:efdea27c3b81 45 }
xively 0:efdea27c3b81 46
xively 0:efdea27c3b81 47 xi_feed_t feed;
xively 0:efdea27c3b81 48 memset( &feed, NULL, sizeof( xi_feed_t ) );
xively 0:efdea27c3b81 49
xively 0:efdea27c3b81 50 feed.feed_id = XI_FEED_ID;
xively 3:7ad3f6543b6e 51 feed.datastream_count = 3;
xively 0:efdea27c3b81 52
xively 0:efdea27c3b81 53 feed.datastreams[0].datapoint_count = 1;
xively 0:efdea27c3b81 54 xi_datastream_t* orientation_datastream = &feed.datastreams[0];
xively 0:efdea27c3b81 55 strcpy( orientation_datastream->datastream_id, "orientation" );
xively 0:efdea27c3b81 56 xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0];
xively 0:efdea27c3b81 57
xively 0:efdea27c3b81 58 feed.datastreams[1].datapoint_count = 1;
xively 0:efdea27c3b81 59 xi_datastream_t* side_rotation_datastream = &feed.datastreams[1];
xively 0:efdea27c3b81 60 strcpy( side_rotation_datastream->datastream_id, "side_rotation" );
xively 0:efdea27c3b81 61 xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0];
xively 0:efdea27c3b81 62
xively 3:7ad3f6543b6e 63 feed.datastreams[2].datapoint_count = 1;
xively 3:7ad3f6543b6e 64 xi_datastream_t* temperature_datastream = &feed.datastreams[2];
xively 3:7ad3f6543b6e 65 strcpy( temperature_datastream->datastream_id, "temperature" );
xively 3:7ad3f6543b6e 66 xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0];
xively 3:7ad3f6543b6e 67
xively 0:efdea27c3b81 68 // create the cosm library context
xively 0:efdea27c3b81 69 xi_context_t* xi_context
xively 0:efdea27c3b81 70 = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
xively 0:efdea27c3b81 71
xively 0:efdea27c3b81 72 // check if everything works
xively 0:efdea27c3b81 73 if( xi_context == NULL )
xively 0:efdea27c3b81 74 {
xively 0:efdea27c3b81 75 return -1;
xively 0:efdea27c3b81 76 }
xively 0:efdea27c3b81 77
xively 0:efdea27c3b81 78 while(1) {
xively 0:efdea27c3b81 79
xively 0:efdea27c3b81 80 switch( axl.getSide() ) {
xively 0:efdea27c3b81 81 case MMA7660::Front:
xively 0:efdea27c3b81 82 xi_set_value_str( current_side_rotation, "front" );
xively 0:efdea27c3b81 83 break;
xively 0:efdea27c3b81 84 case MMA7660::Back:
xively 0:efdea27c3b81 85 xi_set_value_str( current_side_rotation, "back" );
xively 0:efdea27c3b81 86 break;
xively 0:efdea27c3b81 87 default:
xively 0:efdea27c3b81 88 xi_set_value_str( current_side_rotation, "unknown" );
xively 0:efdea27c3b81 89 break;
xively 0:efdea27c3b81 90 }
xively 0:efdea27c3b81 91
xively 0:efdea27c3b81 92 switch( axl.getOrientation() ) {
xively 0:efdea27c3b81 93 case MMA7660::Down:
xively 0:efdea27c3b81 94 xi_set_value_str( current_orientation, "down" );
xively 0:efdea27c3b81 95 break;
xively 0:efdea27c3b81 96 case MMA7660::Up:
xively 0:efdea27c3b81 97 xi_set_value_str( current_orientation, "up" );
xively 0:efdea27c3b81 98 break;
xively 0:efdea27c3b81 99 case MMA7660::Right:
xively 0:efdea27c3b81 100 xi_set_value_str( current_orientation, "right" );
xively 0:efdea27c3b81 101 break;
xively 0:efdea27c3b81 102 case MMA7660::Left:
xively 0:efdea27c3b81 103 xi_set_value_str( current_orientation, "left" );
xively 0:efdea27c3b81 104 break;
xively 0:efdea27c3b81 105 default:
xively 0:efdea27c3b81 106 xi_set_value_str( current_orientation, "unknown" );
xively 0:efdea27c3b81 107 break;
xively 0:efdea27c3b81 108 }
xively 3:7ad3f6543b6e 109
xively 3:7ad3f6543b6e 110 xi_set_value_f32( current_temperature, tmp.read() );
xively 4:e7ca62a11595 111
xively 7:0eff5db44b8b 112 lcd_printf( "update...\n" );
errordeveloper 11:bdf601a405fc 113 xi_feed_update( xi_context, &feed );
xively 7:0eff5db44b8b 114 lcd_printf( "done...\n" );
xively 3:7ad3f6543b6e 115
bhakti08 14:e32799a15720 116 wait( 10.0 );
xively 0:efdea27c3b81 117 }
Ilya Dmitrichenko 6:9e4f4a8c1829 118 }