tst

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

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

Committer:
habibiam
Date:
Tue Jun 03 03:41:12 2014 +0000
Revision:
7:ffaea0d21d77
Parent:
6:9af362ececc4
test

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
habibiam 7:ffaea0d21d77 60 // #define XI_FEED_ID 332668647 // set Xively Feed ID (numerical, no quoutes
habibiam 7:ffaea0d21d77 61 #define XI_FEED_ID 580296092
habibiam 7:ffaea0d21d77 62 //#define XI_API_KEY "ZmCG3GmfnJzvt1LZnLdHfS9D5vlfNrXQSxKD1jpzqsAsp3bh" // set Xively API key (double-quoted string)
habibiam 7:ffaea0d21d77 63 #define XI_API_KEY "XfwL8x9W6zHc1cFA05SqL9SGOMC1mMzmvRjR0i6Exf5s2lqS"
xively 0:efdea27c3b81 64
xively 0:efdea27c3b81 65 #include "C12832_lcd.h"
xively 0:efdea27c3b81 66
xively 0:efdea27c3b81 67 C12832_LCD lcd;
xively 0:efdea27c3b81 68
xively 0:efdea27c3b81 69 MMA7660 axl(p28, p27);
xively 3:7ad3f6543b6e 70 LM75B tmp(p28, p27);
xively 0:efdea27c3b81 71
xively 0:efdea27c3b81 72 extern "C" {
xively 0:efdea27c3b81 73
xively 0:efdea27c3b81 74 void user_printf( const char* buffer )
xively 0:efdea27c3b81 75 {
xively 0:efdea27c3b81 76 lcd.cls();
xively 0:efdea27c3b81 77 lcd.locate( 0, 3 );
xively 0:efdea27c3b81 78 lcd.printf( buffer );
xively 0:efdea27c3b81 79 //wait( 1.0 );
xively 0:efdea27c3b81 80 }
xively 0:efdea27c3b81 81
xively 0:efdea27c3b81 82 void mbed_printf( const char* fmt, ... )
xively 0:efdea27c3b81 83 {
xively 0:efdea27c3b81 84 char buffer[ 64 ];
xively 0:efdea27c3b81 85
xively 0:efdea27c3b81 86 va_list ap;
xively 0:efdea27c3b81 87 va_start( ap, fmt );
xively 0:efdea27c3b81 88 vsnprintf( buffer, 64, fmt, ap );
xively 0:efdea27c3b81 89 va_end( ap );
xively 0:efdea27c3b81 90
xively 0:efdea27c3b81 91 user_printf( buffer );
xively 0:efdea27c3b81 92 }
xively 0:efdea27c3b81 93
xively 0:efdea27c3b81 94 }
xively 0:efdea27c3b81 95
xively 0:efdea27c3b81 96 int main() {
xively 0:efdea27c3b81 97 // set our device specific print function
xively 0:efdea27c3b81 98 USER_PRINT = user_printf;
avnisha 6:9af362ececc4 99
avnisha 6:9af362ececc4 100 #ifdef ETHERNET
xively 0:efdea27c3b81 101 EthernetInterface eth;
xively 0:efdea27c3b81 102
xively 0:efdea27c3b81 103 int s = eth.init(); //Use DHCP
xively 0:efdea27c3b81 104
xively 0:efdea27c3b81 105 if( s != NULL )
xively 0:efdea27c3b81 106 {
xively 0:efdea27c3b81 107 mbed_printf( "Could not initialise. Will halt!\n" );
xively 0:efdea27c3b81 108 exit( 0 );
xively 0:efdea27c3b81 109 }
xively 0:efdea27c3b81 110
xively 0:efdea27c3b81 111 s = eth.connect();
xively 0:efdea27c3b81 112
xively 0:efdea27c3b81 113 if( s != NULL )
xively 0:efdea27c3b81 114 {
xively 0:efdea27c3b81 115 mbed_printf( "Could not connect. Will halt!\n" );
xively 0:efdea27c3b81 116 exit( 0 );
xively 0:efdea27c3b81 117 }
xively 0:efdea27c3b81 118 else
xively 0:efdea27c3b81 119 {
xively 0:efdea27c3b81 120 mbed_printf( "IP: %s\n", eth.getIPAddress() );
xively 0:efdea27c3b81 121 }
avnisha 6:9af362ececc4 122 #else
avnisha 6:9af362ececc4 123 wifly.init(); // use DHCP
avnisha 6:9af362ececc4 124 while (!wifly.connect()); // join the network
avnisha 6:9af362ececc4 125 printf("IP Address is %s\n\r", wifly.getIPAddress());
avnisha 6:9af362ececc4 126 #endif
avnisha 6:9af362ececc4 127
xively 0:efdea27c3b81 128 xi_feed_t feed;
xively 0:efdea27c3b81 129 memset( &feed, NULL, sizeof( xi_feed_t ) );
xively 0:efdea27c3b81 130
xively 0:efdea27c3b81 131 feed.feed_id = XI_FEED_ID;
habibiam 7:ffaea0d21d77 132 // feed.datastream_count = 3; //
habibiam 7:ffaea0d21d77 133 feed.datastream_count = 4;
xively 0:efdea27c3b81 134 feed.datastreams[0].datapoint_count = 1;
xively 0:efdea27c3b81 135 xi_datastream_t* orientation_datastream = &feed.datastreams[0];
xively 0:efdea27c3b81 136 strcpy( orientation_datastream->datastream_id, "orientation" );
xively 0:efdea27c3b81 137 xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0];
xively 0:efdea27c3b81 138
xively 0:efdea27c3b81 139 feed.datastreams[1].datapoint_count = 1;
xively 0:efdea27c3b81 140 xi_datastream_t* side_rotation_datastream = &feed.datastreams[1];
xively 0:efdea27c3b81 141 strcpy( side_rotation_datastream->datastream_id, "side_rotation" );
xively 0:efdea27c3b81 142 xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0];
xively 0:efdea27c3b81 143
xively 3:7ad3f6543b6e 144 feed.datastreams[2].datapoint_count = 1;
xively 3:7ad3f6543b6e 145 xi_datastream_t* temperature_datastream = &feed.datastreams[2];
xively 3:7ad3f6543b6e 146 strcpy( temperature_datastream->datastream_id, "temperature" );
xively 3:7ad3f6543b6e 147 xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0];
xively 3:7ad3f6543b6e 148
xively 0:efdea27c3b81 149 // create the cosm library context
xively 0:efdea27c3b81 150 xi_context_t* xi_context
xively 0:efdea27c3b81 151 = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
xively 0:efdea27c3b81 152
xively 0:efdea27c3b81 153 // check if everything works
xively 0:efdea27c3b81 154 if( xi_context == NULL )
xively 0:efdea27c3b81 155 {
xively 0:efdea27c3b81 156 return -1;
xively 0:efdea27c3b81 157 }
xively 0:efdea27c3b81 158
xively 0:efdea27c3b81 159 mbed_printf("feed:%d datastreams:[%s,%s]\n", feed.feed_id,
xively 0:efdea27c3b81 160 orientation_datastream->datastream_id,
xively 0:efdea27c3b81 161 side_rotation_datastream->datastream_id);
xively 0:efdea27c3b81 162
xively 0:efdea27c3b81 163 while(1) {
xively 0:efdea27c3b81 164
xively 0:efdea27c3b81 165 switch( axl.getSide() ) {
xively 0:efdea27c3b81 166 case MMA7660::Front:
habibiam 7:ffaea0d21d77 167 xi_set_value_str( current_side_rotation, "my_front" );
xively 0:efdea27c3b81 168 break;
xively 0:efdea27c3b81 169 case MMA7660::Back:
xively 0:efdea27c3b81 170 xi_set_value_str( current_side_rotation, "back" );
xively 0:efdea27c3b81 171 break;
xively 0:efdea27c3b81 172 default:
xively 0:efdea27c3b81 173 xi_set_value_str( current_side_rotation, "unknown" );
xively 0:efdea27c3b81 174 break;
xively 0:efdea27c3b81 175 }
xively 0:efdea27c3b81 176
xively 0:efdea27c3b81 177 switch( axl.getOrientation() ) {
xively 0:efdea27c3b81 178 case MMA7660::Down:
xively 0:efdea27c3b81 179 mbed_printf("down %s\n",
xively 0:efdea27c3b81 180 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 181 xi_set_value_str( current_orientation, "down" );
xively 0:efdea27c3b81 182 break;
xively 0:efdea27c3b81 183 case MMA7660::Up:
xively 0:efdea27c3b81 184 mbed_printf("up %s\n",
xively 0:efdea27c3b81 185 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 186 xi_set_value_str( current_orientation, "up" );
xively 0:efdea27c3b81 187 break;
xively 0:efdea27c3b81 188 case MMA7660::Right:
xively 0:efdea27c3b81 189 mbed_printf("right %s\n",
xively 0:efdea27c3b81 190 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 191 xi_set_value_str( current_orientation, "right" );
xively 0:efdea27c3b81 192 break;
xively 0:efdea27c3b81 193 case MMA7660::Left:
xively 0:efdea27c3b81 194 mbed_printf("left %s\n",
xively 0:efdea27c3b81 195 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 196 xi_set_value_str( current_orientation, "left" );
xively 0:efdea27c3b81 197 break;
xively 0:efdea27c3b81 198 default:
xively 0:efdea27c3b81 199 xi_set_value_str( current_orientation, "unknown" );
xively 0:efdea27c3b81 200 break;
xively 0:efdea27c3b81 201 }
xively 3:7ad3f6543b6e 202
xively 3:7ad3f6543b6e 203 xi_set_value_f32( current_temperature, tmp.read() );
xively 4:e7ca62a11595 204
xively 0:efdea27c3b81 205 mbed_printf( "update...\n" );
xively 0:efdea27c3b81 206 xi_feed_update(xi_context, &feed);
xively 0:efdea27c3b81 207 mbed_printf( "done...\n" );
habibiam 7:ffaea0d21d77 208 mbed_printf( ".... done...\n" );
xively 3:7ad3f6543b6e 209
habibiam 7:ffaea0d21d77 210 wait( 1.0 );
xively 0:efdea27c3b81 211 }
xively 0:efdea27c3b81 212 }