Fork of Farrukh's webserver. Tested on LPC1768 and STM32f401 but should work on almost any platform.

Dependencies:   mbed

New version that has been tested on LPC1768 and STM32F401 Based on Farrukh's idea here: https://os.mbed.com/users/programmer5/code/STM32-ESP8266-WEBSERVER/

Enter your Wi-Fi SSID and PASSWORD and edit the espbaud to suit your ESP8266, Works fast and stable at 460800.

Use configuration program to reset and set up the ESP8266 if needed:

https://os.mbed.com/users/star297/code/ESP8266-configuaration-baudrate/

Limitations are no HTTPS.

Committer:
star297
Date:
Tue Apr 21 09:32:28 2020 +0000
Revision:
7:26dab90b464f
Parent:
6:9f3f0db71230
code tidy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
star297 0:e2a155f50119 1 #include "mbed.h"
star297 0:e2a155f50119 2
star297 5:efcfa9e61907 3
star297 6:9f3f0db71230 4 // LPC1768 ESP8266 works up to 460800 baud
star297 5:efcfa9e61907 5
star297 4:7334688498cc 6 //Serial ports to be used
star297 4:7334688498cc 7 Serial pc(USBTX,USBRX);//TO BE used for debug info
star297 4:7334688498cc 8 Serial esp(p13,p14);//TX,RX TO BE CONNECTED TO ESP
star297 4:7334688498cc 9 Serial esp2(p13,p14);//TX,RX TO BE CONNECTED TO ESP
star297 6:9f3f0db71230 10 int espbaud = 115200;
star297 4:7334688498cc 11 DigitalOut espreset(p25,1);
star297 4:7334688498cc 12 //Connections to relay
star297 4:7334688498cc 13 //relay works at logic LOW
star297 4:7334688498cc 14 DigitalOut digital_out_1(LED1,1);// High on initialization
star297 4:7334688498cc 15 DigitalOut digital_out_2(LED2,1);// High on initialization
star297 4:7334688498cc 16 DigitalOut digital_out_3(LED3,1);// High on initialization
star297 4:7334688498cc 17 DigitalOut digital_out_4(LED4,1);// High on initialization
star297 4:7334688498cc 18 //digital inputs, connected to push buttons
star297 4:7334688498cc 19 DigitalIn digital_in_1(p21);
star297 4:7334688498cc 20 DigitalIn digital_in_2(p22);
star297 4:7334688498cc 21 DigitalIn digital_in_3(p23);
star297 4:7334688498cc 22 DigitalIn digital_in_4(p24);
star297 4:7334688498cc 23 //Analog output
star297 4:7334688498cc 24 PwmOut analog_out_1(p26);
star297 4:7334688498cc 25 //Analog Input
star297 4:7334688498cc 26 AnalogIn tempSensor(p20);
star297 0:e2a155f50119 27
star297 6:9f3f0db71230 28 //F401 ESP8266 works up to 460800 baud
star297 4:7334688498cc 29 /*
star297 4:7334688498cc 30 //Serial ports to be used
star297 4:7334688498cc 31 Serial pc(USBTX,USBRX);//TO BE used for debug info
star297 4:7334688498cc 32 Serial esp(D8,D2);//TX,RX TO BE CONNECTED TO ESP
star297 4:7334688498cc 33 Serial esp2(D8,D2);//TX,RX TO BE CONNECTED TO ESP
star297 6:9f3f0db71230 34 int espbaud = 115200;
star297 4:7334688498cc 35 //Connections to relay
star297 4:7334688498cc 36 //relay works at logic LOW
star297 4:7334688498cc 37 DigitalOut digital_out_1(D3,1);// High on initialization
star297 4:7334688498cc 38 DigitalOut digital_out_2(D4,1);// High on initialization
star297 4:7334688498cc 39 DigitalOut digital_out_3(D5,1);// High on initialization
star297 4:7334688498cc 40 DigitalOut digital_out_4(D6,1);// High on initialization
star297 4:7334688498cc 41 //digital inputs, connected to push buttons
star297 4:7334688498cc 42 DigitalIn digital_in_1(A1);
star297 4:7334688498cc 43 DigitalIn digital_in_2(A2);
star297 4:7334688498cc 44 DigitalIn digital_in_3(A3);
star297 4:7334688498cc 45 DigitalIn digital_in_4(A4);
star297 4:7334688498cc 46 //Analog output
star297 4:7334688498cc 47 PwmOut analog_out_1(D15);
star297 4:7334688498cc 48 //Analog Input
star297 4:7334688498cc 49 AnalogIn tempSensor(A0);
star297 4:7334688498cc 50 */
star297 4:7334688498cc 51
star297 7:26dab90b464f 52 char ssid[32] = "ssid"; // enter your router ssid inside the quotes
star297 7:26dab90b464f 53 char pwd[32] = "password"; // enter your router password inside the quotes
star297 0:e2a155f50119 54
star297 4:7334688498cc 55 #define BUFFER_SIZE 3000
star297 4:7334688498cc 56 #define REQ_LINE_BUFF_SIZE 100
star297 4:7334688498cc 57 #define UNKNOWN 0
star297 4:7334688498cc 58 #define OK 1
star297 4:7334688498cc 59 #define ERROR 2
star297 4:7334688498cc 60 #define FAIL 3
star297 4:7334688498cc 61 #define READY 4
star297 4:7334688498cc 62 #define READY_TO_WRITE_TCP 5
star297 4:7334688498cc 63
star297 0:e2a155f50119 64
star297 4:7334688498cc 65 const char get_analog_outputs_status[]="/analog_outputs";
star297 4:7334688498cc 66 const char get_Toggle_Output[]="/digital_outputs/toggle";
star297 4:7334688498cc 67 const char get_analog_inputs_status[]="/analog_inputs";
star297 4:7334688498cc 68 const char get_analog_output_update[]="/analog_outputs/update";
star297 4:7334688498cc 69 const char get_digital_output_status[]="/digital_outputs";
star297 4:7334688498cc 70 const char get_digital_inputs_html[]="/dinputs.html";
star297 4:7334688498cc 71 const char get_digital_input_status[]="/digital_inputs";
star297 4:7334688498cc 72 const char get_index_html[]="/index.html";
star297 4:7334688498cc 73 const char get_analog_outputs[]="/anoutputs.html";
star297 4:7334688498cc 74 const char get_analog_inputs_html[]="/aninputs.html";
star297 4:7334688498cc 75
star297 4:7334688498cc 76
star297 4:7334688498cc 77 const char jsonHeader[]="HTTP/1.1 200 OK\n"
star297 4:7334688498cc 78 "Content-type: application/json\r\n\r\n";
star297 2:d4c6bc0f2dc4 79
star297 4:7334688498cc 80 const char textPlainHeader[]="HTTP/1.1 200 OK\n"
star297 4:7334688498cc 81 "Content-type: text/plain\r\n\r\n";
star297 4:7334688498cc 82
star297 4:7334688498cc 83 const char index_html[]="HTTP/1.1 200 OK\n"
star297 4:7334688498cc 84 "Content-type: text/html\r\n\r\n"
star297 4:7334688498cc 85 "<!DOCTYPE html>\n<html>\n<head>\n<title>esp</title>\n<link rel=stylesheet type=text/css href=css/style.css>\n<script src=https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js></script>\n<script>$(document).ready(function(){setInterval(\"get_digital_output_status()\",2000)});function get_digital_output_status(){var a=\"/digital_outputs\";$.ajax({url:a,dataType:\"json\",success:function(b){if(b.digital_outputs.dout1==1){$(\"#dout1\").html(\"HIGH\")}else{$(\"#dout1\").html(\"LOW\")}if(b.digital_outputs.dout2==1){$(\"#dout2\").html(\"HIGH\")}else{$(\"#dout2\").html(\"LOW\")}if(b.digital_outputs.dout3==1){$(\"#dout3\").html(\"HIGH\")}else{$(\"#dout3\").html(\"LOW\")}if(b.digital_outputs.dout4==1){$(\"#dout4\").html(\"HIGH\")}else{$(\"#dout4\").html(\"LOW\")}},timeout:2000})}function digital_output_toggle(a){var b=\"/digital_outputs/toggle?pin=\"+a;$.ajax({url:b,dataType:\"text\",success:function(c){if(c==\"1\"){$(\"#\"+a).html(\"HIGH\")}else{if(c==\"0\"){$(\"#\"+a).html(\"LOW\")}else{alert(\"failed to toggle digital output\")}}},timeout:2000})};</script>\n</head>\n<body>\n<header>\n<img src=images/logo.jpg>\n<h1>ESP8266 BASED WEBSERVER</h1>\n</header>\n<nav>\n<ul>\n<li><a class=active href=index.html>Digital Outputs</a></li>\n<li><a href=dinputs.html>Digital inputs</a></li>\n<li><a href=anoutputs.html>Analog Outputs</a></li>\n<li><a href=aninputs.html>Analog Inputs</a></li>\n</ul>\n</nav>\n<section>\n<table>\n<tr>\n<th>Digital Ouput</th>\n<th>Status</th>\n<th>Option</th>\n</tr>\n<tr>\n<td>DOut1</td>\n<td id=dout1>waiting..</td>\n<td><button class=button onclick=\"digital_output_toggle('dout1')\">Toggle</button>\n</td>\n</tr>\n<tr>\n<td>DOut2</td>\n<td id=dout2>waiting..</td>\n<td><button class=button onclick=\"digital_output_toggle('dout2')\">Toggle</button>\n</tr>\n<tr>\n<td>DOut3</td>\n<td id=dout3>waiting..</td>\n<td><button class=button onclick=\"digital_output_toggle('dout3')\">Toggle</button>\n</tr>\n<tr>\n<td>DOut4</td>\n<td id=dout4>waiting..</td>\n<td><button class=button onclick=\"digital_output_toggle('dout4')\">Toggle</button>\n</tr>\n</table>\n</section>\n</body>\n</html>";
star297 4:7334688498cc 86
star297 4:7334688498cc 87 const char digitalInputs_html[]="HTTP/1.1 200 OK\n"
star297 4:7334688498cc 88 "Content-type: text/html\r\n\r\n"
star297 4:7334688498cc 89 "<!DOCTYPE html>\n<html>\n<head>\n<title>esp</title>\n<link rel=stylesheet type=text/css href=css/style.css>\n<script src=https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js></script>\n<script>$(document).ready(function(){setInterval(\"get_digital_input_status()\",2000)});function get_digital_input_status(){var a=\"/digital_inputs\";$.ajax({url:a,dataType:\"json\",success:function(b){if(b.digital_inputs.din1==1){$(\"#din1\").html(\"HIGH\")}else{$(\"#din1\").html(\"LOW\")}if(b.digital_inputs.din2==1){$(\"#din2\").html(\"HIGH\")}else{$(\"#din2\").html(\"LOW\")}if(b.digital_inputs.din3==1){$(\"#din3\").html(\"HIGH\")}else{$(\"#din3\").html(\"LOW\")}if(b.digital_inputs.din4==1){$(\"#din4\").html(\"HIGH\")}else{$(\"#din4\").html(\"LOW\")}},timeout:2000})};</script>\n</head>\n<body>\n<header>\n<img src=images/logo.jpg>\n<h1>ESP8266 BASED WEBSERVER</h1>\n</header>\n<nav>\n<ul>\n<li><a href=index.html>Digital Outputs</a></li>\n<li><a class=active href=dinputs.html>Digital inputs</a></li>\n<li><a href=anoutputs.html>Analog Outputs</a></li>\n<li><a href=aninputs.html>Analog Inputs</a></li>\n</ul>\n</nav>\n<section>\n<table id=inputsTable>\n<tr>\n<th>Digital Input</th>\n<th>Status</th>\n</tr>\n<tr>\n<td>DIn1</td>\n<td id=din1>waiting..</td>\n</td>\n</tr>\n<tr>\n<td>DIn2</td>\n<td id=din2>waiting..</td>\n</tr>\n<tr>\n<td>DIn3</td>\n<td id=din3>waiting..</td>\n</tr>\n<tr>\n<td>DIn4</td>\n<td id=din4>waiting..</td>\n</tr>\n</table>\n</section>\n</body>\n</html>";
star297 4:7334688498cc 90
star297 4:7334688498cc 91 const char analog_outputs_html[]="HTTP/1.1 200 OK\n"
star297 4:7334688498cc 92 "Content-type: text/html\r\n\r\n"
star297 5:efcfa9e61907 93 "<!DOCTYPE html>\n<html>\n<head>\n<title>esp</title>\n<link rel=stylesheet type=text/css href=css/style.css>\n<script src=https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js></script>\n<script type=text/javascript src=https://www.gstatic.com/charts/loader.js></script>\n<script>$(document).ready(function(){setInterval(\"getAnalogOutputStatus()\",2000);displayVoltageLevel()});var voltage_level=0;function getAnalogOutputStatus(){var a=\"/analog_outputs\";$.ajax({url:a,dataType:\"text\",success:function(b){voltage_level=parseFloat(b)},timeout:2000})}function setNewVoltageLevel(a){var b=\"/analog_outputs/update?value=\"+a;$.ajax({url:b,dataType:\"text\",success:function(c){voltage_level=parseFloat(c)},timeout:2000})}function displayVoltageLevel(){google.charts.load(\"current\",{packages:[\"gauge\"]});google.charts.setOnLoadCallback(a);function a(){var d=google.visualization.arrayToDataTable([[\"Label\",\"Value\"],[\"Volts\",0],]);var b={width:300,height:250,redFrom:8,redTo:12,yellowFrom:4,yellowTo:8,greenFrom:0,greenTo:4,min:0,max:12,minorTicks:5};var c=new google.visualization.Gauge(document.getElementById(\"chart_div\"));c.draw(d,b);setInterval(function(){d.setValue(0,1,voltage_level);c.draw(d,b)},500)}};</script>\n</head>\n<body>\n<header>\n<img src=images/logo.jpg>\n<h1>ESP8266 BASED WEBSERVER</h1>\n</header>\n<nav>\n<ul>\n<li><a href=index.html>Digital Outputs</a>\n</li>\n<li><a href=dinputs.html>Digital inputs</a>\n</li>\n<li><a class=active href=anoutputs.html>Analog Outputs</a>\n</li>\n<li><a href=aninputs.html>Analog Inputs</a>\n</li>\n</ul>\n</nav>\n<section>\n<h3>Enter new voltage value and press Update btton</h3>\n<input type=text id=volts maxlength=5 placeholder=Voltage..(0.00-12.00)>\n<button class=button onclick=\"setNewVoltageLevel(document.getElementById('volts').value)\">Update</button>\n<div id=chart_div style=width:300px;height:250px></div>\n<h1 style=color:blue;margin-left:50px>Voltage Level</h1>\n</section>\n</body>\n</html>";
star297 5:efcfa9e61907 94
star297 5:efcfa9e61907 95 const char analog_inputs_html[]="HTTP/1.1 200 OK\n"
star297 5:efcfa9e61907 96 "Content-type: text/html\r\n\r\n"
star297 5:efcfa9e61907 97 "<!DOCTYPE html>\n<html>\n<head>\n<title>esp</title>\n<link rel=stylesheet type=text/css href=css/style.css>\n<script src=https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js></script>\n<script>$(document).ready(function(){setInterval(\"getTemperature()\",2000)});function getTemperature(){var a=\"/analog_inputs\";$.ajax({url:a,dataType:\"text\",success:function(b){$(\"#temp\").html(b+\"&#8451;\")},timeout:2000})};</script>\n</head>\n<body>\n<header>\n<img src=images/logo.jpg>\n<h1>ESP8266 BASED WEBSERVER</h1>\n</header>\n<nav>\n<ul>\n<li><a href=index.html>Digital Outputs</a>\n</li>\n<li><a href=dinputs.html>Digital inputs</a>\n</li>\n<li><a href=anoutputs.html>Analog Outputs</a>\n</li>\n<li><a class=active href=aninputs.html>Analog Inputs</a>\n</li>\n</ul>\n</nav>\n<section>\n<h1 id=temp style=border-style:solid;border-width:6px;border-color:red;border-radius:20px;background-color:#aeb5b7;width:100px;margin-top:20px;margin-left:40px;padding:20px>Waiting..</h1>\n<h2 style=margin-left:25px;color:blue>Temperature Value</h2>\n<br><br><h2>Temperature history</h2>\n<iframe width=450 height=260 style=\"border:1px solid #ccc\" src=\"https://thingspeak.com/channels/243141/charts/1?bgcolor=%23ffffff&color=%23d62020&dynamic=true&results=100&type=line\"></iframe>\n</section>\n</body>\n</html>";
star297 5:efcfa9e61907 98
star297 5:efcfa9e61907 99 const char style_css[]="HTTP/1.1 200 OK\n"
star297 5:efcfa9e61907 100 "Content-type: text/css\r\n\r\n"
star297 5:efcfa9e61907 101 "*{padding:0;margin:0}header{background-color:#27ace5}body{font-family:calibri}header h1{text-align:center;font-size:4em;color:#fff;padding:10px}header img{width:110px;margin-top:10px;float:left}ul{list-style-type:none;margin:0;padding:0;overflow:hidden;background-color:#333}li{float:left}li a{display:block;color:#fff;text-align:center;padding:14px 16px;text-decoration:none}li a:hover:not(.active){background-color:#111}.active{background-color:#4CAF50}table{border-collapse:collapse;width:100%}table#inputsTable{border-collapse:collapse;width:70%}th,td{text-align:left;padding:8px}tr:nth-child(even){background-color:#f2f2f2}th{background-color:#4CAF50;color:#fff}section{width:60%;margin:10px}.button{display:inline-block;padding:10px 15px;font-size:15px;cursor:pointer;text-align:center;text-decoration:none;outline:none;color:#fff;background-color:#4CAF50;border:none;border-radius:15px;box-shadow:0 9px #999}.button:hover{background-color:#3e8e41}.button:active{background-color:#3e8e41;box-shadow:0 5px #666;transform:translateY(4px)}input[type=text],select{width:25%;padding:12px 20px;margin:8px 0;display:inline-block;border:1px solid #ccc;border-radius:4px;box-sizing:border-box}";
star297 5:efcfa9e61907 102
star297 5:efcfa9e61907 103 const char not_found_text[]="HTTP/1.1 404 Not Found\n"
star297 5:efcfa9e61907 104 "Content-type: text/plain\r\n\r\n"
star297 5:efcfa9e61907 105 "page not found";
star297 5:efcfa9e61907 106
star297 5:efcfa9e61907 107 //HTTP/1.1 200 OK
star297 5:efcfa9e61907 108 //Content-type:image/jpeg
star297 5:efcfa9e61907 109 const char logo_jpg[]={0x48, 0x54, 0x54, 0x50, 0x2F, 0x31, 0x2E, 0x31, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4F, 0x4B, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x74, 0x79, 0x70, 0x65, 0x3A, 0x69, 0x6D, 0x61, 0x67, 0x65, 0x2F, 0x6A, 0x70, 0x65, 0x67, 0x0D,0x0A,0x0D, 0x0A,
star297 5:efcfa9e61907 110 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x3A, 0x43, 0x52, 0x45, 0x41, 0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xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x11, 0x08, 0x00, 0x71, 0x00, 0x96, 0x03, 0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xFF, 0xC4, 0x00, 0x1F, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0xFF, 0xC4, 0x00, 0xB5, 0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFF, 0xC4, 0x00, 0x1F, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0xFF, 0xC4, 0x00, 0xB5, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77,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0x11, 0x54, 0x2F, 0x4A, 0x5A, 0x28, 0xA0, 0x02, 0x8A, 0x28, 0xA0, 0x02, 0x8A, 0x28, 0xA0, 0x02, 0x8A, 0x28, 0xA0, 0x02, 0x8A, 0x28, 0xA0, 0x02, 0x8A, 0x28, 0xA0, 0x04, 0x23, 0x27, 0xDA, 0xA1, 0x61, 0xB7, 0x38, 0x1F, 0x2D, 0x4F, 0x48, 0x47, 0x06, 0x80, 0x21, 0x04, 0xA8, 0xE3, 0xA5, 0x36, 0x9E, 0x54, 0x83, 0xC0, 0xC8, 0x34, 0xA2, 0x3C, 0x1E, 0x69, 0xDC, 0x06, 0xAA, 0x16, 0xA9, 0x95, 0x42, 0xD2, 0x81, 0x8A, 0x29, 0x00, 0x51, 0x45, 0x14, 0x00, 0x51, 0x45, 0x14, 0x00, 0x51, 0x45, 0x14, 0x00, 0x51, 0x45, 0x14, 0x00, 0x51, 0x45, 0x14, 0x00, 0x51, 0x45, 0x14, 0x00, 0x51, 0x45, 0x14, 0x00, 0x51, 0x45, 0x14, 0x00, 0x84, 0x70, 0x29, 0x68, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x0A, 0x28, 0xA2, 0x80, 0x3F, 0xFF, 0xD9};
star297 5:efcfa9e61907 111
star297 5:efcfa9e61907 112 // HTTP/1.1 200 OK
star297 5:efcfa9e61907 113 //Content-type:image/x-icon
star297 5:efcfa9e61907 114 const char favicon_ico[]={0x48, 0x54, 0x54, 0x50, 0x2F, 0x31, 0x2E, 0x31, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4F, 0x4B, 0x0A, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2D, 0x74, 0x79, 0x70, 0x65, 0x3A, 0x20, 0x69, 0x6D, 0x61, 0x67, 0x65, 0x2F, 0x78, 0x2D, 0x69, 0x63, 0x6F, 0x6E,0x0D, 0x0A,0x0D, 0x0A,
star297 5:efcfa9e61907 115 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x10, 0x10, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x68, 0x03, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xED, 0xED, 0xED, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8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00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
star297 5:efcfa9e61907 116
star297 5:efcfa9e61907 117 char rxBuff[BUFFER_SIZE];//array to store data received from esp
star297 5:efcfa9e61907 118 char reqLineBuff[REQ_LINE_BUFF_SIZE];
star297 5:efcfa9e61907 119 unsigned char reqLinBuffIndex=0;
star297 5:efcfa9e61907 120 unsigned int bufferWritingIndex=0;//write pointer
star297 5:efcfa9e61907 121 unsigned int bufferReadingIndex_IpdSearch=0;//read pointer
star297 5:efcfa9e61907 122 unsigned int bufferReadingIndex_espRespSearch=0;//read pointer
star297 5:efcfa9e61907 123 char serverIp[16];
star297 5:efcfa9e61907 124
star297 5:efcfa9e61907 125 Timer t;
star297 5:efcfa9e61907 126
star297 5:efcfa9e61907 127 void espRxInterrupt();
star297 5:efcfa9e61907 128 char readEspResponse();
star297 5:efcfa9e61907 129 void handleHttpRequests();
star297 5:efcfa9e61907 130 void processReqLine(char *stringToProcess);
star297 5:efcfa9e61907 131 void sendMemArrayToEsp(const char*str,unsigned int len);
star297 5:efcfa9e61907 132 void sendRequestedPageToClient(char id, const char* page,unsigned int len);
star297 5:efcfa9e61907 133 void extractQueryFieldValue(char* someUrl,char* field, char* value);
star297 5:efcfa9e61907 134 char toggleOutput(char* pinName);
star297 5:efcfa9e61907 135
star297 5:efcfa9e61907 136 int main(){
star297 5:efcfa9e61907 137 //configure Pull down on all digital inputs
star297 5:efcfa9e61907 138 digital_in_1.mode(PullDown);
star297 5:efcfa9e61907 139 digital_in_2.mode(PullDown);
star297 5:efcfa9e61907 140 digital_in_3.mode(PullDown);
star297 5:efcfa9e61907 141 digital_in_4.mode(PullDown);
star297 5:efcfa9e61907 142
star297 5:efcfa9e61907 143 //configure baud rate for UART
star297 5:efcfa9e61907 144 pc.baud(115200);
star297 6:9f3f0db71230 145 esp.baud(espbaud);
star297 5:efcfa9e61907 146
star297 5:efcfa9e61907 147 esp2.attach(&espRxInterrupt,Serial::RxIrq);
star297 5:efcfa9e61907 148
star297 5:efcfa9e61907 149 pc.printf("\033[0m\033[2J\033[HInitialise!\r\n\n\n");
star297 5:efcfa9e61907 150
star297 5:efcfa9e61907 151 esp.printf("AT+RST\r\n");
star297 5:efcfa9e61907 152 while(readEspResponse()!=READY);
star297 5:efcfa9e61907 153 pc.printf("Reset success\n");
star297 5:efcfa9e61907 154 esp.printf("ATE0\r\n");//disable ECHO
star297 5:efcfa9e61907 155 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 156 esp.printf("AT+CWMODE=1\r\n");//enable station mode
star297 5:efcfa9e61907 157 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 158 esp.printf("AT+CIPMUX=1\r\n");// enable multiple connections
star297 5:efcfa9e61907 159 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 160 esp.printf("AT+CIPSERVER=1,80\r\n");//start server at port 80
star297 5:efcfa9e61907 161 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 162 esp.printf("AT+CIPSTO=5\r\n");//Server timeout=5 seconds
star297 5:efcfa9e61907 163 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 164
star297 5:efcfa9e61907 165 pc.printf("Connecting to WiFi..");
star297 5:efcfa9e61907 166 char cmdbuff[60];
star297 5:efcfa9e61907 167 strcpy(cmdbuff, "AT+CWJAP_CUR=\"");
star297 5:efcfa9e61907 168 strcat(cmdbuff, ssid);
star297 5:efcfa9e61907 169 strcat(cmdbuff, "\",\"");
star297 5:efcfa9e61907 170 strcat(cmdbuff, pwd);
star297 5:efcfa9e61907 171 strcat(cmdbuff, "\"\r\n");
star297 5:efcfa9e61907 172 esp.printf(cmdbuff);
star297 5:efcfa9e61907 173 char responseFromEsp;
star297 5:efcfa9e61907 174
star297 5:efcfa9e61907 175 while(1)
star297 5:efcfa9e61907 176 {
star297 5:efcfa9e61907 177 responseFromEsp=readEspResponse();
star297 5:efcfa9e61907 178 wait_us(100000);
star297 5:efcfa9e61907 179 pc.putc('.');
star297 5:efcfa9e61907 180 if(responseFromEsp==OK || responseFromEsp==FAIL)
star297 5:efcfa9e61907 181 break;
star297 5:efcfa9e61907 182 }
star297 5:efcfa9e61907 183 pc.putc('\n');
star297 5:efcfa9e61907 184 if(responseFromEsp==OK)
star297 5:efcfa9e61907 185 {
star297 5:efcfa9e61907 186 pc.printf("Connected to Wifi\n");
star297 5:efcfa9e61907 187 __disable_irq();
star297 5:efcfa9e61907 188 esp.printf("AT+CIFSR\r\n");//check obtained IP
star297 6:9f3f0db71230 189 esp.scanf("+CIFSR:STAIP,\"%15[^\"]",serverIp);
star297 5:efcfa9e61907 190 __enable_irq();
star297 5:efcfa9e61907 191 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 192 }
star297 6:9f3f0db71230 193 if(responseFromEsp==FAIL){
star297 6:9f3f0db71230 194 pc.printf("Can't connect to Wifi\n");
star297 6:9f3f0db71230 195 while(1);
star297 6:9f3f0db71230 196 }
star297 5:efcfa9e61907 197
star297 5:efcfa9e61907 198 pc.printf("Server IP is %s\n",serverIp);
star297 5:efcfa9e61907 199
star297 5:efcfa9e61907 200 t.start();//start timer
star297 5:efcfa9e61907 201 while(1){
star297 5:efcfa9e61907 202 handleHttpRequests();
star297 5:efcfa9e61907 203 }
star297 5:efcfa9e61907 204 }
star297 5:efcfa9e61907 205
star297 5:efcfa9e61907 206 void espRxInterrupt(){
star297 5:efcfa9e61907 207 if(esp2.readable())
star297 5:efcfa9e61907 208 {
star297 5:efcfa9e61907 209 rxBuff[bufferWritingIndex++]=esp2.getc();
star297 5:efcfa9e61907 210 if(bufferWritingIndex>=BUFFER_SIZE)
star297 5:efcfa9e61907 211 bufferWritingIndex=0;
star297 5:efcfa9e61907 212 }
star297 5:efcfa9e61907 213 }
star297 5:efcfa9e61907 214
star297 5:efcfa9e61907 215 char readEspResponse(){
star297 5:efcfa9e61907 216 char rxByte;
star297 5:efcfa9e61907 217 char espResponse=UNKNOWN;
star297 5:efcfa9e61907 218 static char state=0;
star297 5:efcfa9e61907 219
star297 5:efcfa9e61907 220 while(bufferReadingIndex_espRespSearch!=bufferWritingIndex)
star297 5:efcfa9e61907 221 {
star297 5:efcfa9e61907 222 rxByte=rxBuff[bufferReadingIndex_espRespSearch++];
star297 5:efcfa9e61907 223 //pc.putc(rxByte);
star297 5:efcfa9e61907 224 if(bufferReadingIndex_espRespSearch>=BUFFER_SIZE)
star297 5:efcfa9e61907 225 bufferReadingIndex_espRespSearch=0;
star297 5:efcfa9e61907 226
star297 5:efcfa9e61907 227 switch(state)
star297 5:efcfa9e61907 228 {
star297 5:efcfa9e61907 229 case 0:
star297 5:efcfa9e61907 230 if(rxByte=='O')//it may be OK response
star297 5:efcfa9e61907 231 state=1;
star297 5:efcfa9e61907 232 else if(rxByte=='E')//it may be ERROR response
star297 5:efcfa9e61907 233 state=4;
star297 5:efcfa9e61907 234 else if(rxByte=='F')//it may be FAIL response
star297 5:efcfa9e61907 235 state=10;
star297 5:efcfa9e61907 236 else if(rxByte=='r')//it may be 'ready' response
star297 5:efcfa9e61907 237 state=15;
star297 5:efcfa9e61907 238 else if(rxByte=='>')//it may be Ready To Write TCP '>' response
star297 5:efcfa9e61907 239 state=21;
star297 5:efcfa9e61907 240 break;
star297 5:efcfa9e61907 241
star297 5:efcfa9e61907 242 case 1:
star297 5:efcfa9e61907 243 if(rxByte=='K')
star297 5:efcfa9e61907 244 state=2;
star297 5:efcfa9e61907 245 else state=0;
star297 5:efcfa9e61907 246 break;
star297 5:efcfa9e61907 247
star297 5:efcfa9e61907 248 case 2:
star297 5:efcfa9e61907 249 if(rxByte==0x0d)
star297 5:efcfa9e61907 250 state=3;
star297 5:efcfa9e61907 251 else state=0;
star297 5:efcfa9e61907 252 break;
star297 5:efcfa9e61907 253
star297 5:efcfa9e61907 254 case 3:
star297 5:efcfa9e61907 255 if(rxByte==0x0A)
star297 5:efcfa9e61907 256 espResponse=OK;
star297 5:efcfa9e61907 257 state=0;
star297 5:efcfa9e61907 258 break;
star297 5:efcfa9e61907 259
star297 5:efcfa9e61907 260 case 4://ERROR
star297 5:efcfa9e61907 261 if(rxByte=='R')
star297 5:efcfa9e61907 262 state=5;
star297 5:efcfa9e61907 263 else state=0;
star297 5:efcfa9e61907 264 break;
star297 5:efcfa9e61907 265
star297 5:efcfa9e61907 266 case 5:
star297 5:efcfa9e61907 267 if(rxByte=='R')
star297 5:efcfa9e61907 268 state=6;
star297 5:efcfa9e61907 269 else state=0;
star297 5:efcfa9e61907 270 break;
star297 5:efcfa9e61907 271
star297 5:efcfa9e61907 272 case 6:
star297 5:efcfa9e61907 273 if(rxByte=='O')
star297 5:efcfa9e61907 274 state=7;
star297 5:efcfa9e61907 275 else state=0;
star297 5:efcfa9e61907 276 break;
star297 5:efcfa9e61907 277
star297 5:efcfa9e61907 278
star297 5:efcfa9e61907 279 case 7:
star297 5:efcfa9e61907 280 if(rxByte=='R')
star297 5:efcfa9e61907 281 state=8;
star297 5:efcfa9e61907 282 else state=0;
star297 5:efcfa9e61907 283 break;
star297 5:efcfa9e61907 284
star297 5:efcfa9e61907 285 case 8:
star297 5:efcfa9e61907 286 if(rxByte==0x0d)
star297 5:efcfa9e61907 287 state=9;
star297 5:efcfa9e61907 288 else state=0;
star297 5:efcfa9e61907 289 break;
star297 5:efcfa9e61907 290
star297 5:efcfa9e61907 291 case 9:
star297 5:efcfa9e61907 292 if(rxByte==0x0A)
star297 5:efcfa9e61907 293 espResponse=ERROR;
star297 5:efcfa9e61907 294 state=0;
star297 5:efcfa9e61907 295 break;
star297 5:efcfa9e61907 296
star297 5:efcfa9e61907 297
star297 5:efcfa9e61907 298 case 10://fail
star297 5:efcfa9e61907 299 if(rxByte=='A')
star297 5:efcfa9e61907 300 state=11;
star297 5:efcfa9e61907 301 else state=0;
star297 5:efcfa9e61907 302 break;
star297 5:efcfa9e61907 303
star297 5:efcfa9e61907 304
star297 5:efcfa9e61907 305 case 11:
star297 5:efcfa9e61907 306 if(rxByte=='I')
star297 5:efcfa9e61907 307 state=12;
star297 5:efcfa9e61907 308 else state=0;
star297 5:efcfa9e61907 309 break;
star297 5:efcfa9e61907 310
star297 5:efcfa9e61907 311
star297 5:efcfa9e61907 312 case 12:
star297 5:efcfa9e61907 313 if(rxByte=='L')
star297 5:efcfa9e61907 314 state=13;
star297 5:efcfa9e61907 315 else state=0;
star297 5:efcfa9e61907 316
star297 5:efcfa9e61907 317 break;
star297 5:efcfa9e61907 318
star297 5:efcfa9e61907 319 case 13:
star297 5:efcfa9e61907 320 if(rxByte==0x0d)
star297 5:efcfa9e61907 321 state=14;
star297 5:efcfa9e61907 322 else state=0;
star297 5:efcfa9e61907 323 break;
star297 5:efcfa9e61907 324
star297 5:efcfa9e61907 325 case 14:
star297 5:efcfa9e61907 326 if(rxByte==0x0A)
star297 5:efcfa9e61907 327 espResponse=FAIL;
star297 5:efcfa9e61907 328 state=0;
star297 5:efcfa9e61907 329 break;
star297 5:efcfa9e61907 330
star297 5:efcfa9e61907 331
star297 5:efcfa9e61907 332 case 15://READY
star297 5:efcfa9e61907 333 if(rxByte=='e')
star297 5:efcfa9e61907 334 state=16;
star297 5:efcfa9e61907 335 else state=0;
star297 5:efcfa9e61907 336 break;
star297 5:efcfa9e61907 337
star297 5:efcfa9e61907 338
star297 5:efcfa9e61907 339 case 16:
star297 5:efcfa9e61907 340 if(rxByte=='a')
star297 5:efcfa9e61907 341 state=17;
star297 5:efcfa9e61907 342 else state=0;
star297 5:efcfa9e61907 343 break;
star297 5:efcfa9e61907 344
star297 5:efcfa9e61907 345 case 17:
star297 5:efcfa9e61907 346 if(rxByte=='d')
star297 5:efcfa9e61907 347 state=18;
star297 5:efcfa9e61907 348 else state=0;
star297 5:efcfa9e61907 349 break;
star297 5:efcfa9e61907 350
star297 5:efcfa9e61907 351 case 18:
star297 5:efcfa9e61907 352 if(rxByte=='y')
star297 5:efcfa9e61907 353 state=19;
star297 5:efcfa9e61907 354 else state=0;
star297 5:efcfa9e61907 355 break;
star297 5:efcfa9e61907 356
star297 5:efcfa9e61907 357 case 19:
star297 5:efcfa9e61907 358 if(rxByte==0x0d)
star297 5:efcfa9e61907 359 state=20;
star297 5:efcfa9e61907 360 else state=0;
star297 5:efcfa9e61907 361 break;
star297 5:efcfa9e61907 362
star297 5:efcfa9e61907 363 case 20:
star297 5:efcfa9e61907 364 if(rxByte==0x0A)
star297 5:efcfa9e61907 365 espResponse=READY;
star297 5:efcfa9e61907 366 state=0;
star297 5:efcfa9e61907 367 break;
star297 5:efcfa9e61907 368
star297 5:efcfa9e61907 369 case 21:
star297 5:efcfa9e61907 370 if(rxByte==0x20)
star297 5:efcfa9e61907 371 espResponse=READY_TO_WRITE_TCP;
star297 5:efcfa9e61907 372 state=0;
star297 5:efcfa9e61907 373
star297 5:efcfa9e61907 374 default:
star297 5:efcfa9e61907 375 state=0;
star297 5:efcfa9e61907 376 break;
star297 5:efcfa9e61907 377 }
star297 5:efcfa9e61907 378 }
star297 5:efcfa9e61907 379 return espResponse;
star297 5:efcfa9e61907 380 }
star297 5:efcfa9e61907 381
star297 5:efcfa9e61907 382
star297 5:efcfa9e61907 383
star297 5:efcfa9e61907 384 void handleHttpRequests(){
star297 5:efcfa9e61907 385 char rxByte;
star297 5:efcfa9e61907 386 static char state=0;
star297 5:efcfa9e61907 387
star297 5:efcfa9e61907 388 while(bufferReadingIndex_IpdSearch!=bufferWritingIndex)
star297 5:efcfa9e61907 389 {
star297 5:efcfa9e61907 390 rxByte=rxBuff[bufferReadingIndex_IpdSearch++];
star297 5:efcfa9e61907 391 //pc.putc(rxByte);
star297 5:efcfa9e61907 392 if(bufferReadingIndex_IpdSearch>=BUFFER_SIZE)
star297 5:efcfa9e61907 393 bufferReadingIndex_IpdSearch=0;
star297 5:efcfa9e61907 394 switch(state)
star297 5:efcfa9e61907 395 {
star297 5:efcfa9e61907 396 case 0:
star297 5:efcfa9e61907 397 if(rxByte=='+')
star297 5:efcfa9e61907 398 state=1;
star297 5:efcfa9e61907 399 break;
star297 5:efcfa9e61907 400
star297 5:efcfa9e61907 401 case 1:
star297 5:efcfa9e61907 402 if(rxByte=='I')
star297 5:efcfa9e61907 403 state=2;
star297 5:efcfa9e61907 404 else state=0;
star297 5:efcfa9e61907 405 break;
star297 5:efcfa9e61907 406
star297 5:efcfa9e61907 407 case 2:
star297 5:efcfa9e61907 408 if(rxByte=='P')
star297 5:efcfa9e61907 409 state=3;
star297 5:efcfa9e61907 410 else state=0;
star297 5:efcfa9e61907 411 break;
star297 5:efcfa9e61907 412
star297 5:efcfa9e61907 413 case 3:
star297 5:efcfa9e61907 414 if(rxByte=='D')
star297 5:efcfa9e61907 415 state=4;
star297 5:efcfa9e61907 416 else state=0;
star297 5:efcfa9e61907 417 break;
star297 5:efcfa9e61907 418
star297 5:efcfa9e61907 419 case 4:
star297 5:efcfa9e61907 420 if(rxByte==',')
star297 5:efcfa9e61907 421 state=5;
star297 5:efcfa9e61907 422 else state=0;
star297 5:efcfa9e61907 423 break;
star297 5:efcfa9e61907 424
star297 5:efcfa9e61907 425 case 5:
star297 5:efcfa9e61907 426 if(rxByte!=0x0d)
star297 5:efcfa9e61907 427 {
star297 5:efcfa9e61907 428 reqLineBuff[reqLinBuffIndex++]=rxByte;
star297 5:efcfa9e61907 429 }
star297 5:efcfa9e61907 430 else
star297 5:efcfa9e61907 431 {
star297 5:efcfa9e61907 432 reqLineBuff[reqLinBuffIndex]=0x00;
star297 5:efcfa9e61907 433 bufferReadingIndex_espRespSearch=bufferReadingIndex_IpdSearch;
star297 5:efcfa9e61907 434 processReqLine(reqLineBuff);
star297 5:efcfa9e61907 435 state=0;
star297 5:efcfa9e61907 436 reqLinBuffIndex=0;
star297 5:efcfa9e61907 437 }
star297 5:efcfa9e61907 438 }
star297 5:efcfa9e61907 439 }
star297 5:efcfa9e61907 440 }
star297 5:efcfa9e61907 441
star297 5:efcfa9e61907 442 void processReqLine(char *stringToProcess)
star297 5:efcfa9e61907 443 {
star297 5:efcfa9e61907 444 //0,416:GET /?led=ON HTTP/1.1
star297 5:efcfa9e61907 445 char requestType[6];
star297 5:efcfa9e61907 446 char request[50];
star297 5:efcfa9e61907 447 char linkId;
star297 5:efcfa9e61907 448 int ipdLen;
star297 5:efcfa9e61907 449 sscanf(stringToProcess,"%c,%d:%s %s",&linkId,&ipdLen,requestType,request);
star297 5:efcfa9e61907 450 pc.printf("%s\n",request);
star297 5:efcfa9e61907 451 if(request!=NULL)
star297 5:efcfa9e61907 452 {
star297 5:efcfa9e61907 453 if(strcmp(request,"/")==0 || strcmp(request,get_index_html)==0)
star297 5:efcfa9e61907 454 {
star297 5:efcfa9e61907 455 //send index.html
star297 5:efcfa9e61907 456 sendRequestedPageToClient(linkId,index_html,sizeof(index_html)-1);
star297 5:efcfa9e61907 457 }
star297 5:efcfa9e61907 458 else if(strcmp(request,get_digital_inputs_html)==0)
star297 5:efcfa9e61907 459 {
star297 5:efcfa9e61907 460 sendRequestedPageToClient(linkId,digitalInputs_html,sizeof(digitalInputs_html)-1);
star297 5:efcfa9e61907 461 }
star297 5:efcfa9e61907 462 else if(strcmp(request,get_analog_inputs_html)==0)
star297 5:efcfa9e61907 463 {
star297 5:efcfa9e61907 464 sendRequestedPageToClient(linkId,analog_inputs_html,sizeof(analog_inputs_html)-1);
star297 5:efcfa9e61907 465
star297 5:efcfa9e61907 466 }
star297 5:efcfa9e61907 467 else if(strcmp(request,get_analog_outputs)==0)
star297 5:efcfa9e61907 468 {
star297 5:efcfa9e61907 469 sendRequestedPageToClient(linkId,analog_outputs_html,sizeof(analog_outputs_html)-1);
star297 5:efcfa9e61907 470 }
star297 5:efcfa9e61907 471
star297 5:efcfa9e61907 472 else if(strcmp(request,"/images/logo.jpg")==0)
star297 5:efcfa9e61907 473 {
star297 5:efcfa9e61907 474 sendRequestedPageToClient(linkId,logo_jpg,sizeof(logo_jpg));
star297 5:efcfa9e61907 475 }
star297 5:efcfa9e61907 476 else if(strcmp(request,"/favicon.ico")==0)
star297 5:efcfa9e61907 477 {
star297 5:efcfa9e61907 478 sendRequestedPageToClient(linkId,favicon_ico,sizeof(favicon_ico));
star297 5:efcfa9e61907 479 }
star297 5:efcfa9e61907 480 else if(strcmp(request,"/css/style.css")==0)
star297 5:efcfa9e61907 481 {
star297 5:efcfa9e61907 482 sendRequestedPageToClient(linkId,style_css,sizeof(style_css)-1);
star297 5:efcfa9e61907 483 }
star297 5:efcfa9e61907 484 else if(strncmp(request,get_Toggle_Output,strlen(get_Toggle_Output))==0)
star297 5:efcfa9e61907 485 {
star297 5:efcfa9e61907 486 //check query field and value, and toggle appropriate Output
star297 5:efcfa9e61907 487 char field[10],value[10];
star297 5:efcfa9e61907 488 extractQueryFieldValue(request,field,value);
star297 5:efcfa9e61907 489 if(value!=NULL)
star297 5:efcfa9e61907 490 {
star297 5:efcfa9e61907 491 char newPinState=toggleOutput(value);
star297 5:efcfa9e61907 492 char responsePacket[100];
star297 5:efcfa9e61907 493 sprintf(responsePacket,"%s%c",textPlainHeader,newPinState+48);
star297 5:efcfa9e61907 494 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 495 }
star297 5:efcfa9e61907 496 }
star297 5:efcfa9e61907 497 else if(strcmp(request,get_digital_output_status)==0)
star297 5:efcfa9e61907 498 {
star297 5:efcfa9e61907 499 //"{\"digital_outputs\":{\"dout1\":1,\"dout2\":0,\"dout3\":1,\"dout4\":1}}"
star297 5:efcfa9e61907 500 char responsePacket[200];
star297 5:efcfa9e61907 501 sprintf(responsePacket,"%s{\"digital_outputs\":{\"dout1\":%c,\
star297 5:efcfa9e61907 502 \"dout2\":%c,\"dout3\":%c,\"dout4\":%c}}",jsonHeader,(!digital_out_1)+48,
star297 5:efcfa9e61907 503 (!digital_out_2)+48,(!digital_out_3)+48,(!digital_out_4)+48);
star297 5:efcfa9e61907 504 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 505 }
star297 5:efcfa9e61907 506 else if(strcmp(request,get_digital_input_status)==0)
star297 5:efcfa9e61907 507 {
star297 5:efcfa9e61907 508 char responsePacket[200];
star297 5:efcfa9e61907 509 sprintf(responsePacket,"%s{\"digital_inputs\":{\"din1\":%c,\
star297 5:efcfa9e61907 510 \"din2\":%c,\"din3\":%c,\"din4\":%c}}",jsonHeader,(digital_in_1)+48,
star297 5:efcfa9e61907 511 (digital_in_2)+48,(digital_in_3)+48,(digital_in_4)+48);
star297 5:efcfa9e61907 512 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 513
star297 5:efcfa9e61907 514 }
star297 5:efcfa9e61907 515 else if(strncmp(request,get_analog_output_update,strlen(get_analog_output_update))==0)
star297 5:efcfa9e61907 516 {
star297 5:efcfa9e61907 517 char field[10],value[10];
star297 5:efcfa9e61907 518 extractQueryFieldValue(request,field,value);
star297 5:efcfa9e61907 519 if(value!=NULL)
star297 5:efcfa9e61907 520 {
star297 5:efcfa9e61907 521 analog_out_1=atof(value)/12.0;
star297 5:efcfa9e61907 522 char responsePacket[100];
star297 6:9f3f0db71230 523 sprintf(responsePacket,"%s%.2f",textPlainHeader,analog_out_1.read()*12.0f);
star297 5:efcfa9e61907 524 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 525 }
star297 5:efcfa9e61907 526 }
star297 5:efcfa9e61907 527 else if(strcmp(request,get_analog_outputs_status)==0)
star297 5:efcfa9e61907 528 {
star297 5:efcfa9e61907 529 char responsePacket[100];
star297 6:9f3f0db71230 530 sprintf(responsePacket,"%s%.2f",textPlainHeader,analog_out_1.read()*12.0f);
star297 5:efcfa9e61907 531 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 532 }
star297 5:efcfa9e61907 533 else if(strcmp(request,get_analog_inputs_status)==0)
star297 5:efcfa9e61907 534 {
star297 5:efcfa9e61907 535 char responsePacket[100];
star297 6:9f3f0db71230 536 sprintf(responsePacket,"%s%.2f",textPlainHeader,((tempSensor*3.3f)-0.500f)*100.0f);
star297 5:efcfa9e61907 537 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 538 }
star297 5:efcfa9e61907 539 else
star297 5:efcfa9e61907 540 {
star297 5:efcfa9e61907 541 sendRequestedPageToClient(linkId,not_found_text,sizeof(not_found_text)-1);
star297 5:efcfa9e61907 542 //send page not found message
star297 5:efcfa9e61907 543 }
star297 5:efcfa9e61907 544 }
star297 5:efcfa9e61907 545 }
star297 5:efcfa9e61907 546
star297 5:efcfa9e61907 547
star297 5:efcfa9e61907 548 void sendRequestedPageToClient(char id, const char* page,unsigned int len)
star297 5:efcfa9e61907 549 {
star297 5:efcfa9e61907 550 char atCommandArray[50];
star297 5:efcfa9e61907 551 unsigned int lenOfPacketToTx;
star297 5:efcfa9e61907 552 unsigned int pageToSendAddress=0;
star297 5:efcfa9e61907 553 char tempEspStatus;
star297 5:efcfa9e61907 554 while(len>0)
star297 5:efcfa9e61907 555 {
star297 5:efcfa9e61907 556 if(len>2048){
star297 5:efcfa9e61907 557 len-=2048;
star297 5:efcfa9e61907 558 lenOfPacketToTx=2048;
star297 5:efcfa9e61907 559 }
star297 5:efcfa9e61907 560 else{
star297 5:efcfa9e61907 561 lenOfPacketToTx=len;
star297 5:efcfa9e61907 562 len=0;
star297 5:efcfa9e61907 563 }
star297 5:efcfa9e61907 564
star297 5:efcfa9e61907 565 sprintf(atCommandArray,"AT+CIPSEND=%c,%d\r\n",id,lenOfPacketToTx);
star297 5:efcfa9e61907 566 bufferReadingIndex_espRespSearch=bufferWritingIndex;
star297 5:efcfa9e61907 567 esp.printf(atCommandArray);
star297 5:efcfa9e61907 568
star297 5:efcfa9e61907 569 while(1)
star297 5:efcfa9e61907 570 {
star297 5:efcfa9e61907 571 tempEspStatus=readEspResponse();
star297 5:efcfa9e61907 572 if(tempEspStatus==READY_TO_WRITE_TCP||tempEspStatus==ERROR ||tempEspStatus==FAIL)
star297 5:efcfa9e61907 573 break;
star297 5:efcfa9e61907 574 }
star297 5:efcfa9e61907 575 //now send page
star297 5:efcfa9e61907 576 if(tempEspStatus==READY_TO_WRITE_TCP)
star297 5:efcfa9e61907 577 {
star297 5:efcfa9e61907 578 sendMemArrayToEsp(page+pageToSendAddress,lenOfPacketToTx);
star297 5:efcfa9e61907 579 do{
star297 5:efcfa9e61907 580 tempEspStatus=readEspResponse();
star297 5:efcfa9e61907 581 }
star297 5:efcfa9e61907 582 while(tempEspStatus==UNKNOWN);
star297 5:efcfa9e61907 583 if(tempEspStatus!=OK)//link broken, don't send more data to this link.
star297 5:efcfa9e61907 584 break;
star297 5:efcfa9e61907 585
star297 5:efcfa9e61907 586 pageToSendAddress+=lenOfPacketToTx;
star297 5:efcfa9e61907 587 }
star297 5:efcfa9e61907 588 else
star297 5:efcfa9e61907 589 break;
star297 5:efcfa9e61907 590 }
star297 5:efcfa9e61907 591 if(tempEspStatus==OK)
star297 5:efcfa9e61907 592 {
star297 5:efcfa9e61907 593 sprintf(atCommandArray,"AT+CIPCLOSE=%c\r\n",id);
star297 5:efcfa9e61907 594 esp.printf(atCommandArray);
star297 5:efcfa9e61907 595 while(readEspResponse()==UNKNOWN);
star297 5:efcfa9e61907 596 }
star297 5:efcfa9e61907 597 }
star297 5:efcfa9e61907 598
star297 5:efcfa9e61907 599 void sendMemArrayToEsp(const char*str,unsigned int len)
star297 5:efcfa9e61907 600 {
star297 5:efcfa9e61907 601 while(len--)
star297 5:efcfa9e61907 602 esp.putc(*str++);
star297 5:efcfa9e61907 603 }
star297 5:efcfa9e61907 604
star297 5:efcfa9e61907 605 void extractQueryFieldValue(char* someUrl,char* field, char* value)
star297 5:efcfa9e61907 606 {
star297 5:efcfa9e61907 607 sscanf(someUrl,"%*[^?]%*c%[^=]%*c%s",field,value);
star297 5:efcfa9e61907 608 }
star297 5:efcfa9e61907 609
star297 5:efcfa9e61907 610 char toggleOutput(char* pinName)
star297 5:efcfa9e61907 611 {
star297 5:efcfa9e61907 612 if(strcmp(pinName,"dout1")==0)
star297 5:efcfa9e61907 613 {
star297 5:efcfa9e61907 614 digital_out_1=!digital_out_1;
star297 5:efcfa9e61907 615 return !digital_out_1;
star297 5:efcfa9e61907 616 }
star297 5:efcfa9e61907 617 else if(strcmp(pinName,"dout2")==0)
star297 5:efcfa9e61907 618 {
star297 5:efcfa9e61907 619 digital_out_2=!digital_out_2;
star297 5:efcfa9e61907 620 return !digital_out_2;
star297 5:efcfa9e61907 621 }
star297 5:efcfa9e61907 622 else if(strcmp(pinName,"dout3")==0)
star297 5:efcfa9e61907 623 {
star297 5:efcfa9e61907 624 digital_out_3=!digital_out_3;
star297 5:efcfa9e61907 625 return !digital_out_3;
star297 5:efcfa9e61907 626 }
star297 5:efcfa9e61907 627 else if(strcmp(pinName,"dout4")==0)
star297 5:efcfa9e61907 628 {
star297 5:efcfa9e61907 629 digital_out_4=!digital_out_4;
star297 5:efcfa9e61907 630 return !digital_out_4;
star297 5:efcfa9e61907 631 }
star297 5:efcfa9e61907 632 else return 2;//error
star297 5:efcfa9e61907 633
star297 5:efcfa9e61907 634 }
star297 5:efcfa9e61907 635
star297 5:efcfa9e61907 636