- Tue Oct 24, 2017 1:09 am
#71157
Let me try in plain english because i'm afraid it obfuscates my lack of knowledge if i try otherwise. I know know i mixed two issues together:
1. Wdt reset occured when i started expanding the button handling code from this thread with ota, a simple counter and website code to make it prettier. I got the boot code 1,6 which according to your linked issue (thanks by the way) is
(resetInfo.reason == REASON_SOFT_RESTART) { // software restart ,system_restart , GPIO status won’t change. I shelved that for now because i thought it'd to be a natural thing to run into due to adding complexity and precisely one of the reason why you created esparto.
2. The freezing issue (in absence of any console or debug data) is really just no reaction at all from the esp after 3-5min of running a ajax timer (see below). Before you gave me that info about the boot code i assumed (<-
) the issues are the same. Since the second has no ota i think those are worlds apart.
Freezing:
1) the Ajax Code stops in the browser:
This is the ESP website ...
Runtime = 00:06:24
<-- this timer stops incrementingReloading the website eventually leads to 192.168.1.104 took too long to respond.
2) The serial console shows nothing. Just the boot messages. The only lifesign is minuscule amounts of power drawn. After a manual reset works fine (until it freezes up again)
for reference the code from
http://www.esp8266.com/viewtopic.php?p=24807#p24807, which many people answered and expanded upon so i thought it to be fairly stable for a test. My end goal was to use the code to have a checkbox imitating a real life light switch and styling it from white to green background with ajax to avoid calling a whole url.
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
ESP8266WebServer server(80);
const char* ssid="SSID";
const char* password="PASSWORD";
String webSite,javaScript,XML;
void buildWebsite(){
buildJavascript();
webSite="<!DOCTYPE HTML>\n";
webSite+=javaScript;
webSite+="<BODY onload='process()'>\n";
webSite+="<BR>This is the ESP website ...<BR>\n";
webSite+="Runtime = <A id='runtime'></A>\n";
webSite+="</BODY>\n";
webSite+="</HTML>\n";
}
void buildJavascript(){
javaScript="<SCRIPT>\n";
javaScript+="var xmlHttp=createXmlHttpObject();\n";
javaScript+="function createXmlHttpObject(){\n";
javaScript+=" if(window.XMLHttpRequest){\n";
javaScript+=" xmlHttp=new XMLHttpRequest();\n";
javaScript+=" }else{\n";
javaScript+=" xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');\n";
javaScript+=" }\n";
javaScript+=" return xmlHttp;\n";
javaScript+="}\n";
javaScript+="function process(){\n";
javaScript+=" if(xmlHttp.readyState==0 || xmlHttp.readyState==4){\n";
javaScript+=" xmlHttp.open('PUT','xml',true);\n";
javaScript+=" xmlHttp.onreadystatechange=handleServerResponse;\n"; // no brackets?????
javaScript+=" xmlHttp.send(null);\n";
javaScript+=" }\n";
javaScript+=" setTimeout('process()',1000);\n";
javaScript+="}\n";
javaScript+="function handleServerResponse(){\n";
javaScript+=" if(xmlHttp.readyState==4 && xmlHttp.status==200){\n";
javaScript+=" xmlResponse=xmlHttp.responseXML;\n";
javaScript+=" xmldoc = xmlResponse.getElementsByTagName('response');\n";
javaScript+=" message = xmldoc[0].firstChild.nodeValue;\n";
javaScript+=" document.getElementById('runtime').innerHTML=message;\n";
javaScript+=" }\n";
javaScript+="}\n";
javaScript+="</SCRIPT>\n";
}
void buildXML(){
XML="<?xml version='1.0'?>";
XML+="<response>";
XML+=millis2time();
XML+="</response>";
}
String millis2time(){
String Time="";
unsigned long ss;
byte mm,hh;
ss=millis()/1000;
hh=ss/3600;
mm=(ss-hh*3600)/60;
ss=(ss-hh*3600)-mm*60;
if(hh<10)Time+="0";
Time+=(String)hh+":";
if(mm<10)Time+="0";
Time+=(String)mm+":";
if(ss<10)Time+="0";
Time+=(String)ss;
return Time;
}
void handleWebsite(){
buildWebsite();
server.send(200,"text/html",webSite);
}
void handleXML(){
buildXML();
server.send(200,"text/xml",XML);
}
void setup() {
Serial.begin(115200);
WiFi.begin(ssid,password);
while(WiFi.status()!=WL_CONNECTED)delay(500);
WiFi.mode(WIFI_STA);
Serial.println("\n\nBOOTING ESP8266 ...");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("Station IP address: ");
Serial.println(WiFi.localIP());
server.on("/",handleWebsite);
server.on("/xml",handleXML);
server.begin();
}
void loop() {
server.handleClient();
}
And finally:
Do you mean to have the switch and the ESP GPIO fed into an OR-gate so that either will cause the out put?
Uhm, to be honest that sounds exactly what i want. I will however have to read up on that.
Last edited by Narfel on Tue Oct 24, 2017 6:50 am, edited 1 time in total.
Under normal circumstances i never let fear and good judgment stand in the way of a hearty laugh. ~AvE