led get

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

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

Committer:
avnisha
Date:
Tue Sep 24 22:40:17 2013 +0000
Revision:
6:9af362ececc4
Parent:
4:e7ca62a11595
Child:
7:382c67265a5d
ok

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
avnisha 6:9af362ececc4 60 #define XI_FEED_ID 332668647 // set Xively Feed ID (numerical, no quoutes
avnisha 6:9af362ececc4 61 #define XI_API_KEY "ZmCG3GmfnJzvt1LZnLdHfS9D5vlfNrXQSxKD1jpzqsAsp3bh" // 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;
xively 3:7ad3f6543b6e 130 feed.datastream_count = 3;
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
xively 0:efdea27c3b81 147 // create the cosm library context
xively 0:efdea27c3b81 148 xi_context_t* xi_context
xively 0:efdea27c3b81 149 = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
xively 0:efdea27c3b81 150
xively 0:efdea27c3b81 151 // check if everything works
xively 0:efdea27c3b81 152 if( xi_context == NULL )
xively 0:efdea27c3b81 153 {
xively 0:efdea27c3b81 154 return -1;
xively 0:efdea27c3b81 155 }
xively 0:efdea27c3b81 156
xively 0:efdea27c3b81 157 mbed_printf("feed:%d datastreams:[%s,%s]\n", feed.feed_id,
xively 0:efdea27c3b81 158 orientation_datastream->datastream_id,
xively 0:efdea27c3b81 159 side_rotation_datastream->datastream_id);
xively 0:efdea27c3b81 160
xively 0:efdea27c3b81 161 while(1) {
xively 0:efdea27c3b81 162
xively 0:efdea27c3b81 163 switch( axl.getSide() ) {
xively 0:efdea27c3b81 164 case MMA7660::Front:
xively 0:efdea27c3b81 165 xi_set_value_str( current_side_rotation, "front" );
xively 0:efdea27c3b81 166 break;
xively 0:efdea27c3b81 167 case MMA7660::Back:
xively 0:efdea27c3b81 168 xi_set_value_str( current_side_rotation, "back" );
xively 0:efdea27c3b81 169 break;
xively 0:efdea27c3b81 170 default:
xively 0:efdea27c3b81 171 xi_set_value_str( current_side_rotation, "unknown" );
xively 0:efdea27c3b81 172 break;
xively 0:efdea27c3b81 173 }
xively 0:efdea27c3b81 174
xively 0:efdea27c3b81 175 switch( axl.getOrientation() ) {
xively 0:efdea27c3b81 176 case MMA7660::Down:
xively 0:efdea27c3b81 177 mbed_printf("down %s\n",
xively 0:efdea27c3b81 178 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 179 xi_set_value_str( current_orientation, "down" );
xively 0:efdea27c3b81 180 break;
xively 0:efdea27c3b81 181 case MMA7660::Up:
xively 0:efdea27c3b81 182 mbed_printf("up %s\n",
xively 0:efdea27c3b81 183 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 184 xi_set_value_str( current_orientation, "up" );
xively 0:efdea27c3b81 185 break;
xively 0:efdea27c3b81 186 case MMA7660::Right:
xively 0:efdea27c3b81 187 mbed_printf("right %s\n",
xively 0:efdea27c3b81 188 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 189 xi_set_value_str( current_orientation, "right" );
xively 0:efdea27c3b81 190 break;
xively 0:efdea27c3b81 191 case MMA7660::Left:
xively 0:efdea27c3b81 192 mbed_printf("left %s\n",
xively 0:efdea27c3b81 193 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 194 xi_set_value_str( current_orientation, "left" );
xively 0:efdea27c3b81 195 break;
xively 0:efdea27c3b81 196 default:
xively 0:efdea27c3b81 197 xi_set_value_str( current_orientation, "unknown" );
xively 0:efdea27c3b81 198 break;
xively 0:efdea27c3b81 199 }
xively 3:7ad3f6543b6e 200
xively 3:7ad3f6543b6e 201 xi_set_value_f32( current_temperature, tmp.read() );
xively 4:e7ca62a11595 202
xively 0:efdea27c3b81 203 mbed_printf( "update...\n" );
xively 0:efdea27c3b81 204 xi_feed_update(xi_context, &feed);
xively 0:efdea27c3b81 205 mbed_printf( "done...\n" );
xively 3:7ad3f6543b6e 206
xively 3:7ad3f6543b6e 207 wait( 15.0 );
xively 0:efdea27c3b81 208 }
xively 0:efdea27c3b81 209 }