4180 Final Project
Dependencies: 4DGL-uLCD-SE mbed Servo
Diff: wifi.cpp
- Revision:
- 25:2e95a5731412
- Parent:
- 6:50a82641d07b
- Child:
- 27:2bd737c0a8af
--- a/wifi.cpp Wed Apr 27 19:33:54 2016 +0000 +++ b/wifi.cpp Thu Apr 28 19:26:59 2016 +0000 @@ -1,6 +1,9 @@ #include "wifi.h" -Serial esp(p28, p27); // tx, rx + +Serial esp(p13, p14); // tx, rx + +extern Serial pc; Timer t; int count,ended,timeout; @@ -69,8 +72,8 @@ ESPsetbaudrate(); - //pc.printf("\n---------- Connecting to AP ----------\r\n"); - //pc.printf("ssid = %s pwd = %s\r\n",ssid,pwd); + pc.printf("\n---------- Connecting to AP ----------\r\n"); + pc.printf("ssid = %s pwd = %s\r\n",ssid,pwd); strcpy(snd, "wifi.sta.config(\""); strcat(snd, ssid); strcat(snd, "\",\""); @@ -82,7 +85,7 @@ //pc.printf(buf); wait(5); - /* + pc.printf("\n---------- Get IP's ----------\r\n"); strcpy(snd, "print(wifi.sta.getip())\r\n"); SendCMD(); @@ -99,7 +102,7 @@ timeout=2; getreply(); pc.printf(buf); - */ + } @@ -174,4 +177,77 @@ set_time(utime); time_t seconds = time(NULL); //pc.printf("Time as a basic string = %s", ctime(&seconds)); -} \ No newline at end of file +} + +void setup_http() +{ + + pc.printf("\n---------- Setting up http server ----------\r\n"); + + strcpy(snd, "log={'test','hey Edison'}\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "srv=net.createServer(net.TCP)\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "srv:listen(80,function(conn)\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "conn:on(\"receive\",function(conn,payload)\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "conn:send(\"<!DOCTYPE html>\")\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "conn:send(\"<html>\")\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "for key,value in pairs(log) do conn:send(\"<p>\" .. value .. \"<p>\") end\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "conn:send(\"</html>\")\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "end)\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "conn:on(\"sent\",function(conn) conn:close() end)\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "end)\r\n"); + SendCMD(); + + flush(); + +} + +void update_log(vector<string>& log) +{ + strcpy(snd, "log={"); + //SendCMD(); + //wait(1); + + for(unsigned i=0; i<log.size(); i++){ + strcat(snd, "\""); + strcat(snd, log[i].c_str()); + strcat(snd, "\""); + if(i<log.size()-1) + strcat(snd, ","); + //SendCMD(); + //wait(1); + + } + strcat(snd, "}\r\n"); + pc.printf("%s\n\r",snd); + SendCMD(); + wait(1); + flush(); +} + \ No newline at end of file