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:
Mon Apr 20 23:10:10 2020 +0000
Revision:
5:efcfa9e61907
Parent:
4:7334688498cc
Child:
6:9f3f0db71230
update

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 4:7334688498cc 4 // LPC1768
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 4:7334688498cc 10 DigitalOut espreset(p25,1);
star297 4:7334688498cc 11 //Connections to relay
star297 4:7334688498cc 12 //relay works at logic LOW
star297 4:7334688498cc 13 DigitalOut digital_out_1(LED1,1);// High on initialization
star297 4:7334688498cc 14 DigitalOut digital_out_2(LED2,1);// High on initialization
star297 4:7334688498cc 15 DigitalOut digital_out_3(LED3,1);// High on initialization
star297 4:7334688498cc 16 DigitalOut digital_out_4(LED4,1);// High on initialization
star297 4:7334688498cc 17 //digital inputs, connected to push buttons
star297 4:7334688498cc 18 DigitalIn digital_in_1(p21);
star297 4:7334688498cc 19 DigitalIn digital_in_2(p22);
star297 4:7334688498cc 20 DigitalIn digital_in_3(p23);
star297 4:7334688498cc 21 DigitalIn digital_in_4(p24);
star297 4:7334688498cc 22 //Analog output
star297 4:7334688498cc 23 PwmOut analog_out_1(p26);
star297 4:7334688498cc 24 //Analog Input
star297 4:7334688498cc 25 AnalogIn tempSensor(p20);
star297 0:e2a155f50119 26
star297 4:7334688498cc 27 //F401
star297 4:7334688498cc 28 /*
star297 4:7334688498cc 29 //Serial ports to be used
star297 4:7334688498cc 30 Serial pc(USBTX,USBRX);//TO BE used for debug info
star297 4:7334688498cc 31 Serial esp(D8,D2);//TX,RX TO BE CONNECTED TO ESP
star297 4:7334688498cc 32 Serial esp2(D8,D2);//TX,RX TO BE CONNECTED TO ESP
star297 4:7334688498cc 33 //Connections to relay
star297 4:7334688498cc 34 //relay works at logic LOW
star297 4:7334688498cc 35 DigitalOut digital_out_1(D3,1);// High on initialization
star297 4:7334688498cc 36 DigitalOut digital_out_2(D4,1);// High on initialization
star297 4:7334688498cc 37 DigitalOut digital_out_3(D5,1);// High on initialization
star297 4:7334688498cc 38 DigitalOut digital_out_4(D6,1);// High on initialization
star297 4:7334688498cc 39 //digital inputs, connected to push buttons
star297 4:7334688498cc 40 DigitalIn digital_in_1(A1);
star297 4:7334688498cc 41 DigitalIn digital_in_2(A2);
star297 4:7334688498cc 42 DigitalIn digital_in_3(A3);
star297 4:7334688498cc 43 DigitalIn digital_in_4(A4);
star297 4:7334688498cc 44 //Analog output
star297 4:7334688498cc 45 PwmOut analog_out_1(D15);
star297 4:7334688498cc 46 //Analog Input
star297 4:7334688498cc 47 AnalogIn tempSensor(A0);
star297 4:7334688498cc 48 */
star297 4:7334688498cc 49
star297 4:7334688498cc 50 char ssid[32] = "ssid"; // enter your router ssid inside the quotes
star297 4:7334688498cc 51 char pwd[32] = "password"; // enter your router password inside the quotes
star297 4:7334688498cc 52
star297 0:e2a155f50119 53
star297 4:7334688498cc 54 #define BUFFER_SIZE 3000
star297 4:7334688498cc 55 #define REQ_LINE_BUFF_SIZE 100
star297 4:7334688498cc 56 #define UNKNOWN 0
star297 4:7334688498cc 57 #define OK 1
star297 4:7334688498cc 58 #define ERROR 2
star297 4:7334688498cc 59 #define FAIL 3
star297 4:7334688498cc 60 #define READY 4
star297 4:7334688498cc 61 #define READY_TO_WRITE_TCP 5
star297 4:7334688498cc 62
star297 0:e2a155f50119 63
star297 4:7334688498cc 64 const char get_analog_outputs_status[]="/analog_outputs";
star297 4:7334688498cc 65 const char get_Toggle_Output[]="/digital_outputs/toggle";
star297 4:7334688498cc 66 const char get_analog_inputs_status[]="/analog_inputs";
star297 4:7334688498cc 67 const char get_analog_output_update[]="/analog_outputs/update";
star297 4:7334688498cc 68 const char get_digital_output_status[]="/digital_outputs";
star297 4:7334688498cc 69 const char get_digital_inputs_html[]="/dinputs.html";
star297 4:7334688498cc 70 const char get_digital_input_status[]="/digital_inputs";
star297 4:7334688498cc 71 const char get_index_html[]="/index.html";
star297 4:7334688498cc 72 const char get_analog_outputs[]="/anoutputs.html";
star297 4:7334688498cc 73 const char get_analog_inputs_html[]="/aninputs.html";
star297 4:7334688498cc 74
star297 4:7334688498cc 75
star297 4:7334688498cc 76 const char jsonHeader[]="HTTP/1.1 200 OK\n"
star297 4:7334688498cc 77 "Content-type: application/json\r\n\r\n";
star297 2:d4c6bc0f2dc4 78
star297 4:7334688498cc 79 const char textPlainHeader[]="HTTP/1.1 200 OK\n"
star297 4:7334688498cc 80 "Content-type: text/plain\r\n\r\n";
star297 4:7334688498cc 81
star297 4:7334688498cc 82 const char index_html[]="HTTP/1.1 200 OK\n"
star297 4:7334688498cc 83 "Content-type: text/html\r\n\r\n"
star297 4:7334688498cc 84 "<!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 85
star297 4:7334688498cc 86 const char digitalInputs_html[]="HTTP/1.1 200 OK\n"
star297 4:7334688498cc 87 "Content-type: text/html\r\n\r\n"
star297 4:7334688498cc 88 "<!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 89
star297 4:7334688498cc 90 const char analog_outputs_html[]="HTTP/1.1 200 OK\n"
star297 4:7334688498cc 91 "Content-type: text/html\r\n\r\n"
star297 5:efcfa9e61907 92 "<!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 93
star297 5:efcfa9e61907 94 const char analog_inputs_html[]="HTTP/1.1 200 OK\n"
star297 5:efcfa9e61907 95 "Content-type: text/html\r\n\r\n"
star297 5:efcfa9e61907 96 "<!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 97
star297 5:efcfa9e61907 98 const char style_css[]="HTTP/1.1 200 OK\n"
star297 5:efcfa9e61907 99 "Content-type: text/css\r\n\r\n"
star297 5:efcfa9e61907 100 "*{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 101
star297 5:efcfa9e61907 102 const char not_found_text[]="HTTP/1.1 404 Not Found\n"
star297 5:efcfa9e61907 103 "Content-type: text/plain\r\n\r\n"
star297 5:efcfa9e61907 104 "page not found";
star297 5:efcfa9e61907 105
star297 5:efcfa9e61907 106 //HTTP/1.1 200 OK
star297 5:efcfa9e61907 107 //Content-type:image/jpeg
star297 5:efcfa9e61907 108 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 109 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, 0x54, 0x4F, 0x52, 0x3A, 0x20, 0x67, 0x64, 0x2D, 0x6A, 0x70, 0x65, 0x67, 0x20,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FF, 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, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92,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x8A, 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 110
star297 5:efcfa9e61907 111 // HTTP/1.1 200 OK
star297 5:efcfa9e61907 112 //Content-type:image/x-icon
star297 5:efcfa9e61907 113 const char favicon_ico[]={0x48, 0x54, 0x54, 0x50, 0x2F, 0x31, 0x2E, 0x31, 0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 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 115
star297 5:efcfa9e61907 116 char rxBuff[BUFFER_SIZE];//array to store data received from esp
star297 5:efcfa9e61907 117 char reqLineBuff[REQ_LINE_BUFF_SIZE];
star297 5:efcfa9e61907 118 unsigned char reqLinBuffIndex=0;
star297 5:efcfa9e61907 119 unsigned int bufferWritingIndex=0;//write pointer
star297 5:efcfa9e61907 120 unsigned int bufferReadingIndex_IpdSearch=0;//read pointer
star297 5:efcfa9e61907 121 unsigned int bufferReadingIndex_espRespSearch=0;//read pointer
star297 5:efcfa9e61907 122 char serverIp[16];
star297 5:efcfa9e61907 123
star297 5:efcfa9e61907 124 Timer t;
star297 5:efcfa9e61907 125
star297 5:efcfa9e61907 126 void espRxInterrupt();
star297 5:efcfa9e61907 127 char readEspResponse();
star297 5:efcfa9e61907 128 void handleHttpRequests();
star297 5:efcfa9e61907 129 void processReqLine(char *stringToProcess);
star297 5:efcfa9e61907 130 void sendMemArrayToEsp(const char*str,unsigned int len);
star297 5:efcfa9e61907 131 void sendRequestedPageToClient(char id, const char* page,unsigned int len);
star297 5:efcfa9e61907 132 void extractQueryFieldValue(char* someUrl,char* field, char* value);
star297 5:efcfa9e61907 133 char toggleOutput(char* pinName);
star297 5:efcfa9e61907 134
star297 5:efcfa9e61907 135 int main(){
star297 5:efcfa9e61907 136 //configure Pull down on all digital inputs
star297 5:efcfa9e61907 137 digital_in_1.mode(PullDown);
star297 5:efcfa9e61907 138 digital_in_2.mode(PullDown);
star297 5:efcfa9e61907 139 digital_in_3.mode(PullDown);
star297 5:efcfa9e61907 140 digital_in_4.mode(PullDown);
star297 5:efcfa9e61907 141
star297 5:efcfa9e61907 142 //configure baud rate for UART
star297 5:efcfa9e61907 143 pc.baud(115200);
star297 5:efcfa9e61907 144 esp.baud(115200);
star297 5:efcfa9e61907 145
star297 5:efcfa9e61907 146 esp2.attach(&espRxInterrupt,Serial::RxIrq);
star297 5:efcfa9e61907 147
star297 5:efcfa9e61907 148 pc.printf("\033[0m\033[2J\033[HInitialise!\r\n\n\n");
star297 5:efcfa9e61907 149
star297 5:efcfa9e61907 150 esp.printf("AT+RST\r\n");
star297 5:efcfa9e61907 151 while(readEspResponse()!=READY);
star297 5:efcfa9e61907 152 pc.printf("Reset success\n");
star297 5:efcfa9e61907 153 esp.printf("ATE0\r\n");//disable ECHO
star297 5:efcfa9e61907 154 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 155 esp.printf("AT+CWMODE=1\r\n");//enable station mode
star297 5:efcfa9e61907 156 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 157 esp.printf("AT+CIPMUX=1\r\n");// enable multiple connections
star297 5:efcfa9e61907 158 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 159 esp.printf("AT+CIPSERVER=1,80\r\n");//start server at port 80
star297 5:efcfa9e61907 160 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 161 esp.printf("AT+CIPSTO=5\r\n");//Server timeout=5 seconds
star297 5:efcfa9e61907 162 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 163
star297 5:efcfa9e61907 164 pc.printf("Connecting to WiFi..");
star297 5:efcfa9e61907 165 char cmdbuff[60];
star297 5:efcfa9e61907 166 strcpy(cmdbuff, "AT+CWJAP_CUR=\"");
star297 5:efcfa9e61907 167 strcat(cmdbuff, ssid);
star297 5:efcfa9e61907 168 strcat(cmdbuff, "\",\"");
star297 5:efcfa9e61907 169 strcat(cmdbuff, pwd);
star297 5:efcfa9e61907 170 strcat(cmdbuff, "\"\r\n");
star297 5:efcfa9e61907 171 esp.printf(cmdbuff);
star297 5:efcfa9e61907 172 char responseFromEsp;
star297 5:efcfa9e61907 173
star297 5:efcfa9e61907 174 while(1)
star297 5:efcfa9e61907 175 {
star297 5:efcfa9e61907 176 responseFromEsp=readEspResponse();
star297 5:efcfa9e61907 177 wait_us(100000);
star297 5:efcfa9e61907 178 pc.putc('.');
star297 5:efcfa9e61907 179 if(responseFromEsp==OK || responseFromEsp==FAIL)
star297 5:efcfa9e61907 180 break;
star297 5:efcfa9e61907 181 }
star297 5:efcfa9e61907 182 pc.putc('\n');
star297 5:efcfa9e61907 183 if(responseFromEsp==OK)
star297 5:efcfa9e61907 184 {
star297 5:efcfa9e61907 185 pc.printf("Connected to Wifi\n");
star297 5:efcfa9e61907 186 __disable_irq();
star297 5:efcfa9e61907 187 esp.printf("AT+CIFSR\r\n");//check obtained IP
star297 5:efcfa9e61907 188 esp.scanf("+CIFSR:STAIP,\"%[^\"]",&serverIp);
star297 5:efcfa9e61907 189 __enable_irq();
star297 5:efcfa9e61907 190 while(readEspResponse()!=OK);
star297 5:efcfa9e61907 191 }
star297 5:efcfa9e61907 192
star297 5:efcfa9e61907 193 pc.printf("Server IP is %s\n",serverIp);
star297 5:efcfa9e61907 194
star297 5:efcfa9e61907 195 t.start();//start timer
star297 5:efcfa9e61907 196 while(1){
star297 5:efcfa9e61907 197 handleHttpRequests();
star297 5:efcfa9e61907 198 }
star297 5:efcfa9e61907 199 }
star297 5:efcfa9e61907 200
star297 5:efcfa9e61907 201 void espRxInterrupt(){
star297 5:efcfa9e61907 202 if(esp2.readable())
star297 5:efcfa9e61907 203 {
star297 5:efcfa9e61907 204 rxBuff[bufferWritingIndex++]=esp2.getc();
star297 5:efcfa9e61907 205 if(bufferWritingIndex>=BUFFER_SIZE)
star297 5:efcfa9e61907 206 bufferWritingIndex=0;
star297 5:efcfa9e61907 207 }
star297 5:efcfa9e61907 208 }
star297 5:efcfa9e61907 209
star297 5:efcfa9e61907 210 char readEspResponse(){
star297 5:efcfa9e61907 211 char rxByte;
star297 5:efcfa9e61907 212 char espResponse=UNKNOWN;
star297 5:efcfa9e61907 213 static char state=0;
star297 5:efcfa9e61907 214
star297 5:efcfa9e61907 215 while(bufferReadingIndex_espRespSearch!=bufferWritingIndex)
star297 5:efcfa9e61907 216 {
star297 5:efcfa9e61907 217 rxByte=rxBuff[bufferReadingIndex_espRespSearch++];
star297 5:efcfa9e61907 218 //pc.putc(rxByte);
star297 5:efcfa9e61907 219 if(bufferReadingIndex_espRespSearch>=BUFFER_SIZE)
star297 5:efcfa9e61907 220 bufferReadingIndex_espRespSearch=0;
star297 5:efcfa9e61907 221
star297 5:efcfa9e61907 222 switch(state)
star297 5:efcfa9e61907 223 {
star297 5:efcfa9e61907 224 case 0:
star297 5:efcfa9e61907 225 if(rxByte=='O')//it may be OK response
star297 5:efcfa9e61907 226 state=1;
star297 5:efcfa9e61907 227 else if(rxByte=='E')//it may be ERROR response
star297 5:efcfa9e61907 228 state=4;
star297 5:efcfa9e61907 229 else if(rxByte=='F')//it may be FAIL response
star297 5:efcfa9e61907 230 state=10;
star297 5:efcfa9e61907 231 else if(rxByte=='r')//it may be 'ready' response
star297 5:efcfa9e61907 232 state=15;
star297 5:efcfa9e61907 233 else if(rxByte=='>')//it may be Ready To Write TCP '>' response
star297 5:efcfa9e61907 234 state=21;
star297 5:efcfa9e61907 235 break;
star297 5:efcfa9e61907 236
star297 5:efcfa9e61907 237 case 1:
star297 5:efcfa9e61907 238 if(rxByte=='K')
star297 5:efcfa9e61907 239 state=2;
star297 5:efcfa9e61907 240 else state=0;
star297 5:efcfa9e61907 241 break;
star297 5:efcfa9e61907 242
star297 5:efcfa9e61907 243 case 2:
star297 5:efcfa9e61907 244 if(rxByte==0x0d)
star297 5:efcfa9e61907 245 state=3;
star297 5:efcfa9e61907 246 else state=0;
star297 5:efcfa9e61907 247 break;
star297 5:efcfa9e61907 248
star297 5:efcfa9e61907 249 case 3:
star297 5:efcfa9e61907 250 if(rxByte==0x0A)
star297 5:efcfa9e61907 251 espResponse=OK;
star297 5:efcfa9e61907 252 state=0;
star297 5:efcfa9e61907 253 break;
star297 5:efcfa9e61907 254
star297 5:efcfa9e61907 255 case 4://ERROR
star297 5:efcfa9e61907 256 if(rxByte=='R')
star297 5:efcfa9e61907 257 state=5;
star297 5:efcfa9e61907 258 else state=0;
star297 5:efcfa9e61907 259 break;
star297 5:efcfa9e61907 260
star297 5:efcfa9e61907 261 case 5:
star297 5:efcfa9e61907 262 if(rxByte=='R')
star297 5:efcfa9e61907 263 state=6;
star297 5:efcfa9e61907 264 else state=0;
star297 5:efcfa9e61907 265 break;
star297 5:efcfa9e61907 266
star297 5:efcfa9e61907 267 case 6:
star297 5:efcfa9e61907 268 if(rxByte=='O')
star297 5:efcfa9e61907 269 state=7;
star297 5:efcfa9e61907 270 else state=0;
star297 5:efcfa9e61907 271 break;
star297 5:efcfa9e61907 272
star297 5:efcfa9e61907 273
star297 5:efcfa9e61907 274 case 7:
star297 5:efcfa9e61907 275 if(rxByte=='R')
star297 5:efcfa9e61907 276 state=8;
star297 5:efcfa9e61907 277 else state=0;
star297 5:efcfa9e61907 278 break;
star297 5:efcfa9e61907 279
star297 5:efcfa9e61907 280 case 8:
star297 5:efcfa9e61907 281 if(rxByte==0x0d)
star297 5:efcfa9e61907 282 state=9;
star297 5:efcfa9e61907 283 else state=0;
star297 5:efcfa9e61907 284 break;
star297 5:efcfa9e61907 285
star297 5:efcfa9e61907 286 case 9:
star297 5:efcfa9e61907 287 if(rxByte==0x0A)
star297 5:efcfa9e61907 288 espResponse=ERROR;
star297 5:efcfa9e61907 289 state=0;
star297 5:efcfa9e61907 290 break;
star297 5:efcfa9e61907 291
star297 5:efcfa9e61907 292
star297 5:efcfa9e61907 293 case 10://fail
star297 5:efcfa9e61907 294 if(rxByte=='A')
star297 5:efcfa9e61907 295 state=11;
star297 5:efcfa9e61907 296 else state=0;
star297 5:efcfa9e61907 297 break;
star297 5:efcfa9e61907 298
star297 5:efcfa9e61907 299
star297 5:efcfa9e61907 300 case 11:
star297 5:efcfa9e61907 301 if(rxByte=='I')
star297 5:efcfa9e61907 302 state=12;
star297 5:efcfa9e61907 303 else state=0;
star297 5:efcfa9e61907 304 break;
star297 5:efcfa9e61907 305
star297 5:efcfa9e61907 306
star297 5:efcfa9e61907 307 case 12:
star297 5:efcfa9e61907 308 if(rxByte=='L')
star297 5:efcfa9e61907 309 state=13;
star297 5:efcfa9e61907 310 else state=0;
star297 5:efcfa9e61907 311
star297 5:efcfa9e61907 312 break;
star297 5:efcfa9e61907 313
star297 5:efcfa9e61907 314 case 13:
star297 5:efcfa9e61907 315 if(rxByte==0x0d)
star297 5:efcfa9e61907 316 state=14;
star297 5:efcfa9e61907 317 else state=0;
star297 5:efcfa9e61907 318 break;
star297 5:efcfa9e61907 319
star297 5:efcfa9e61907 320 case 14:
star297 5:efcfa9e61907 321 if(rxByte==0x0A)
star297 5:efcfa9e61907 322 espResponse=FAIL;
star297 5:efcfa9e61907 323 state=0;
star297 5:efcfa9e61907 324 break;
star297 5:efcfa9e61907 325
star297 5:efcfa9e61907 326
star297 5:efcfa9e61907 327 case 15://READY
star297 5:efcfa9e61907 328 if(rxByte=='e')
star297 5:efcfa9e61907 329 state=16;
star297 5:efcfa9e61907 330 else state=0;
star297 5:efcfa9e61907 331 break;
star297 5:efcfa9e61907 332
star297 5:efcfa9e61907 333
star297 5:efcfa9e61907 334 case 16:
star297 5:efcfa9e61907 335 if(rxByte=='a')
star297 5:efcfa9e61907 336 state=17;
star297 5:efcfa9e61907 337 else state=0;
star297 5:efcfa9e61907 338 break;
star297 5:efcfa9e61907 339
star297 5:efcfa9e61907 340 case 17:
star297 5:efcfa9e61907 341 if(rxByte=='d')
star297 5:efcfa9e61907 342 state=18;
star297 5:efcfa9e61907 343 else state=0;
star297 5:efcfa9e61907 344 break;
star297 5:efcfa9e61907 345
star297 5:efcfa9e61907 346 case 18:
star297 5:efcfa9e61907 347 if(rxByte=='y')
star297 5:efcfa9e61907 348 state=19;
star297 5:efcfa9e61907 349 else state=0;
star297 5:efcfa9e61907 350 break;
star297 5:efcfa9e61907 351
star297 5:efcfa9e61907 352 case 19:
star297 5:efcfa9e61907 353 if(rxByte==0x0d)
star297 5:efcfa9e61907 354 state=20;
star297 5:efcfa9e61907 355 else state=0;
star297 5:efcfa9e61907 356 break;
star297 5:efcfa9e61907 357
star297 5:efcfa9e61907 358 case 20:
star297 5:efcfa9e61907 359 if(rxByte==0x0A)
star297 5:efcfa9e61907 360 espResponse=READY;
star297 5:efcfa9e61907 361 state=0;
star297 5:efcfa9e61907 362 break;
star297 5:efcfa9e61907 363
star297 5:efcfa9e61907 364 case 21:
star297 5:efcfa9e61907 365 if(rxByte==0x20)
star297 5:efcfa9e61907 366 espResponse=READY_TO_WRITE_TCP;
star297 5:efcfa9e61907 367 state=0;
star297 5:efcfa9e61907 368
star297 5:efcfa9e61907 369 default:
star297 5:efcfa9e61907 370 state=0;
star297 5:efcfa9e61907 371 break;
star297 5:efcfa9e61907 372 }
star297 5:efcfa9e61907 373 }
star297 5:efcfa9e61907 374 return espResponse;
star297 5:efcfa9e61907 375 }
star297 5:efcfa9e61907 376
star297 5:efcfa9e61907 377
star297 5:efcfa9e61907 378
star297 5:efcfa9e61907 379 void handleHttpRequests(){
star297 5:efcfa9e61907 380 char rxByte;
star297 5:efcfa9e61907 381 static char state=0;
star297 5:efcfa9e61907 382
star297 5:efcfa9e61907 383 while(bufferReadingIndex_IpdSearch!=bufferWritingIndex)
star297 5:efcfa9e61907 384 {
star297 5:efcfa9e61907 385 rxByte=rxBuff[bufferReadingIndex_IpdSearch++];
star297 5:efcfa9e61907 386 //pc.putc(rxByte);
star297 5:efcfa9e61907 387 if(bufferReadingIndex_IpdSearch>=BUFFER_SIZE)
star297 5:efcfa9e61907 388 bufferReadingIndex_IpdSearch=0;
star297 5:efcfa9e61907 389 switch(state)
star297 5:efcfa9e61907 390 {
star297 5:efcfa9e61907 391 case 0:
star297 5:efcfa9e61907 392 if(rxByte=='+')
star297 5:efcfa9e61907 393 state=1;
star297 5:efcfa9e61907 394 break;
star297 5:efcfa9e61907 395
star297 5:efcfa9e61907 396 case 1:
star297 5:efcfa9e61907 397 if(rxByte=='I')
star297 5:efcfa9e61907 398 state=2;
star297 5:efcfa9e61907 399 else state=0;
star297 5:efcfa9e61907 400 break;
star297 5:efcfa9e61907 401
star297 5:efcfa9e61907 402 case 2:
star297 5:efcfa9e61907 403 if(rxByte=='P')
star297 5:efcfa9e61907 404 state=3;
star297 5:efcfa9e61907 405 else state=0;
star297 5:efcfa9e61907 406 break;
star297 5:efcfa9e61907 407
star297 5:efcfa9e61907 408 case 3:
star297 5:efcfa9e61907 409 if(rxByte=='D')
star297 5:efcfa9e61907 410 state=4;
star297 5:efcfa9e61907 411 else state=0;
star297 5:efcfa9e61907 412 break;
star297 5:efcfa9e61907 413
star297 5:efcfa9e61907 414 case 4:
star297 5:efcfa9e61907 415 if(rxByte==',')
star297 5:efcfa9e61907 416 state=5;
star297 5:efcfa9e61907 417 else state=0;
star297 5:efcfa9e61907 418 break;
star297 5:efcfa9e61907 419
star297 5:efcfa9e61907 420 case 5:
star297 5:efcfa9e61907 421 if(rxByte!=0x0d)
star297 5:efcfa9e61907 422 {
star297 5:efcfa9e61907 423 reqLineBuff[reqLinBuffIndex++]=rxByte;
star297 5:efcfa9e61907 424 }
star297 5:efcfa9e61907 425 else
star297 5:efcfa9e61907 426 {
star297 5:efcfa9e61907 427 reqLineBuff[reqLinBuffIndex]=0x00;
star297 5:efcfa9e61907 428 bufferReadingIndex_espRespSearch=bufferReadingIndex_IpdSearch;
star297 5:efcfa9e61907 429 processReqLine(reqLineBuff);
star297 5:efcfa9e61907 430 state=0;
star297 5:efcfa9e61907 431 reqLinBuffIndex=0;
star297 5:efcfa9e61907 432 }
star297 5:efcfa9e61907 433 }
star297 5:efcfa9e61907 434 }
star297 5:efcfa9e61907 435 }
star297 5:efcfa9e61907 436
star297 5:efcfa9e61907 437 void processReqLine(char *stringToProcess)
star297 5:efcfa9e61907 438 {
star297 5:efcfa9e61907 439 //0,416:GET /?led=ON HTTP/1.1
star297 5:efcfa9e61907 440 char requestType[6];
star297 5:efcfa9e61907 441 char request[50];
star297 5:efcfa9e61907 442 char linkId;
star297 5:efcfa9e61907 443 int ipdLen;
star297 5:efcfa9e61907 444 sscanf(stringToProcess,"%c,%d:%s %s",&linkId,&ipdLen,requestType,request);
star297 5:efcfa9e61907 445 pc.printf("%s\n",request);
star297 5:efcfa9e61907 446 if(request!=NULL)
star297 5:efcfa9e61907 447 {
star297 5:efcfa9e61907 448 if(strcmp(request,"/")==0 || strcmp(request,get_index_html)==0)
star297 5:efcfa9e61907 449 {
star297 5:efcfa9e61907 450 //send index.html
star297 5:efcfa9e61907 451 sendRequestedPageToClient(linkId,index_html,sizeof(index_html)-1);
star297 5:efcfa9e61907 452 }
star297 5:efcfa9e61907 453 else if(strcmp(request,get_digital_inputs_html)==0)
star297 5:efcfa9e61907 454 {
star297 5:efcfa9e61907 455 sendRequestedPageToClient(linkId,digitalInputs_html,sizeof(digitalInputs_html)-1);
star297 5:efcfa9e61907 456 }
star297 5:efcfa9e61907 457 else if(strcmp(request,get_analog_inputs_html)==0)
star297 5:efcfa9e61907 458 {
star297 5:efcfa9e61907 459 sendRequestedPageToClient(linkId,analog_inputs_html,sizeof(analog_inputs_html)-1);
star297 5:efcfa9e61907 460
star297 5:efcfa9e61907 461 }
star297 5:efcfa9e61907 462 else if(strcmp(request,get_analog_outputs)==0)
star297 5:efcfa9e61907 463 {
star297 5:efcfa9e61907 464 sendRequestedPageToClient(linkId,analog_outputs_html,sizeof(analog_outputs_html)-1);
star297 5:efcfa9e61907 465 }
star297 5:efcfa9e61907 466
star297 5:efcfa9e61907 467 else if(strcmp(request,"/images/logo.jpg")==0)
star297 5:efcfa9e61907 468 {
star297 5:efcfa9e61907 469 sendRequestedPageToClient(linkId,logo_jpg,sizeof(logo_jpg));
star297 5:efcfa9e61907 470 }
star297 5:efcfa9e61907 471 else if(strcmp(request,"/favicon.ico")==0)
star297 5:efcfa9e61907 472 {
star297 5:efcfa9e61907 473 sendRequestedPageToClient(linkId,favicon_ico,sizeof(favicon_ico));
star297 5:efcfa9e61907 474 }
star297 5:efcfa9e61907 475 else if(strcmp(request,"/css/style.css")==0)
star297 5:efcfa9e61907 476 {
star297 5:efcfa9e61907 477 sendRequestedPageToClient(linkId,style_css,sizeof(style_css)-1);
star297 5:efcfa9e61907 478 }
star297 5:efcfa9e61907 479 else if(strncmp(request,get_Toggle_Output,strlen(get_Toggle_Output))==0)
star297 5:efcfa9e61907 480 {
star297 5:efcfa9e61907 481 //check query field and value, and toggle appropriate Output
star297 5:efcfa9e61907 482 char field[10],value[10];
star297 5:efcfa9e61907 483 extractQueryFieldValue(request,field,value);
star297 5:efcfa9e61907 484 if(value!=NULL)
star297 5:efcfa9e61907 485 {
star297 5:efcfa9e61907 486 char newPinState=toggleOutput(value);
star297 5:efcfa9e61907 487 char responsePacket[100];
star297 5:efcfa9e61907 488 sprintf(responsePacket,"%s%c",textPlainHeader,newPinState+48);
star297 5:efcfa9e61907 489 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 490 }
star297 5:efcfa9e61907 491 }
star297 5:efcfa9e61907 492 else if(strcmp(request,get_digital_output_status)==0)
star297 5:efcfa9e61907 493 {
star297 5:efcfa9e61907 494 //"{\"digital_outputs\":{\"dout1\":1,\"dout2\":0,\"dout3\":1,\"dout4\":1}}"
star297 5:efcfa9e61907 495 char responsePacket[200];
star297 5:efcfa9e61907 496 sprintf(responsePacket,"%s{\"digital_outputs\":{\"dout1\":%c,\
star297 5:efcfa9e61907 497 \"dout2\":%c,\"dout3\":%c,\"dout4\":%c}}",jsonHeader,(!digital_out_1)+48,
star297 5:efcfa9e61907 498 (!digital_out_2)+48,(!digital_out_3)+48,(!digital_out_4)+48);
star297 5:efcfa9e61907 499 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 500 }
star297 5:efcfa9e61907 501 else if(strcmp(request,get_digital_input_status)==0)
star297 5:efcfa9e61907 502 {
star297 5:efcfa9e61907 503 char responsePacket[200];
star297 5:efcfa9e61907 504 sprintf(responsePacket,"%s{\"digital_inputs\":{\"din1\":%c,\
star297 5:efcfa9e61907 505 \"din2\":%c,\"din3\":%c,\"din4\":%c}}",jsonHeader,(digital_in_1)+48,
star297 5:efcfa9e61907 506 (digital_in_2)+48,(digital_in_3)+48,(digital_in_4)+48);
star297 5:efcfa9e61907 507 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 508
star297 5:efcfa9e61907 509 }
star297 5:efcfa9e61907 510 else if(strncmp(request,get_analog_output_update,strlen(get_analog_output_update))==0)
star297 5:efcfa9e61907 511 {
star297 5:efcfa9e61907 512 char field[10],value[10];
star297 5:efcfa9e61907 513 extractQueryFieldValue(request,field,value);
star297 5:efcfa9e61907 514 if(value!=NULL)
star297 5:efcfa9e61907 515 {
star297 5:efcfa9e61907 516 analog_out_1=atof(value)/12.0;
star297 5:efcfa9e61907 517 char responsePacket[100];
star297 5:efcfa9e61907 518 sprintf(responsePacket,"%s%.2f",textPlainHeader,analog_out_1.read()*12.0);
star297 5:efcfa9e61907 519 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 520 }
star297 5:efcfa9e61907 521 }
star297 5:efcfa9e61907 522 else if(strcmp(request,get_analog_outputs_status)==0)
star297 5:efcfa9e61907 523 {
star297 5:efcfa9e61907 524 char responsePacket[100];
star297 5:efcfa9e61907 525 sprintf(responsePacket,"%s%.2f",textPlainHeader,analog_out_1.read()*12.0);
star297 5:efcfa9e61907 526 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 527 }
star297 5:efcfa9e61907 528 else if(strcmp(request,get_analog_inputs_status)==0)
star297 5:efcfa9e61907 529 {
star297 5:efcfa9e61907 530 char responsePacket[100];
star297 5:efcfa9e61907 531 sprintf(responsePacket,"%s%.2f",textPlainHeader,((tempSensor*3.3)-0.500)*100.0);
star297 5:efcfa9e61907 532 sendRequestedPageToClient(linkId,responsePacket,strlen(responsePacket));
star297 5:efcfa9e61907 533 }
star297 5:efcfa9e61907 534 else
star297 5:efcfa9e61907 535 {
star297 5:efcfa9e61907 536 sendRequestedPageToClient(linkId,not_found_text,sizeof(not_found_text)-1);
star297 5:efcfa9e61907 537 //send page not found message
star297 5:efcfa9e61907 538 }
star297 5:efcfa9e61907 539 }
star297 5:efcfa9e61907 540 }
star297 5:efcfa9e61907 541
star297 5:efcfa9e61907 542
star297 5:efcfa9e61907 543 void sendRequestedPageToClient(char id, const char* page,unsigned int len)
star297 5:efcfa9e61907 544 {
star297 5:efcfa9e61907 545 char atCommandArray[50];
star297 5:efcfa9e61907 546 unsigned int lenOfPacketToTx;
star297 5:efcfa9e61907 547 unsigned int pageToSendAddress=0;
star297 5:efcfa9e61907 548 char tempEspStatus;
star297 5:efcfa9e61907 549 while(len>0)
star297 5:efcfa9e61907 550 {
star297 5:efcfa9e61907 551 if(len>2048){
star297 5:efcfa9e61907 552 len-=2048;
star297 5:efcfa9e61907 553 lenOfPacketToTx=2048;
star297 5:efcfa9e61907 554 }
star297 5:efcfa9e61907 555 else{
star297 5:efcfa9e61907 556 lenOfPacketToTx=len;
star297 5:efcfa9e61907 557 len=0;
star297 5:efcfa9e61907 558 }
star297 5:efcfa9e61907 559
star297 5:efcfa9e61907 560 sprintf(atCommandArray,"AT+CIPSEND=%c,%d\r\n",id,lenOfPacketToTx);
star297 5:efcfa9e61907 561 bufferReadingIndex_espRespSearch=bufferWritingIndex;
star297 5:efcfa9e61907 562 esp.printf(atCommandArray);
star297 5:efcfa9e61907 563
star297 5:efcfa9e61907 564 while(1)
star297 5:efcfa9e61907 565 {
star297 5:efcfa9e61907 566 tempEspStatus=readEspResponse();
star297 5:efcfa9e61907 567 if(tempEspStatus==READY_TO_WRITE_TCP||tempEspStatus==ERROR ||tempEspStatus==FAIL)
star297 5:efcfa9e61907 568 break;
star297 5:efcfa9e61907 569 }
star297 5:efcfa9e61907 570 //now send page
star297 5:efcfa9e61907 571 if(tempEspStatus==READY_TO_WRITE_TCP)
star297 5:efcfa9e61907 572 {
star297 5:efcfa9e61907 573 sendMemArrayToEsp(page+pageToSendAddress,lenOfPacketToTx);
star297 5:efcfa9e61907 574 do{
star297 5:efcfa9e61907 575 tempEspStatus=readEspResponse();
star297 5:efcfa9e61907 576 }
star297 5:efcfa9e61907 577 while(tempEspStatus==UNKNOWN);
star297 5:efcfa9e61907 578 if(tempEspStatus!=OK)//link broken, don't send more data to this link.
star297 5:efcfa9e61907 579 break;
star297 5:efcfa9e61907 580
star297 5:efcfa9e61907 581 pageToSendAddress+=lenOfPacketToTx;
star297 5:efcfa9e61907 582 }
star297 5:efcfa9e61907 583 else
star297 5:efcfa9e61907 584 break;
star297 5:efcfa9e61907 585 }
star297 5:efcfa9e61907 586 if(tempEspStatus==OK)
star297 5:efcfa9e61907 587 {
star297 5:efcfa9e61907 588 sprintf(atCommandArray,"AT+CIPCLOSE=%c\r\n",id);
star297 5:efcfa9e61907 589 esp.printf(atCommandArray);
star297 5:efcfa9e61907 590 while(readEspResponse()==UNKNOWN);
star297 5:efcfa9e61907 591 }
star297 5:efcfa9e61907 592 }
star297 5:efcfa9e61907 593
star297 5:efcfa9e61907 594 void sendMemArrayToEsp(const char*str,unsigned int len)
star297 5:efcfa9e61907 595 {
star297 5:efcfa9e61907 596 while(len--)
star297 5:efcfa9e61907 597 esp.putc(*str++);
star297 5:efcfa9e61907 598 }
star297 5:efcfa9e61907 599
star297 5:efcfa9e61907 600 void extractQueryFieldValue(char* someUrl,char* field, char* value)
star297 5:efcfa9e61907 601 {
star297 5:efcfa9e61907 602 sscanf(someUrl,"%*[^?]%*c%[^=]%*c%s",field,value);
star297 5:efcfa9e61907 603 }
star297 5:efcfa9e61907 604
star297 5:efcfa9e61907 605 char toggleOutput(char* pinName)
star297 5:efcfa9e61907 606 {
star297 5:efcfa9e61907 607 if(strcmp(pinName,"dout1")==0)
star297 5:efcfa9e61907 608 {
star297 5:efcfa9e61907 609 digital_out_1=!digital_out_1;
star297 5:efcfa9e61907 610 return !digital_out_1;
star297 5:efcfa9e61907 611 }
star297 5:efcfa9e61907 612 else if(strcmp(pinName,"dout2")==0)
star297 5:efcfa9e61907 613 {
star297 5:efcfa9e61907 614 digital_out_2=!digital_out_2;
star297 5:efcfa9e61907 615 return !digital_out_2;
star297 5:efcfa9e61907 616 }
star297 5:efcfa9e61907 617 else if(strcmp(pinName,"dout3")==0)
star297 5:efcfa9e61907 618 {
star297 5:efcfa9e61907 619 digital_out_3=!digital_out_3;
star297 5:efcfa9e61907 620 return !digital_out_3;
star297 5:efcfa9e61907 621 }
star297 5:efcfa9e61907 622 else if(strcmp(pinName,"dout4")==0)
star297 5:efcfa9e61907 623 {
star297 5:efcfa9e61907 624 digital_out_4=!digital_out_4;
star297 5:efcfa9e61907 625 return !digital_out_4;
star297 5:efcfa9e61907 626 }
star297 5:efcfa9e61907 627 else return 2;//error
star297 5:efcfa9e61907 628
star297 5:efcfa9e61907 629 }
star297 5:efcfa9e61907 630
star297 5:efcfa9e61907 631