mode3

Dependencies:   C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed

Fork of xively-jumpstart-demo_new by Bhakti Kulkarni

Files at this revision

API Documentation at this revision

Comitter:
zaincbs
Date:
Tue Jun 10 00:05:34 2014 +0000
Parent:
14:e32799a15720
Commit message:
mode3;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jun 03 04:07:27 2014 +0000
+++ b/main.cpp	Tue Jun 10 00:05:34 2014 +0000
@@ -1,8 +1,8 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 
-#define XI_FEED_ID 1443794017 // set Xively Feed ID (numerical, no quoutes)
-#define XI_API_KEY "iydtzKtHKHNpc4mQqq5Quv8jhi5nMwg6EKXSN6UkspZcXTrI" // set Xively API key (double-quoted string)
+#define XI_FEED_ID 1344466483 // set Xively Feed ID (numerical, no quoutes)
+#define XI_API_KEY "mgjx3VwlsvsMBhekqcASRLnzMPHi9Aw2gZCZCzyH0vQkefn3" // set Xively API key (double-quoted string)
 
 #include "app_board_io.h"
 
@@ -12,43 +12,47 @@
 #include "MMA7660.h"
 #include "LM75B.h"
 #include "C12832_lcd.h"
-
+#define ECHO_SERVER_PORT   7
 MMA7660 axl(p28, p27);
 //LM75B tmp(p28, p27);
 AnalogIn tmp(p19);
 C12832_LCD lcd;
-
+DigitalOut cL(LED1);
+Serial pc(USBTX,USBRX);
 #include "logo.h"
 
 int main() {
-    lcd_print_xively_logo();
+    cL = 1;
+    /*lcd_print_xively_logo();*/
     EthernetInterface eth;
-    
-    int s = eth.init(); //Use DHCP
-    
-    if( s != NULL )
-    {
-        lcd_printf( "Could not initialise. Will halt!\n" );        
-        exit( 0 );
-    }    
+    eth.init(); //Use DHCP
+    eth.connect();
+    pc.printf("IP Address is %s\n", eth.getIPAddress());
+    TCPSocketServer server;
+    server.bind(ECHO_SERVER_PORT);
+    server.listen();
+    while (true) {
+        pc.printf("\nWait for new connection...\n");
+        TCPSocketConnection client;
+        server.accept(client);
+        client.set_blocking(false, 150000); // Timeout after (1.5)s
         
-    s = eth.connect();
-    
-    if( s != NULL )
-    {
-        lcd_printf( "Could not connect. Will halt!\n" );
-        exit( 0 );
-    }
-    else 
-    {
-        lcd_printf( "IP: %s\n", eth.getIPAddress() );    
-    }
+        pc.printf("Connection from: %s\n", client.get_address());
+        char buffer[256];
+        while (true) {
+            //int n = client.receive(buffer, sizeof(buffer));
+            //if (n <= 0) break;
+            
+            //client.send_all(buffer, n);
+            //if (n <= 0) break;
+              
+    pc.printf("Received:%s", buffer);
     
     xi_feed_t feed;
     memset( &feed, NULL, sizeof( xi_feed_t ) );
     
     feed.feed_id = XI_FEED_ID;
-    feed.datastream_count = 3;
+    feed.datastream_count = 4;
     
     feed.datastreams[0].datapoint_count = 1;
     xi_datastream_t* orientation_datastream = &feed.datastreams[0];
@@ -65,9 +69,13 @@
     strcpy( temperature_datastream->datastream_id, "temperature" );
     xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0];
     
+    feed.datastreams[3].datapoint_count = 1;
+    xi_datastream_t* control_datastream = &feed.datastreams[3];
+    strcpy( control_datastream->datastream_id, "System" );
+    xi_datapoint_t* current_state = &control_datastream->datapoints[0];
+    
     // create the cosm library context
-    xi_context_t* xi_context
-        = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
+    xi_context_t* xi_context = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
 
     // check if everything works
     if( xi_context == NULL )
@@ -75,7 +83,7 @@
         return -1;
     }
 
-    while(1) {
+    
       
       switch( axl.getSide() ) {
         case MMA7660::Front:
@@ -107,12 +115,30 @@
           break;
       }
       
-      xi_set_value_f32( current_temperature, tmp.read() );
+       xi_set_value_f32( current_temperature, tmp.read() );
+       xi_datastream_get( xi_context, feed.feed_id
+                    , control_datastream->datastream_id
+                    , control_datastream->datapoints);      
+                        current_state = &control_datastream->datapoints[0];   
+      int system_status = current_state->value.i32_value;
+      
+      if (system_status == 0)
+       {
+           cL = 0;
+        }
+      if (system_status == 1)
+       {
+           cL = 1;
+        }
         
       lcd_printf( "update...\n" );
       xi_feed_update( xi_context, &feed );
       lcd_printf( "done...\n" );
       
-      wait( 10.0 );
-    }
+      
+      }
+        client.close();
+        
+ }
+   
 }