"led" numerical variable is pushed out from Xively. It is received and printed by mbed. You can edit the number in Xively.

Dependencies:   C12832_lcd EthernetInterface LM75B MMA7660 mbed-libxively-6eca970 mbed-rtos mbed

Fork of Application-xively-jumpstart-demo by avnish aggarwal

Committer:
xively
Date:
Wed Jun 26 11:54:06 2013 +0000
Revision:
4:e7ca62a11595
Parent:
3:7ad3f6543b6e
Child:
6:9af362ececc4
Added temperature datastream and sleep of 15.0

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 0:efdea27c3b81 3 #include "xively.h"
xively 0:efdea27c3b81 4 #include "xi_err.h"
xively 0:efdea27c3b81 5 #include "xi_printf.h"
xively 0:efdea27c3b81 6
xively 0:efdea27c3b81 7 #include <stdarg.h>
xively 0:efdea27c3b81 8 #include <stdio.h>
xively 0:efdea27c3b81 9
xively 0:efdea27c3b81 10 #include "MMA7660.h"
xively 3:7ad3f6543b6e 11 #include "LM75B.h"
xively 0:efdea27c3b81 12
xively 4:e7ca62a11595 13 #define XI_FEED_ID 123 // set Xively Feed ID (numerical, no quoutes
xively 4:e7ca62a11595 14 #define XI_API_KEY "T4KXAH_dasgw1PWBPc3fdsfsdgsdy-dUc4ND0g" // set Xively API key (double-quoted string)
xively 0:efdea27c3b81 15
xively 0:efdea27c3b81 16 #include "C12832_lcd.h"
xively 0:efdea27c3b81 17
xively 0:efdea27c3b81 18 C12832_LCD lcd;
xively 0:efdea27c3b81 19
xively 0:efdea27c3b81 20 MMA7660 axl(p28, p27);
xively 3:7ad3f6543b6e 21 LM75B tmp(p28, p27);
xively 0:efdea27c3b81 22
xively 0:efdea27c3b81 23 extern "C" {
xively 0:efdea27c3b81 24
xively 0:efdea27c3b81 25 void user_printf( const char* buffer )
xively 0:efdea27c3b81 26 {
xively 0:efdea27c3b81 27 lcd.cls();
xively 0:efdea27c3b81 28 lcd.locate( 0, 3 );
xively 0:efdea27c3b81 29 lcd.printf( buffer );
xively 0:efdea27c3b81 30 //wait( 1.0 );
xively 0:efdea27c3b81 31 }
xively 0:efdea27c3b81 32
xively 0:efdea27c3b81 33 void mbed_printf( const char* fmt, ... )
xively 0:efdea27c3b81 34 {
xively 0:efdea27c3b81 35 char buffer[ 64 ];
xively 0:efdea27c3b81 36
xively 0:efdea27c3b81 37 va_list ap;
xively 0:efdea27c3b81 38 va_start( ap, fmt );
xively 0:efdea27c3b81 39 vsnprintf( buffer, 64, fmt, ap );
xively 0:efdea27c3b81 40 va_end( ap );
xively 0:efdea27c3b81 41
xively 0:efdea27c3b81 42 user_printf( buffer );
xively 0:efdea27c3b81 43 }
xively 0:efdea27c3b81 44
xively 0:efdea27c3b81 45 }
xively 0:efdea27c3b81 46
xively 0:efdea27c3b81 47 int main() {
xively 0:efdea27c3b81 48 // set our device specific print function
xively 0:efdea27c3b81 49 USER_PRINT = user_printf;
xively 0:efdea27c3b81 50
xively 0:efdea27c3b81 51 EthernetInterface eth;
xively 0:efdea27c3b81 52
xively 0:efdea27c3b81 53 int s = eth.init(); //Use DHCP
xively 0:efdea27c3b81 54
xively 0:efdea27c3b81 55 if( s != NULL )
xively 0:efdea27c3b81 56 {
xively 0:efdea27c3b81 57 mbed_printf( "Could not initialise. Will halt!\n" );
xively 0:efdea27c3b81 58 exit( 0 );
xively 0:efdea27c3b81 59 }
xively 0:efdea27c3b81 60
xively 0:efdea27c3b81 61 s = eth.connect();
xively 0:efdea27c3b81 62
xively 0:efdea27c3b81 63 if( s != NULL )
xively 0:efdea27c3b81 64 {
xively 0:efdea27c3b81 65 mbed_printf( "Could not connect. Will halt!\n" );
xively 0:efdea27c3b81 66 exit( 0 );
xively 0:efdea27c3b81 67 }
xively 0:efdea27c3b81 68 else
xively 0:efdea27c3b81 69 {
xively 0:efdea27c3b81 70 mbed_printf( "IP: %s\n", eth.getIPAddress() );
xively 0:efdea27c3b81 71 }
xively 0:efdea27c3b81 72
xively 0:efdea27c3b81 73 xi_feed_t feed;
xively 0:efdea27c3b81 74 memset( &feed, NULL, sizeof( xi_feed_t ) );
xively 0:efdea27c3b81 75
xively 0:efdea27c3b81 76 feed.feed_id = XI_FEED_ID;
xively 3:7ad3f6543b6e 77 feed.datastream_count = 3;
xively 0:efdea27c3b81 78
xively 0:efdea27c3b81 79 feed.datastreams[0].datapoint_count = 1;
xively 0:efdea27c3b81 80 xi_datastream_t* orientation_datastream = &feed.datastreams[0];
xively 0:efdea27c3b81 81 strcpy( orientation_datastream->datastream_id, "orientation" );
xively 0:efdea27c3b81 82 xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0];
xively 0:efdea27c3b81 83
xively 0:efdea27c3b81 84 feed.datastreams[1].datapoint_count = 1;
xively 0:efdea27c3b81 85 xi_datastream_t* side_rotation_datastream = &feed.datastreams[1];
xively 0:efdea27c3b81 86 strcpy( side_rotation_datastream->datastream_id, "side_rotation" );
xively 0:efdea27c3b81 87 xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0];
xively 0:efdea27c3b81 88
xively 3:7ad3f6543b6e 89 feed.datastreams[2].datapoint_count = 1;
xively 3:7ad3f6543b6e 90 xi_datastream_t* temperature_datastream = &feed.datastreams[2];
xively 3:7ad3f6543b6e 91 strcpy( temperature_datastream->datastream_id, "temperature" );
xively 3:7ad3f6543b6e 92 xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0];
xively 3:7ad3f6543b6e 93
xively 0:efdea27c3b81 94 // create the cosm library context
xively 0:efdea27c3b81 95 xi_context_t* xi_context
xively 0:efdea27c3b81 96 = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
xively 0:efdea27c3b81 97
xively 0:efdea27c3b81 98 // check if everything works
xively 0:efdea27c3b81 99 if( xi_context == NULL )
xively 0:efdea27c3b81 100 {
xively 0:efdea27c3b81 101 return -1;
xively 0:efdea27c3b81 102 }
xively 0:efdea27c3b81 103
xively 0:efdea27c3b81 104 mbed_printf("feed:%d datastreams:[%s,%s]\n", feed.feed_id,
xively 0:efdea27c3b81 105 orientation_datastream->datastream_id,
xively 0:efdea27c3b81 106 side_rotation_datastream->datastream_id);
xively 0:efdea27c3b81 107
xively 0:efdea27c3b81 108 while(1) {
xively 0:efdea27c3b81 109
xively 0:efdea27c3b81 110 switch( axl.getSide() ) {
xively 0:efdea27c3b81 111 case MMA7660::Front:
xively 0:efdea27c3b81 112 xi_set_value_str( current_side_rotation, "front" );
xively 0:efdea27c3b81 113 break;
xively 0:efdea27c3b81 114 case MMA7660::Back:
xively 0:efdea27c3b81 115 xi_set_value_str( current_side_rotation, "back" );
xively 0:efdea27c3b81 116 break;
xively 0:efdea27c3b81 117 default:
xively 0:efdea27c3b81 118 xi_set_value_str( current_side_rotation, "unknown" );
xively 0:efdea27c3b81 119 break;
xively 0:efdea27c3b81 120 }
xively 0:efdea27c3b81 121
xively 0:efdea27c3b81 122 switch( axl.getOrientation() ) {
xively 0:efdea27c3b81 123 case MMA7660::Down:
xively 0:efdea27c3b81 124 mbed_printf("down %s\n",
xively 0:efdea27c3b81 125 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 126 xi_set_value_str( current_orientation, "down" );
xively 0:efdea27c3b81 127 break;
xively 0:efdea27c3b81 128 case MMA7660::Up:
xively 0:efdea27c3b81 129 mbed_printf("up %s\n",
xively 0:efdea27c3b81 130 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 131 xi_set_value_str( current_orientation, "up" );
xively 0:efdea27c3b81 132 break;
xively 0:efdea27c3b81 133 case MMA7660::Right:
xively 0:efdea27c3b81 134 mbed_printf("right %s\n",
xively 0:efdea27c3b81 135 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 136 xi_set_value_str( current_orientation, "right" );
xively 0:efdea27c3b81 137 break;
xively 0:efdea27c3b81 138 case MMA7660::Left:
xively 0:efdea27c3b81 139 mbed_printf("left %s\n",
xively 0:efdea27c3b81 140 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 141 xi_set_value_str( current_orientation, "left" );
xively 0:efdea27c3b81 142 break;
xively 0:efdea27c3b81 143 default:
xively 0:efdea27c3b81 144 xi_set_value_str( current_orientation, "unknown" );
xively 0:efdea27c3b81 145 break;
xively 0:efdea27c3b81 146 }
xively 3:7ad3f6543b6e 147
xively 3:7ad3f6543b6e 148 xi_set_value_f32( current_temperature, tmp.read() );
xively 4:e7ca62a11595 149
xively 0:efdea27c3b81 150 mbed_printf( "update...\n" );
xively 0:efdea27c3b81 151 xi_feed_update(xi_context, &feed);
xively 0:efdea27c3b81 152 mbed_printf( "done...\n" );
xively 3:7ad3f6543b6e 153
xively 3:7ad3f6543b6e 154 wait( 15.0 );
xively 0:efdea27c3b81 155 }
xively 0:efdea27c3b81 156 }