Xively park working

Dependencies:   C12832_lcd LM75B MMA7660 WiflyInterface libxively mbed-rtos mbed

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

Revision:
5:efa4a9eafe7d
Parent:
4:d1e0e52f7f6b
--- a/main.cpp	Fri Jun 06 13:44:53 2014 +0000
+++ b/main.cpp	Sat Jun 07 01:04:41 2014 +0000
@@ -1,14 +1,31 @@
 //This Program is used to turn the LED ON/OFF via telent (Wifly connected)
 #include "mbed.h"
 #include "WiflyInterface.h"
-#include "Websocket.h"
 #include <string.h>
+#include "LM75B.h"
+#include "MMA7660.h"
+
+#define XI_FEED_ID 209829319 // set Xively Feed ID (numerical, no quoutes)
+#define XI_API_KEY "T0izYrB6TZVkmhhEWpzs5L7F5wqpJixxc6MtenkLDg3BLMIu" // set Xively API key (double-quoted string)
+
+#include "xively.h"
+#include "xi_err.h"
+
+#include "C12832_lcd.h"
+
+#define SEC 1000
+
 
 #define ECHO_SERVER_PORT   7
 
 
 PwmOut servo(p22);
 DigitalOut dir(LED1);
+//LM75B temp(p28,p27);
+AnalogIn temp(p19);
+MMA7660 axl(p28,p27);
+Serial pc(USBTX,USBRX);
+C12832_LCD lcd;
 
 #define FWD 1
 #define REV 0
@@ -30,36 +47,36 @@
 
 int main() {
     
-    char    recv[128];
+   // char    recv[128];
     
     wifly.init(); //Use DHCP
-    printf("1\r\n");
+    pc.printf("1\r\n");
     while (!wifly.connect());
-    printf("IP Address is %s\n\r", wifly.getIPAddress());
-
-   TCPSocketServer server;
-    
-    server.bind(ECHO_SERVER_PORT);
-    server.listen();
-
-    printf("\nWait for new connection...\n");
-    TCPSocketConnection client;
-    server.accept(client);
+    pc.printf("IP Address is %s\n\r", wifly.getIPAddress());
 
-    char buffer[256];
-    servo.period_us(50);
-    while (true) {
-        int n = client.receive(buffer, sizeof(buffer));
-        if (n <= 0) continue;
-        buffer[n] = 0;
-        printf("String is : %s\r\n",buffer);
-
-        client.send_all(buffer, n);
-        if (!(strcmp (buffer, "f")))
-            dir = FWD;
-        else if (!(strcmp(buffer,"r")))
-            dir = REV;
-        servo.pulsewidth_us(10);
-        wait_us(1);
+    xi_feed_t feed;
+        memset( &feed, NULL, sizeof( xi_feed_t ) );
+    
+        feed.feed_id = XI_FEED_ID;
+        feed.datastream_count = 1;
+    
+        feed.datastreams[0].datapoint_count = 1;
+        xi_datastream_t* temperature_datastream = &feed.datastreams[0];
+        strcpy( temperature_datastream->datastream_id, "Temperature" );
+        xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0];
+        
+        xi_context_t* xi_context
+            = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
+        if( xi_context == NULL )
+        {
+            pc.printf("Error in Xi_Context\r\n");
+            exit (0);
+        }
+ 
+        
+       while (true) {
+        xi_set_value_f32( current_temperature, temp.read() ); 
+        xi_feed_update( xi_context, &feed );
+      wait(10.0);
     }
 }
\ No newline at end of file