Dreameforce 2013 giveaway demo

Dependencies:   C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed

Fork of xively-dreamforce by Ilya Dmitrichenko

Committer:
errordeveloper
Date:
Fri Nov 08 16:44:46 2013 +0000
Revision:
12:27471bb09274
Parent:
11:bdf601a405fc
First prototype

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xively 0:efdea27c3b81 1 #include "mbed.h"
xively 7:0eff5db44b8b 2
errordeveloper 12:27471bb09274 3 #include "UbloxUSBCDMAModem.h"
errordeveloper 12:27471bb09274 4 #include "UbloxUSBGSMModem.h"
errordeveloper 12:27471bb09274 5 #define MODEM_UBLOX_CDMA // remove this if you are using GSM
errordeveloper 10:86ffba646df1 6
errordeveloper 12:27471bb09274 7 #define XI_FEED_ID 248 // set Xively Feed ID (numerical, no quoutes)
errordeveloper 12:27471bb09274 8 #define XI_API_KEY "T4KXAH_dasgw1PWBsfsdgy-dUc4ND0g" // set Xively API key (double-quoted string)
errordeveloper 12:27471bb09274 9
errordeveloper 12:27471bb09274 10 #include "cellular_board_io.h"
xively 7:0eff5db44b8b 11
xively 0:efdea27c3b81 12 #include "xively.h"
xively 0:efdea27c3b81 13 #include "xi_err.h"
xively 0:efdea27c3b81 14
errordeveloper 12:27471bb09274 15 int main() {
errordeveloper 11:bdf601a405fc 16
errordeveloper 12:27471bb09274 17 //TODO: maybe move these into board_io files and do it for app board ethernet version too...
errordeveloper 12:27471bb09274 18 #ifdef MODEM_UBLOX_CDMA
errordeveloper 12:27471bb09274 19 UbloxUSBCDMAModem modem(p18, true, 1);
errordeveloper 12:27471bb09274 20 #else
errordeveloper 12:27471bb09274 21 UbloxUSBGSMModem modem;
errordeveloper 12:27471bb09274 22 #endif
xively 0:efdea27c3b81 23
errordeveloper 12:27471bb09274 24 modem.power(true);
errordeveloper 12:27471bb09274 25 Thread::wait(1000);
errordeveloper 12:27471bb09274 26
errordeveloper 12:27471bb09274 27 int s = modem.connect(NULL, NULL, "internet");
xively 0:efdea27c3b81 28
errordeveloper 12:27471bb09274 29 if( s )
xively 0:efdea27c3b81 30 {
errordeveloper 12:27471bb09274 31 printf( "Could not connect to the Internet. Will halt!\r\n" );
xively 0:efdea27c3b81 32 exit( 0 );
xively 0:efdea27c3b81 33 }
xively 0:efdea27c3b81 34
xively 0:efdea27c3b81 35 xi_feed_t feed;
xively 0:efdea27c3b81 36 memset( &feed, NULL, sizeof( xi_feed_t ) );
xively 0:efdea27c3b81 37
xively 0:efdea27c3b81 38 feed.feed_id = XI_FEED_ID;
errordeveloper 12:27471bb09274 39 feed.datastream_count = 1;
xively 0:efdea27c3b81 40
xively 0:efdea27c3b81 41 feed.datastreams[0].datapoint_count = 1;
errordeveloper 12:27471bb09274 42 xi_datastream_t* counter_datastream = &feed.datastreams[0];
errordeveloper 12:27471bb09274 43 strcpy( counter_datastream->datastream_id, "counter" );
errordeveloper 12:27471bb09274 44 xi_datapoint_t* counter = &counter_datastream->datapoints[0];
xively 0:efdea27c3b81 45
errordeveloper 12:27471bb09274 46 //TODO:
errordeveloper 12:27471bb09274 47 //- figure out how got send `AT$DEBUG?` command and parse it's ouput which looks like:
errordeveloper 12:27471bb09274 48 // $DEBUG: 4183,233,100,1,99,-9,-105,2,2,2,93,261,429,186,249,438,21,63,63,63,63,63
errordeveloper 12:27471bb09274 49 // For details see docs: http://www.u-blox.com/images/downloads/Product_Docs/LISAC200-FW75C200_ATCommandsManual_%28CDMA-2X-11002%29.pdf)
errordeveloper 12:27471bb09274 50 // Some of these values represent varios interesting things, e.g. RSSI.
errordeveloper 12:27471bb09274 51 // We should put some of those into separate Xively datastreams...
xively 3:7ad3f6543b6e 52
xively 0:efdea27c3b81 53 // create the cosm library context
xively 0:efdea27c3b81 54 xi_context_t* xi_context
xively 0:efdea27c3b81 55 = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
xively 0:efdea27c3b81 56
xively 0:efdea27c3b81 57 // check if everything works
xively 0:efdea27c3b81 58 if( xi_context == NULL )
xively 0:efdea27c3b81 59 {
xively 0:efdea27c3b81 60 return -1;
xively 0:efdea27c3b81 61 }
errordeveloper 12:27471bb09274 62 long unsigned int c = 0;
xively 0:efdea27c3b81 63 while(1) {
xively 0:efdea27c3b81 64
errordeveloper 12:27471bb09274 65 xi_set_value_i32( counter, ++c );
errordeveloper 12:27471bb09274 66
errordeveloper 12:27471bb09274 67 printf( "Updating Xively feed %d...\r\n", XI_FEED_ID );
errordeveloper 12:27471bb09274 68 xi_feed_update( xi_context, &feed );
errordeveloper 12:27471bb09274 69 printf( " done!\r\n" ); //TODO: add error check, as cellular can be flaky.
xively 0:efdea27c3b81 70
errordeveloper 12:27471bb09274 71 wait( 50.0 );
xively 0:efdea27c3b81 72 }
Ilya Dmitrichenko 6:9e4f4a8c1829 73 }