Final version
Dependencies: mbed Servo Motor
Diff: main.cpp
- Revision:
- 1:6d317aa0aae7
- Parent:
- 0:60cec426fad9
- Child:
- 2:15a043aa08ea
--- a/main.cpp Wed Dec 05 16:38:47 2018 +0000 +++ b/main.cpp Wed Dec 05 20:52:24 2018 +0000 @@ -40,8 +40,8 @@ char webbuff[4096]; // Currently using 1986 characters, Increase this if more web page data added void SendCMD(),getreply(),ReadWebData(),startserver(); char rx_line[1024]; -int port =80; // set server port -int SERVtimeout =5; // set server timeout in seconds in case link breaks. +//int port =80; // set server port +int timeout =5; // set server timeout in seconds in case link breaks. @@ -116,24 +116,23 @@ pc.printf("++++++++++ Resetting ESP ++++++++++\r\n"); strcpy(cmdbuff,"node.restart()\r\n"); SendCMD(); + getreply(); wait(2); - getreply(); // Set up WiFi connection pc.printf(" CONNECTING TO WIFI \r\n"); - strcpy(cmdbuff,"wifi.setmode(wifi.STATION)\r\n"); + strcpy(cmdbuff,"wifi.setmode(wifi.STATIONAP)\r\n"); SendCMD(); getreply(); wait(2); - strcpy(cmdbuff,"wifi.ap.config({ssid=\"WestSide\",pwd=\"uNwieldy_cAbbage87\"})\r\n"); + strcpy(cmdbuff,"wifi.ap.config({ssid=\"Marlon's iPhone\",pwd=\"feelsbadman\"})\r\n"); SendCMD(); getreply(); wait(2); - pc.printf("Server IP Address: \r\n"); - strcpy(cmdbuff,"wifi.ap.getip()\r\n"); + strcpy(cmdbuff,"print(\"Server IP Address: \", wifi.ap.getip())\r\n"); SendCMD(); getreply(); wait(2); @@ -142,7 +141,7 @@ pc.printf("\n++++++++++ Starting Server ++++++++++\r\n> "); //create server - sprintf(cmdbuff, "srv=net.createServer(net.TCP,%d)\r\n",SERVtimeout); + strcpy(cmdbuff, "srv=net.createServer(net.TCP)\r\n"); SendCMD(); getreply(); wait(0.5); @@ -150,48 +149,48 @@ strcpy(cmdbuff,"srv:listen(80,function(conn)\r\n"); SendCMD(); getreply(); - wait(0.3); + wait(2); // Define receive function - strcpy(cmdbuff,"conn:on(\"receive\",function(conn,receivedData) \r\n"); + strcpy(cmdbuff,"conn:on(\"receive\", function(conn, receivedData)\r\n"); SendCMD(); getreply(); - wait(0.3); + wait(2); //print data to mbed - strcpy(cmdbuff,"print(recievedData)\r\n"); + strcpy(cmdbuff,"print(\"Received Data: \" .. receivedData)\r\n"); SendCMD(); getreply(); - wait(0.2); + wait(2); // End receive function strcpy(cmdbuff,"end)\r\n"); SendCMD(); getreply(); - wait(0.2); + wait(2); // Define sent function strcpy(cmdbuff,"conn:on(\"sent\",function(conn)\r\n"); SendCMD(); getreply(); - wait(0.3); + wait(2); //print data to mbed strcpy(cmdbuff,"collectgarbage()\r\n"); SendCMD(); getreply(); - wait(0.2); + wait(2); // End sent function strcpy(cmdbuff,"end)\r\n"); SendCMD(); getreply(); - wait(0.2); + wait(2); // End server listening strcpy(cmdbuff,"end)\r\n"); SendCMD(); getreply(); - wait(0.2); + wait(2); }