WebServer and Chirp Sensor (moisture, temperature, light) on ESP8266 ESP-09 #6055
Replies: 1 comment
-
Posted at 2018-10-29 by @allObjects ...still dying after a while with:
It's a restart, but have to figure out why this Espruino on a ESP8266 happends. But before that though, I will run same app in the configuration of an Espruino with an ESP8266. Posted at 2018-10-29 by Wilberforce Have a look at your free vars and also free heap. I would say you are running out of memory. The esp8266 is quite limited in ram. Posted at 2018-10-29 by @allObjects @wilberforce, did so after start: Posted at 2018-10-30 by @MaBecker Please check your ESP8266 state in function cycle() to check if you are running out of heap space
Posted at 2018-10-30 by @MaBecker freeHeap is the one you should watch Posted at 2018-10-30 by @allObjects Free heap started out at abut 9600... went down to 7200, then backup and circling around 8800, and then, on the 50th - server side - cycle and on the 33rd - client/browser side cycle (pull data) - it crashed... with heap still 7720... and after crashing - without touching - it keeps crashing.... and crashing... and crashing,... about every minute once... with same message.
The code as below can be run in any environment with The code I'm running now is this (with the anomaly that after setting the hostname, I get weird result w/
Posted at 2018-10-30 by @MaBecker Hmm, let me try this with a debug enabled build. Posted at 2018-11-05 by maman Hello @allObjects, What is espruino version do you use ? Posted at 2018-11-05 by @allObjects @maman, thank you for this information. I will give that a try. Yes, I used 2v00, revision not known at this point, but it is ESP-09 - zero nine... Even though I think it should not really matter, because it is all the same EX chip, there could could be some difference. I have also the ESP-07S -zero - seven - S..., which I will try now for sure w/ Espruino on it. I use it though for now only as plain ESP8266 over serial / AT protocol. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-10-29 by @allObjects
Having fiddled a bit with Espruino on ESP8266 -see sister conversation Espruino on ESP8266 ESP-09 - 1 powerful cm2 - I gave this setup a shot for to play with. Final solution will most likely more go into LoRA then Wifi connection between sensors and collector / hub station, and the data will not be pulled but pushed by the sensor node. The browser / viewer wil still do a pull, but pull will not be from the (individual) sensor(s) but from the collector / hub station. For testing things though, the intervalled pull in the browser and use of local Wifi network felt just right.
Initially I used the WebServer module... but with the setup as taken from the Espruino site - w/ inline stings and anonymous function, it stopped work after abut 8..12 pulls, and it did not reconnect. I was a bit disappointed... and lacking the energy to work myself through the WebServer module. Since I served pages before using just the http module and RYO request handler function, I did that again, as you see in the code. Additionally, I converted the http response composing to ES6 Template Strings. Then I gave the WebServer module another chance - with the inline stuff 'externalized', and now it works too... at least longer than before.
The implementation uses two (2) http requests:
Some trick makes the data available to the main page for further processing/rendering/etc. That I have access to the iframe document and data with .innerHTML on the node with id data, you can see in the debug window of the browser screenshot showing parts of Web page and Espruino Web IDE console. I can even JSON parse the string and get a nice object to work with.
The iframe's
document
(DOM) makes itself accessible to the base / main / control page by setting itself as aiframeDocument
property of thetop
window. Initially I used a direct setting liketop.iframeDocument = document;
as the script in the iframe document. Now I check for the presence of thetop.setIframeDocument()
function / method and use that. Using a setter function provides easy hook into the event of new data for what ever (post) processing / rendering by the application. Instead of iframe, ajax / xhr call would do as well... but is way more code with no added benefits....Using iframe to avoid ajax and make data pull as lightweight as possible was not the only reason: initially I did serve the top, framing page with `file://...``` protocol, because I was not sure if I would have enough space in the ESP-09 for all the dhtml code... but it worked itself nicely out... still about half of the variables free... ;-) ...as you can see from stats:
The last visual attachment shows a 404 - page not found - http error... just to verify that my 404 in the RYO WebServer does what it's supposed to to.
Here is the complete code - with static and dynamic Web resources at the end:
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions