Xively park working

Dependencies:   C12832_lcd LM75B MMA7660 WiflyInterface libxively mbed-rtos mbed

Fork of IOT-Project-LED-ControlTelnet by Bhakti Kulkarni

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //This Program is used to turn the LED ON/OFF via telent (Wifly connected)
00002 #include "mbed.h"
00003 #include "WiflyInterface.h"
00004 #include <string.h>
00005 #include "LM75B.h"
00006 #include "MMA7660.h"
00007 
00008 #define XI_FEED_ID 209829319 // set Xively Feed ID (numerical, no quoutes)
00009 #define XI_API_KEY "T0izYrB6TZVkmhhEWpzs5L7F5wqpJixxc6MtenkLDg3BLMIu" // set Xively API key (double-quoted string)
00010 
00011 #include "xively.h"
00012 #include "xi_err.h"
00013 
00014 #include "C12832_lcd.h"
00015 
00016 #define SEC 1000
00017 
00018 
00019 #define ECHO_SERVER_PORT   7
00020 
00021 
00022 PwmOut servo(p22);
00023 DigitalOut dir(LED1);
00024 //LM75B temp(p28,p27);
00025 AnalogIn temp(p19);
00026 MMA7660 axl(p28,p27);
00027 Serial pc(USBTX,USBRX);
00028 C12832_LCD lcd;
00029 
00030 #define FWD 1
00031 #define REV 0
00032 
00033 
00034 /* wifly interface:
00035 *     - p9 and p10 are for the serial communication
00036 *     - p19 is for the reset pin
00037 *     - p26 is for the connection status
00038 *     - "mbed" is the ssid of the network
00039 *     - "password" is the password
00040 *     - WPA is the security
00041 */
00042 //apps board
00043 WiflyInterface wifly(p9, p10, p30, p29, "MY_WIFI", "", NONE);
00044 
00045 //pololu
00046 //WiflyInterface wifly(p28, p27, p26, NC, "iotlab", "42F67YxLX4AawRdcj", WPA);
00047 
00048 int main() {
00049     
00050    // char    recv[128];
00051     
00052     wifly.init(); //Use DHCP
00053     pc.printf("1\r\n");
00054     while (!wifly.connect());
00055     pc.printf("IP Address is %s\n\r", wifly.getIPAddress());
00056 
00057     xi_feed_t feed;
00058         memset( &feed, NULL, sizeof( xi_feed_t ) );
00059     
00060         feed.feed_id = XI_FEED_ID;
00061         feed.datastream_count = 1;
00062     
00063         feed.datastreams[0].datapoint_count = 1;
00064         xi_datastream_t* temperature_datastream = &feed.datastreams[0];
00065         strcpy( temperature_datastream->datastream_id, "Temperature" );
00066         xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0];
00067         
00068         xi_context_t* xi_context
00069             = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
00070         if( xi_context == NULL )
00071         {
00072             pc.printf("Error in Xi_Context\r\n");
00073             exit (0);
00074         }
00075  
00076         
00077        while (true) {
00078         xi_set_value_f32( current_temperature, temp.read() ); 
00079         xi_feed_update( xi_context, &feed );
00080       wait(10.0);
00081     }
00082 }