So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By oxurane
#71133
rudy wrote:Most inputs on CPUs have the option of using an internal pull up current source. And while you may not see it in the schematic can be in the electrical circuit. As long as the connection to the switch is relatively short the internal pull up is sufficient.


I fully agree. Your solution will save the use of additional electronic components. By experience I can say not many beginners crawl through a datasheet, before starting. Quite often I see the following : click a device onto a breadboard, write some code, pop it into this device and see what happens.
If just this internal pull-up/down was always implemented and explained, less starters wonder why things sometimes don't work as expected. So it's good you mentioned it. Two thumbs up !
User avatar
By Narfel
#71140 Thanks for the input. I can't offer a solution for complexity vs. teaching it beginner-friendly, but as a newbie in the field i can very much attest to a certain unchallenged "electronics is an exact science" expectation amongst total beginners. A switch is a switch right? Light and dark, hot and cold, ketchup or mayo. If it doesn't work it is broken. That kind of stuff. That's where a tutorial should at least mention the shade of grey type situation that's all too often making things more complicated as they seem. Sorry for preaching, but i just caught myself assuming that for the umpteenth time and the off-chance of reaching a fellow newbie is worth it in my book.

Back on topic (and probably another instance of me falling for it): While trying out the solutions from this thread and combining them i ran into freezing of my board and wdt resets and that got me thinking (aside from the obvious search for the error): Can the status of a frozen/crashed ESP8266 devboard be determined? I mean is there still power on the power pins, is ground still ground, pin still physically pulled up/down or is it just a lost cause like my endeavours into electronics? :? 8-) ... and to come full circle here: Can i wire up a physical solution that makes the physical switch work in such a situation where power is there but no or unknown signals from the (hanging) esp?
User avatar
By Narfel
#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 incrementing

Reloading 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.
User avatar
By schufti
#71162
philbowles wrote:As for your other question, I just don't understand what you are asking...if the code is "frozen" the WDT will physically reboot it - that's what the WDT is for - thus there is no such thing as a "hanging" ESP...(well, not for long anyway). So, often the first thing you know about the "crash" is the WDT reboot - when its then obviously too late to do anything about it and the ESP is by definiton no longer "frozen" or "crashed"...

that is not exactly true. If you have a situation that basically comes down to something like
while (1) delay(10) ;
the esp will virtually be "frozen" allthough it's factually twiddling its thumbs, without the wdt even twitching.