OK View: http://sockets.mbed.org/demo/viewer

Dependencies:   MMA7660 WebSocketClient WiflyInterface mbed

Fork of Websocket_Wifly_HelloWorld by Samuel Mokrani

Revision:
3:034dbd0b2002
Parent:
1:31e50fea8be8
--- a/main.cpp	Fri Aug 24 14:06:31 2012 +0000
+++ b/main.cpp	Thu May 08 17:21:02 2014 +0000
@@ -1,3 +1,5 @@
+#define OLD
+#ifdef OLD
 #include "mbed.h"
 #include "WiflyInterface.h"
 #include "Websocket.h"
@@ -11,18 +13,154 @@
 *     - "password" is the password
 *     - WPA is the security
 */
-WiflyInterface wifly(p9, p10, p19, p26, "mbed", "password", WPA);
+//apps board
+//WiflyInterface wifly(p9, p10, p30, p29, "iotlab", "42F67YxLX4AawRdcj", WPA);
+
+//pololu
+WiflyInterface wifly(p28, p27, p26, NC, "iotlab", "42F67YxLX4AawRdcj", WPA);
 
 int main() {
+    
+    char    recv[128];
+    
     wifly.init(); //Use DHCP
     while (!wifly.connect());
     printf("IP Address is %s\n\r", wifly.getIPAddress());
 
-    Websocket ws("ws://sockets.mbed.org:443/ws/demo/wo");
+    Websocket ws("ws://echo.websocket.org/");
+    Websocket ws1("ws://sockets.mbed.org:443/ws/demo/wo");
     while (!ws.connect());
 
     while (1) {
-            ws.send("WebSocket Hello World over Wifly");
+            ws.send("WebSocket Hello World over Wifly AA");
             wait(1.0);
+            printf("send OK\n\r");
+            if (ws.read(recv)) 
+                printf("read: %s\r\n", recv);
     }
-}
\ No newline at end of file
+}
+
+#endif
+
+#ifdef MMA
+//Uses the measured z-acceleration to drive leds 2 and 3 of the mbed
+
+#include "mbed.h"
+#include "MMA7660.h"
+
+MMA7660 MMA(p28, p27);
+
+DigitalOut connectionLed(LED4);
+PwmOut Xaxis_p(LED1);
+PwmOut Yaxis_p(LED2);
+PwmOut Zaxis_p(LED3);
+
+int main() {  
+    if (MMA.testConnection())
+        connectionLed = 1;
+        
+    while(1) {
+        Xaxis_p = MMA.x();
+        //Zaxis_n = -MMA.z();
+        Yaxis_p = MMA.y();
+        //Zaxis_n = -MMA.y();
+        Zaxis_p = MMA.z();
+        //Zaxis_n = -MMA.z();
+        
+    }
+    
+
+}
+#endif
+
+#ifdef NEW
+#include "mbed.h"
+//#include "Wifly.h"
+#include "WiflyInterface.h"
+#include "Websocket.h"
+//#include "ADXL345.h"
+
+//ADXL345 accelerometer(p5, p6, p7, p8);
+DigitalIn tcp(p20);
+
+DigitalOut Gled(p29);
+DigitalOut Rled(p27);
+DigitalOut Yled(p28);
+
+//Wifly wifly(p9, p10, p22, "mbed", "password", true);
+WiflyInterface wifly(p9, p10, p25, p26, "bubbles", "", NONE);
+//Websocket ws("ws://sockets.mbed.org/ws/sensors/wo",&wifly);
+Websocket ws("ws://sockets.mbed.org/ws/sensors/wo");
+
+#include "MMA7660.h"
+
+MMA7660 MMA(p28, p27);
+
+DigitalOut connectionLed(LED4);
+PwmOut Xaxis_p(LED1);
+PwmOut Yaxis_p(LED2);
+PwmOut Zaxis_p(LED3);
+
+int main() {
+    char json_str[100];
+
+    int readings[3] = {0, 0, 0};
+
+    //Go into standby mode to configure the device.
+    //accelerometer.setPowerControl(0x00);
+    //accelerometer.setDataFormatControl(0x0B);
+    //accelerometer.setDataRate(ADXL345_3200HZ);
+    //accelerometer.setPowerControl(0x08);
+ 
+#ifdef DOTHIS   
+    while (!wifly.cmdMode()) {
+        wifly.send("a\r\n");
+    }
+    //wifly.send("set sys iofunc 0x40\r\n", "AOK");
+#endif
+    wifly.init();           // new code
+    printf("here\n");
+    while (1) {
+        Rled = 1;
+        Yled = 0;
+        Gled = 0;
+
+#ifdef DOTHIS  
+        while (!wifly.join()) {
+            wifly.reset();
+        }
+#endif
+
+        Rled = 0;
+        Yled = 1;
+        Gled = 0;
+
+        while (!ws.connect());
+
+        Rled = 0;
+        Yled = 0;
+        Gled = 1;
+
+        while (1) {
+        
+            wait(0.1);
+            
+            Xaxis_p = MMA.x();
+            Yaxis_p = MMA.y();
+            Zaxis_p = MMA.z();
+            
+            //we read accelerometers values
+            //accelerometer.getOutput(readings);
+
+            //sprintf(json_str, "{\"id\":\"wifly_acc\",\"ax\":\"%d\",\"ay\":\"%d\",\"az\":\"%d\"}", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
+            sprintf(json_str, "{\"id\":\"wifly_acc\",\"ax\":\"%d\",\"ay\":\"%d\",\"az\":\"%d\"}", (int16_t)Xaxis_p, (int16_t)Yaxis_p, (int16_t)Zaxis_p);
+            ws.send(json_str);
+
+            if (tcp.read() != 1) {
+                wifly.reset();
+                break;
+            }
+        }
+    }
+}
+#endif
\ No newline at end of file