Xively park working

Dependencies:   C12832_lcd LM75B MMA7660 WiflyInterface libxively mbed-rtos mbed

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

main.cpp

Committer:
bhakti08
Date:
2014-06-06
Revision:
4:d1e0e52f7f6b
Parent:
3:034dbd0b2002
Child:
5:efa4a9eafe7d

File content as of revision 4:d1e0e52f7f6b:

//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>

#define ECHO_SERVER_PORT   7


PwmOut servo(p22);
DigitalOut dir(LED1);

#define FWD 1
#define REV 0


/* wifly interface:
*     - p9 and p10 are for the serial communication
*     - p19 is for the reset pin
*     - p26 is for the connection status
*     - "mbed" is the ssid of the network
*     - "password" is the password
*     - WPA is the security
*/
//apps board
WiflyInterface wifly(p9, p10, p30, p29, "MY_WIFI", "", NONE);

//pololu
//WiflyInterface wifly(p28, p27, p26, NC, "iotlab", "42F67YxLX4AawRdcj", WPA);

int main() {
    
    char    recv[128];
    
    wifly.init(); //Use DHCP
    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);

    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);
    }
}