"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:
thomas_sullivan
Date:
Sat May 31 23:37:01 2014 +0000
Revision:
7:ce814bb26bd1
Parent:
6:9af362ececc4
An updated version of Avnish's Xively jumpstart.  The fourth numerical variable "led" is pushed out from Xively and printed by mbed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
avnisha 6:9af362ececc4 1 #define ETHERNET
avnisha 6:9af362ececc4 2
avnisha 6:9af362ececc4 3 #ifdef WIFLY
avnisha 6:9af362ececc4 4 #include "mbed.h"
avnisha 6:9af362ececc4 5 #include "WiflyInterface.h"
avnisha 6:9af362ececc4 6
avnisha 6:9af362ececc4 7 Serial pc(USBTX, USBRX);
avnisha 6:9af362ececc4 8
avnisha 6:9af362ececc4 9 /* wifly object where:
avnisha 6:9af362ececc4 10 * - p9 and p10 are for the serial communication
avnisha 6:9af362ececc4 11 * - p25 is for the reset pin
avnisha 6:9af362ececc4 12 * - p26 is for the connection status
avnisha 6:9af362ececc4 13 * - "mbed" is the ssid of the network
avnisha 6:9af362ececc4 14 * - "password" is the password
avnisha 6:9af362ececc4 15 * - WPA is the security
avnisha 6:9af362ececc4 16 */
avnisha 6:9af362ececc4 17 WiflyInterface wifly(p9, p10, p25, p26, "bubbles", "", NONE);
avnisha 6:9af362ececc4 18
avnisha 6:9af362ececc4 19 int main() {
avnisha 6:9af362ececc4 20 printf("hello\n\r");
avnisha 6:9af362ececc4 21 wifly.init(); // use DHCP
avnisha 6:9af362ececc4 22 while (!wifly.connect()); // join the network
avnisha 6:9af362ececc4 23 printf("IP Address is %s\n\r", wifly.getIPAddress());
avnisha 6:9af362ececc4 24 while (1) {}
avnisha 6:9af362ececc4 25 wifly.disconnect();
avnisha 6:9af362ececc4 26 }
avnisha 6:9af362ececc4 27
avnisha 6:9af362ececc4 28 #endif
avnisha 6:9af362ececc4 29
xively 0:efdea27c3b81 30 #include "mbed.h"
xively 0:efdea27c3b81 31 #include "EthernetInterface.h"
xively 0:efdea27c3b81 32 #include "xively.h"
xively 0:efdea27c3b81 33 #include "xi_err.h"
xively 0:efdea27c3b81 34 #include "xi_printf.h"
xively 0:efdea27c3b81 35
avnisha 6:9af362ececc4 36 #ifdef WIFLY
avnisha 6:9af362ececc4 37 #include "WiflyInterface.h"
avnisha 6:9af362ececc4 38
avnisha 6:9af362ececc4 39 Serial pc(USBTX, USBRX);
avnisha 6:9af362ececc4 40
avnisha 6:9af362ececc4 41 /* wifly object where:
avnisha 6:9af362ececc4 42 * - p9 and p10 are for the serial communication
avnisha 6:9af362ececc4 43 * - p25 is for the reset pin
avnisha 6:9af362ececc4 44 * - p26 is for the connection status
avnisha 6:9af362ececc4 45 * - "mbed" is the ssid of the network
avnisha 6:9af362ececc4 46 * - "password" is the password
avnisha 6:9af362ececc4 47 * - WPA is the security
avnisha 6:9af362ececc4 48 */
avnisha 6:9af362ececc4 49 WiflyInterface wifly(p9, p10, p25, p26, "bubbles", "", NONE);
avnisha 6:9af362ececc4 50 #endif
avnisha 6:9af362ececc4 51
xively 0:efdea27c3b81 52 #include <stdarg.h>
xively 0:efdea27c3b81 53 #include <stdio.h>
xively 0:efdea27c3b81 54
xively 0:efdea27c3b81 55 #include "MMA7660.h"
xively 3:7ad3f6543b6e 56 #include "LM75B.h"
xively 0:efdea27c3b81 57
avnisha 6:9af362ececc4 58 // 332668647
avnisha 6:9af362ececc4 59 // ZmCG3GmfnJzvt1LZnLdHfS9D5vlfNrXQSxKD1jpzqsAsp3bh
thomas_sullivan 7:ce814bb26bd1 60 #define XI_FEED_ID 442300006 // set Xively Feed ID (numerical, no quoutes
thomas_sullivan 7:ce814bb26bd1 61 #define XI_API_KEY "FvameuMiutLFm5O135FCYEQn6okK8gijbsjPXTcSYARgkCYv" // set Xively API key (double-quoted string)
xively 0:efdea27c3b81 62
xively 0:efdea27c3b81 63 #include "C12832_lcd.h"
xively 0:efdea27c3b81 64
xively 0:efdea27c3b81 65 C12832_LCD lcd;
xively 0:efdea27c3b81 66
xively 0:efdea27c3b81 67 MMA7660 axl(p28, p27);
xively 3:7ad3f6543b6e 68 LM75B tmp(p28, p27);
xively 0:efdea27c3b81 69
xively 0:efdea27c3b81 70 extern "C" {
xively 0:efdea27c3b81 71
xively 0:efdea27c3b81 72 void user_printf( const char* buffer )
xively 0:efdea27c3b81 73 {
xively 0:efdea27c3b81 74 lcd.cls();
xively 0:efdea27c3b81 75 lcd.locate( 0, 3 );
xively 0:efdea27c3b81 76 lcd.printf( buffer );
xively 0:efdea27c3b81 77 //wait( 1.0 );
xively 0:efdea27c3b81 78 }
xively 0:efdea27c3b81 79
xively 0:efdea27c3b81 80 void mbed_printf( const char* fmt, ... )
xively 0:efdea27c3b81 81 {
xively 0:efdea27c3b81 82 char buffer[ 64 ];
xively 0:efdea27c3b81 83
xively 0:efdea27c3b81 84 va_list ap;
xively 0:efdea27c3b81 85 va_start( ap, fmt );
xively 0:efdea27c3b81 86 vsnprintf( buffer, 64, fmt, ap );
xively 0:efdea27c3b81 87 va_end( ap );
xively 0:efdea27c3b81 88
xively 0:efdea27c3b81 89 user_printf( buffer );
xively 0:efdea27c3b81 90 }
xively 0:efdea27c3b81 91
xively 0:efdea27c3b81 92 }
xively 0:efdea27c3b81 93
xively 0:efdea27c3b81 94 int main() {
xively 0:efdea27c3b81 95 // set our device specific print function
xively 0:efdea27c3b81 96 USER_PRINT = user_printf;
avnisha 6:9af362ececc4 97
avnisha 6:9af362ececc4 98 #ifdef ETHERNET
xively 0:efdea27c3b81 99 EthernetInterface eth;
xively 0:efdea27c3b81 100
xively 0:efdea27c3b81 101 int s = eth.init(); //Use DHCP
xively 0:efdea27c3b81 102
xively 0:efdea27c3b81 103 if( s != NULL )
xively 0:efdea27c3b81 104 {
xively 0:efdea27c3b81 105 mbed_printf( "Could not initialise. Will halt!\n" );
xively 0:efdea27c3b81 106 exit( 0 );
xively 0:efdea27c3b81 107 }
xively 0:efdea27c3b81 108
xively 0:efdea27c3b81 109 s = eth.connect();
xively 0:efdea27c3b81 110
xively 0:efdea27c3b81 111 if( s != NULL )
xively 0:efdea27c3b81 112 {
xively 0:efdea27c3b81 113 mbed_printf( "Could not connect. Will halt!\n" );
xively 0:efdea27c3b81 114 exit( 0 );
xively 0:efdea27c3b81 115 }
xively 0:efdea27c3b81 116 else
xively 0:efdea27c3b81 117 {
xively 0:efdea27c3b81 118 mbed_printf( "IP: %s\n", eth.getIPAddress() );
xively 0:efdea27c3b81 119 }
avnisha 6:9af362ececc4 120 #else
avnisha 6:9af362ececc4 121 wifly.init(); // use DHCP
avnisha 6:9af362ececc4 122 while (!wifly.connect()); // join the network
avnisha 6:9af362ececc4 123 printf("IP Address is %s\n\r", wifly.getIPAddress());
avnisha 6:9af362ececc4 124 #endif
avnisha 6:9af362ececc4 125
xively 0:efdea27c3b81 126 xi_feed_t feed;
xively 0:efdea27c3b81 127 memset( &feed, NULL, sizeof( xi_feed_t ) );
xively 0:efdea27c3b81 128
xively 0:efdea27c3b81 129 feed.feed_id = XI_FEED_ID;
thomas_sullivan 7:ce814bb26bd1 130 feed.datastream_count = 4;
xively 0:efdea27c3b81 131
xively 0:efdea27c3b81 132 feed.datastreams[0].datapoint_count = 1;
xively 0:efdea27c3b81 133 xi_datastream_t* orientation_datastream = &feed.datastreams[0];
xively 0:efdea27c3b81 134 strcpy( orientation_datastream->datastream_id, "orientation" );
xively 0:efdea27c3b81 135 xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0];
xively 0:efdea27c3b81 136
xively 0:efdea27c3b81 137 feed.datastreams[1].datapoint_count = 1;
xively 0:efdea27c3b81 138 xi_datastream_t* side_rotation_datastream = &feed.datastreams[1];
xively 0:efdea27c3b81 139 strcpy( side_rotation_datastream->datastream_id, "side_rotation" );
xively 0:efdea27c3b81 140 xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0];
xively 0:efdea27c3b81 141
xively 3:7ad3f6543b6e 142 feed.datastreams[2].datapoint_count = 1;
xively 3:7ad3f6543b6e 143 xi_datastream_t* temperature_datastream = &feed.datastreams[2];
xively 3:7ad3f6543b6e 144 strcpy( temperature_datastream->datastream_id, "temperature" );
xively 3:7ad3f6543b6e 145 xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0];
xively 3:7ad3f6543b6e 146
thomas_sullivan 7:ce814bb26bd1 147 feed.datastreams[3].datapoint_count = 1;
thomas_sullivan 7:ce814bb26bd1 148 xi_datastream_t* led_datastream = &feed.datastreams[3];
thomas_sullivan 7:ce814bb26bd1 149 strcpy( led_datastream->datastream_id, "led" );
thomas_sullivan 7:ce814bb26bd1 150 xi_datapoint_t* current_led = &led_datastream->datapoints[0];
thomas_sullivan 7:ce814bb26bd1 151
xively 0:efdea27c3b81 152 // create the cosm library context
xively 0:efdea27c3b81 153 xi_context_t* xi_context
xively 0:efdea27c3b81 154 = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
xively 0:efdea27c3b81 155
xively 0:efdea27c3b81 156 // check if everything works
xively 0:efdea27c3b81 157 if( xi_context == NULL )
xively 0:efdea27c3b81 158 {
xively 0:efdea27c3b81 159 return -1;
xively 0:efdea27c3b81 160 }
xively 0:efdea27c3b81 161
xively 0:efdea27c3b81 162 mbed_printf("feed:%d datastreams:[%s,%s]\n", feed.feed_id,
xively 0:efdea27c3b81 163 orientation_datastream->datastream_id,
xively 0:efdea27c3b81 164 side_rotation_datastream->datastream_id);
xively 0:efdea27c3b81 165
xively 0:efdea27c3b81 166 while(1) {
xively 0:efdea27c3b81 167
xively 0:efdea27c3b81 168 switch( axl.getSide() ) {
xively 0:efdea27c3b81 169 case MMA7660::Front:
xively 0:efdea27c3b81 170 xi_set_value_str( current_side_rotation, "front" );
xively 0:efdea27c3b81 171 break;
xively 0:efdea27c3b81 172 case MMA7660::Back:
xively 0:efdea27c3b81 173 xi_set_value_str( current_side_rotation, "back" );
xively 0:efdea27c3b81 174 break;
xively 0:efdea27c3b81 175 default:
xively 0:efdea27c3b81 176 xi_set_value_str( current_side_rotation, "unknown" );
xively 0:efdea27c3b81 177 break;
xively 0:efdea27c3b81 178 }
xively 0:efdea27c3b81 179
xively 0:efdea27c3b81 180 switch( axl.getOrientation() ) {
xively 0:efdea27c3b81 181 case MMA7660::Down:
xively 0:efdea27c3b81 182 mbed_printf("down %s\n",
xively 0:efdea27c3b81 183 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 184 xi_set_value_str( current_orientation, "down" );
xively 0:efdea27c3b81 185 break;
xively 0:efdea27c3b81 186 case MMA7660::Up:
xively 0:efdea27c3b81 187 mbed_printf("up %s\n",
xively 0:efdea27c3b81 188 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 189 xi_set_value_str( current_orientation, "up" );
xively 0:efdea27c3b81 190 break;
xively 0:efdea27c3b81 191 case MMA7660::Right:
xively 0:efdea27c3b81 192 mbed_printf("right %s\n",
xively 0:efdea27c3b81 193 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 194 xi_set_value_str( current_orientation, "right" );
xively 0:efdea27c3b81 195 break;
xively 0:efdea27c3b81 196 case MMA7660::Left:
xively 0:efdea27c3b81 197 mbed_printf("left %s\n",
xively 0:efdea27c3b81 198 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 199 xi_set_value_str( current_orientation, "left" );
xively 0:efdea27c3b81 200 break;
xively 0:efdea27c3b81 201 default:
xively 0:efdea27c3b81 202 xi_set_value_str( current_orientation, "unknown" );
xively 0:efdea27c3b81 203 break;
xively 0:efdea27c3b81 204 }
xively 3:7ad3f6543b6e 205
xively 3:7ad3f6543b6e 206 xi_set_value_f32( current_temperature, tmp.read() );
xively 4:e7ca62a11595 207
xively 0:efdea27c3b81 208 mbed_printf( "update...\n" );
xively 0:efdea27c3b81 209 xi_feed_update(xi_context, &feed);
thomas_sullivan 7:ce814bb26bd1 210 //xi_response_t myInData;
thomas_sullivan 7:ce814bb26bd1 211 //myInData = xi_feed_get(xi_context, &feed);
thomas_sullivan 7:ce814bb26bd1 212 xi_datastream_get(xi_context, feed.feed_id, led_datastream->datastream_id, led_datastream->datapoints);
thomas_sullivan 7:ce814bb26bd1 213 mbed_printf( "%d...\n",led_datastream->datapoints[0]);
xively 3:7ad3f6543b6e 214
thomas_sullivan 7:ce814bb26bd1 215 extern const xi_response_t* xi_datastream_get(xi_context_t* xi, int32_t feed_id
thomas_sullivan 7:ce814bb26bd1 216 , const char * datastream_id, xi_datapoint_t* dp );
thomas_sullivan 7:ce814bb26bd1 217
thomas_sullivan 7:ce814bb26bd1 218 wait( 5.0 );
xively 0:efdea27c3b81 219 }
xively 0:efdea27c3b81 220 }