![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Update
Dependencies: MMA7660FC WebSocketClient WiflyInterface mbed
Fork of mbed_websocket_for_3Axis_Digiital_Accelerometer by
Revision 1:099ea08628f2, committed 2015-02-16
- Comitter:
- lingtien5846
- Date:
- Mon Feb 16 09:18:48 2015 +0000
- Parent:
- 0:de962bd57d31
- Commit message:
- Update
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r de962bd57d31 -r 099ea08628f2 main.cpp --- a/main.cpp Fri Feb 06 04:56:32 2015 +0000 +++ b/main.cpp Mon Feb 16 09:18:48 2015 +0000 @@ -12,12 +12,12 @@ * - "password" is the password * - WPA is the security */ -WiflyInterface wifly(p13, p14, p19, p26, "WWNet", "mmmmmmmm", WPA); +WiflyInterface wifly(p9, p10, p19, p26, "Nexus_5", "1234567890", WPA); DigitalOut myled1(LED1); DigitalOut myled2(LED2); DigitalOut myled3(LED3); DigitalOut myled4(LED4); - + #define ADDR_MMA7660 0x98 // I2C SLAVE ADDR MMA7660FC MMA7660FC Acc(p28, p27, ADDR_MMA7660); //sda, scl, Addr @@ -30,25 +30,25 @@ wifly.init(); //Use DHCP //wifly.init("192.168.21.33","255.255.255.0","192.168.21.2"); while (!wifly.connect()); - myled4=1; + myled1 = 1; printf("IP Address is %s\n\r", wifly.getIPAddress()); - Websocket ws("ws://sockets.mbed.org/ws/mbedschool/viewer"); + //Websocket ws("ws://192.168.0.153:8080/ws/accel/send"); + //Websocket ws("ws://192.168.0.102:8888"); + Websocket ws("ws://wot.city/object/accelerometer/send"); + while (!ws.connect()); - myled2=1; + myled2 = 1; - Acc.init(); // Initialization - pc.printf("Value reg 0x06: %#x\n", Acc.read_reg(0x06)); // Test the correct value of the register 0x06 + pc.printf("Value reg 0x06: %#x\n", Acc.read_reg( 0x06)); // Test the correct value of the register 0x06 pc.printf("Value reg 0x08: %#x\n", Acc.read_reg(0x08)); // Test the correct value of the register 0x08 pc.printf("Value reg 0x07: %#x\n\r", Acc.read_reg(0x07)); // Test the correct value of the register 0x07 - - while (1) { char data[256]; - myled4=1; + myled3 = 1; float x=0, y=0, z=0; float ax=0, ay=0, az=0; @@ -59,30 +59,28 @@ wait_ms(100); - - ax = G_VALUE[Acc.read_x()]; ay = G_VALUE[Acc.read_y()]; az = G_VALUE[Acc.read_z()]; - if(ax<0){ - myled1=1; - }else{ - myled1=0; - } - if(ay<0){ - myled2=1; - }else{ - myled2=0; - } - if(az<0){ - myled3=1; - }else{ - myled3=0; - } +// if(ax<0){ +// myled1=1; +// }else{ +// myled1=0; +// } +// if(ay<0){ +// myled2=1; +// }else{ +// myled2=0; +// } +// if(az<0){ +// myled3=1; +// }else{ +// myled3=0; +// } - wait(1); - sprintf( data , " X: %d, Y: %d, Z: %d\n", ax, ay, az ); + wait(0.2); + sprintf(data , "{\"ax\": %f, \"ay\": %f, \"az\": %f}", ax, ay, az); ws.send(data); //wait(1.0);