Espruino Pico webserver #633
Replies: 34 comments
-
Posted at 2016-02-26 by DrAzzy
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-27 by @gfwilliams Just moved... as @drazzy says, there's a bunch of info on the website. You might want to look at http://www.espruino.com/Interactive+Web+UI which shows you how to use Pico + ESP8266 as a webserver that serves up a webpage with a control on it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-05 by samppa Hi @gordon, I was able to make a simple web server on Espruino Wifi board, but it stops responding http requests after awhile. It seems to depend on the http request frequency (overload); if there are several parallel requests coming the server stops output after awhile. I can still see requests coming in and handled by the web server on console window, but the response dot not go to network looking at Wireshark. And ping still goes through during the "outage". Sometimes it recovers after several minutes if the request frequency dropped. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-06 by @gfwilliams So you're saying that the requests are actually being seen by the Espruino board and handled, just not being replied to over the network? Roughly how many requests per second are you sending when this becomes a problem? Could you run You could also try My guess is it might be the ESP8266 itself though - in that case I'm not really sure what to suggest... I guess if you see some error message from the ESP8266 after doing Is it possible that the computer sending the requests has just left a bunch of connections open? In that case the ESP8266 would have to wait until they timed out before it was able to open more. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-06 by samppa Before the hand E.getErrorFlags() returned LOW_MEMORY once. wifi.at.debug() provided this lead:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-06 by ClearMemory041063 Have you installed the capacitor on the shim? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-06 by @gfwilliams I think he's using the Espruino WiFi in which case it's already got something on there.
I wouldn't worry too much about 5-10 requests a second is relatively high for it though - I wouldn't expect the ESP8266 to handle much more than that. It's just how long it takes it recover after you stop hitting it with that many requests. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-06 by samppa Yes its Espruino Wifi with embedded ESP8266. Here is better one from the failure case:
The issue is that since I cannot control the requests the server should fail gracefully, restart and not jam. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-06 by samppa During the capture above the clients timed out and did not receive anything although some requests came through and were "handled" by the Espruino but not sent to network. Or then the client timed out before the reply was ready and sent too late. So it seems there is some request queue that is longer than client side timeout. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-06 by samppa Here is my code:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-06 by @allObjects The code - assuming it supposed to run on EspruinoWifi board - messes with the pins that are used for communication of Espruino with ESP8266. Do not use any pin marked with purple box in EspruinoWifi board reference. I see that in Doing any read on a pin auto-configs the pin to input an then Espruino is / cannot properly write to ESP8266 anymore (on pin A2, for example). For ADC, use only from pin set |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-06 by samppa If you look closely I am actually using B0 and B1 to replace A2 and A3 in the code so that is not the culprit. What should be the timeout on the client side? I use 5 seconds. And 500 ms repeat interval. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by @allObjects ...my bad not noticing the replacement / mapping. I assumed you had used the sensor faking to isolate the issues. Your test proves that being swamped is not well handled yet. From what you notice is that requests still enter Espruino, but responses don't make it out anymore. Could you verify that the requests made it completely - uncorrupted - into Espruino? I have kind of the feeling that requests - respective their responses - get mingled within Espruino's async handling code. It - packet / request sequencing issues - could already have its roots within ESP8266... even though I would expect the code to be mature enough by now to handle sequencing. The next isolation level of issues is to make a test with just one way traffic - just requests and no responses - and figure out the tanking point. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by ClearMemory041063 I've had a similar issue using two Picos one Posting data and one acting as a server. Client posts data (80 characters), server receives and echos data over and over and finally it crashes with the CIPSERVER fail message. I think it has to do with the number (5) of sockets. I though it might be the capacitor on the shim but haven't had time to install them for a test. Wifi.debug() displays the socket information. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by @gfwilliams @ClearMemory041063 it'd be good if you could find a way to reproduce this? Since there can only be 5 sockets (#0..#4), Espruino's driver uses socket #5 to represent the server. It might be that the 0.60 firmware supports more sockets and so hits #5, which makes Espruino try and do server-related stuff? @samppa so that dump was during the point at which it wasn't responding? It looks like Espruino is working perfectly, so it's on the ESP8266 side. Could you try:
That sets the server timeout. It's never been an issue before, but it might allow the server to drop connections where nothing happens for 2 seconds, which should hopefully aid speedy recovery. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by @gfwilliams So there's no difference at all? I'd expected that the server might go offline, but now would recover after 2 seconds? Also, I imagine the 60 second timeout in If your webpage is actually just creating loads of connections and not closing them, I'm not sure what can be done. It's like you're making you own mini denial of service attack on the Espruino board. Maybe the server can respond with a How often are you expecting to be polling from each webpage that views the Espruino Wifi? If it's more than every few seconds them IMO you should really be using WebSockets - which will keep one connection open and allow you to update as many times as you want. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by samppa @gordon Unfortunately no help or different behavior in this case. Yes indeed the situation is like a DOS attack, but it should recover after the spam is over and that is not the case at the moment. Next I will try the wifi disconnect trick. But how the server knows when to do that since everything seems fine on that side? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by @gfwilliams So did you actually try it with the 2 second timeout in the ajax request? My guess is there are a whole bunch sockets being held open by the PC, and it's those open sockets that are blocking everything else until they finally time out. If the ESP8266 gets overwhelmed, you want the AJAX request to fail as soon as possible - then you can just try again later (you could even detect it and decrease the speed at which you issue requests). It might even be worth setting the timeout even lower than 2s. If you close all the webpages and restart them, does the server spring back into life faster? That would help to narrow it down. Also, what about the WebSocket suggestion?
Yeah, I have no idea - short of just seeing if you have no requests for a while. If you do find a way, you might find that closing the server and re-opening it solves everything, and is much faster than restarting the ESP8266. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by samppa @gordon Faster timeout on client side makes the situation worse since the request that has gone out from client cannot be aborted in a way that it would go away from the buffers on network or sever side. Therefore issuing new request after timeout just adds to the pile. The request can be aborted on the client side ajax but I think that has no effect on server side. Of course after timeout I could wait longer before issuing next request, but that is handled kind of automatically by waiting the timeout longer. Using WebSockets is a bit more complicated (not done that before and I like the idea of stateless and client agnostic server) so I would not like to go there now that the requests actually work :-) How should I close and reopen the server in a sound way (code example)? By the way, thank you so much for helping me out! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by samppa @gordon : Closing and creating the server does not seem to resolve the jam.
Should I do some deeper cleanup/reset/disconnection than just recreating the http server? Also I get these errors during the restart:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-10 by @gfwilliams The error during restart is because the server won't have been able to close instantly, but you are trying to recreate it on basically the next line. It's also possible the ESP8266 is taking a while to try and close all the active connections to the server... You could try:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-13 by samppa @gordon Thanks for the tip, but it did not help. I still get this at server startup:
Here is the inactivity checker with 2 sec delay for server start:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-13 by samppa At each code upload from IDE to EspruinoWifi I get this error:
By the way is there any way to reset or cleanup the Wifi? Would that help? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-13 by @gfwilliams Hmm, it looks like the ESP8266 is just too busy to respond - probably a reboot of the ESP8266 is required ( By the way: The ESP8266 is never contacted until It's a bit of a hack but you could use the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-13 by samppa
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-13 by samppa same for wifi.close().. wifi.disconnect() worked. Let's see if that helps.. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-13 by samppa What happens if wifi.listen fails? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-13 by @gfwilliams Ok, just do:
That'll actually power cycle the WiFi |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-13 by samppa @gordon Now it recovers! Great! Thanks! Of course that does not resolve the root cause.. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-13 by @gfwilliams I'm actually having a lot of trouble reproducing this with your code. I uploaded it to the board and added the Then I stuck your polling code in a html file set to call 5 times a second. Any more and it refused to work:
And then loaded it in 4 windows - so that's 20 requests per second. After a bit I started getting the following:
But interspersed with the correctly returned page. After closing the extra windows the board immediately returned to working correctly. So I'd say the behaviour was perfect. So I'm thinking this is probably the computer(s) that are requesting data that are still keeping connections open. Which web browser are you using on them? When you have problems, could you run:
and post the result? It's possible that connections are open and the HTTP header hasn't got through, so Espruino is just leaving sockets open waiting for a response. If so, it might be possible to add a timeout on Espruino's side that would close the connections if the header wasn't received within the first second. You could also try:
That should force Espruino to close all server connections immediately. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-02-26 by ert4
Hello i was wonder if there any why to make the pico a server to host a local webpage. I want to host a webpage to control the light on the pico itself but i don't know how to set it up on the pico or where to start.
<title>Untitled Document</title>------------------------------------HTML
Beta Was this translation helpful? Give feedback.
All reactions