Mode3

Dependencies:   WiflyInterface mbed C12832_lcd

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

Committer:
bhakti08
Date:
Mon Jun 09 23:32:35 2014 +0000
Revision:
6:c9595d2630c7
Parent:
5:62cd993d82a6
Child:
7:7f0988b083cb
Mode 3;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bhakti08 4:d1e0e52f7f6b 1 //This Program is used to turn the LED ON/OFF via telent (Wifly connected)
samux 1:31e50fea8be8 2 #include "mbed.h"
samux 1:31e50fea8be8 3 #include "WiflyInterface.h"
bhakti08 4:d1e0e52f7f6b 4 #include <string.h>
bhakti08 5:62cd993d82a6 5
bhakti08 4:d1e0e52f7f6b 6 #define ECHO_SERVER_PORT 7
bhakti08 6:c9595d2630c7 7 #define FWD 3
bhakti08 5:62cd993d82a6 8 #define REV 4
bhakti08 6:c9595d2630c7 9 #define LEFT 1
bhakti08 6:c9595d2630c7 10 #define RIGHT 2
bhakti08 6:c9595d2630c7 11 #define STOP 0
bhakti08 6:c9595d2630c7 12 #define STRAIGHT_WHEEL 5
bhakti08 5:62cd993d82a6 13
bhakti08 5:62cd993d82a6 14
bhakti08 4:d1e0e52f7f6b 15 PwmOut servo(p22);
bhakti08 4:d1e0e52f7f6b 16 DigitalOut dir(LED1);
bhakti08 6:c9595d2630c7 17 BusOut motor(p5,p6,p7);
bhakti08 5:62cd993d82a6 18
bhakti08 5:62cd993d82a6 19 //#define FWD 1
bhakti08 5:62cd993d82a6 20 //#define REV 0
bhakti08 5:62cd993d82a6 21
bhakti08 5:62cd993d82a6 22
samux 1:31e50fea8be8 23 /* wifly interface:
samux 1:31e50fea8be8 24 * - p9 and p10 are for the serial communication
samux 1:31e50fea8be8 25 * - p19 is for the reset pin
samux 1:31e50fea8be8 26 * - p26 is for the connection status
samux 1:31e50fea8be8 27 * - "mbed" is the ssid of the network
samux 1:31e50fea8be8 28 * - "password" is the password
samux 1:31e50fea8be8 29 * - WPA is the security
samux 1:31e50fea8be8 30 */
avnisha 3:034dbd0b2002 31 //apps board
bhakti08 4:d1e0e52f7f6b 32 WiflyInterface wifly(p9, p10, p30, p29, "MY_WIFI", "", NONE);
bhakti08 5:62cd993d82a6 33
avnisha 3:034dbd0b2002 34 //pololu
bhakti08 4:d1e0e52f7f6b 35 //WiflyInterface wifly(p28, p27, p26, NC, "iotlab", "42F67YxLX4AawRdcj", WPA);
bhakti08 5:62cd993d82a6 36
samux 1:31e50fea8be8 37 int main() {
avnisha 3:034dbd0b2002 38
samux 1:31e50fea8be8 39 wifly.init(); //Use DHCP
bhakti08 4:d1e0e52f7f6b 40 printf("1\r\n");
samux 1:31e50fea8be8 41 while (!wifly.connect());
samux 1:31e50fea8be8 42 printf("IP Address is %s\n\r", wifly.getIPAddress());
bhakti08 5:62cd993d82a6 43
bhakti08 4:d1e0e52f7f6b 44 TCPSocketServer server;
bhakti08 4:d1e0e52f7f6b 45
bhakti08 4:d1e0e52f7f6b 46 server.bind(ECHO_SERVER_PORT);
bhakti08 4:d1e0e52f7f6b 47 server.listen();
bhakti08 5:62cd993d82a6 48
bhakti08 4:d1e0e52f7f6b 49 printf("\nWait for new connection...\n");
bhakti08 4:d1e0e52f7f6b 50 TCPSocketConnection client;
bhakti08 4:d1e0e52f7f6b 51 server.accept(client);
bhakti08 6:c9595d2630c7 52 printf("Server accept\r\n");
bhakti08 6:c9595d2630c7 53
bhakti08 4:d1e0e52f7f6b 54 char buffer[256];
bhakti08 4:d1e0e52f7f6b 55 servo.period_us(50);
bhakti08 5:62cd993d82a6 56 motor = STOP;
bhakti08 4:d1e0e52f7f6b 57 while (true) {
bhakti08 5:62cd993d82a6 58 //if (client.available()){
bhakti08 5:62cd993d82a6 59 int n = client.receive(buffer, sizeof(buffer));
bhakti08 5:62cd993d82a6 60 if (n <= 0) continue;
bhakti08 5:62cd993d82a6 61 buffer[n] = 0;
bhakti08 5:62cd993d82a6 62 printf("String is : %s\r\n",buffer);
bhakti08 5:62cd993d82a6 63
bhakti08 5:62cd993d82a6 64 client.send_all(buffer, n);
bhakti08 5:62cd993d82a6 65 if (!(strcmp (buffer, "w")))
bhakti08 5:62cd993d82a6 66 motor = FWD;
bhakti08 5:62cd993d82a6 67 else if (!(strcmp(buffer,"x")))
bhakti08 5:62cd993d82a6 68 motor = REV;
bhakti08 5:62cd993d82a6 69 else if (!(strcmp(buffer,"z")))
bhakti08 5:62cd993d82a6 70 motor = STRAIGHT_WHEEL;
bhakti08 5:62cd993d82a6 71 else if (!(strcmp(buffer,"d")))
bhakti08 5:62cd993d82a6 72 motor = RIGHT;
bhakti08 5:62cd993d82a6 73 else if (!(strcmp(buffer,"a")))
bhakti08 5:62cd993d82a6 74 motor = LEFT;
bhakti08 5:62cd993d82a6 75 else if (!(strcmp(buffer,"s")))
bhakti08 5:62cd993d82a6 76 motor = STOP;
bhakti08 5:62cd993d82a6 77 //}
bhakti08 4:d1e0e52f7f6b 78 servo.pulsewidth_us(10);
bhakti08 4:d1e0e52f7f6b 79 wait_us(1);
avnisha 3:034dbd0b2002 80 }
bhakti08 5:62cd993d82a6 81 }