MicroWebSrv icon indicating copy to clipboard operation
MicroWebSrv copied to clipboard

Error 112 on ESP32

Open arpadtamasi opened this issue 6 years ago • 13 comments

During development every time I download a new version, I got the following trace: Traceback (most recent call last): File "", line 1, in File "", line 34, in File "microWebSrv.py", line 224, in Start OSError: 112

arpadtamasi avatar Jul 31 '19 11:07 arpadtamasi

Hi there,

first things first: Thanks Jean-Christophe for conceiving this excellent piece of software!

While developing the Terkin Datalogger [1] (as well on ESP32 with Pycom MicroPython), we probably experienced the same thing as @arpadtamasi:

   22.3080 [terkin.api.http          ] INFO   : Setting up HTTP API
   22.4902 [terkin.api.http          ] INFO   : Starting HTTP server
Traceback (most recent call last):
  File "main.py", line 65, in <module>
  File "main.py", line 60, in main
  File "/flash/lib/terkin/datalogger.py", line 130, in start
  File "/flash/lib/terkin/device.py", line 211, in start_network_services
  File "/flash/lib/terkin/network/core.py", line 70, in start_httpserver
  File "/flash/lib/terkin/api/http.py", line 54, in start
  File "dist-packages/microWebSrv.py", line 224, in Start
OSError: [Errno 12] ENOMEM

-- Program crashes when webserver is started twice -- OSError: [Errno 12] ENOMEM on soft reboot

We compensated for that by checking for webserver.IsStarted() appropriately when starting the server in a new thread like webserver.Start(threaded=True).

def start(self):
    if self.webserver.IsStarted():
        log.info('HTTP server already started')
    else:
        log.info('Starting HTTP server')
        self.webserver.Start(threaded=True)

-- TerkinHttpApi.start()

So, the reason for your observation could be that the code might be attempting to start the webserver twice.

With kind regards, Andreas.

[1] https://github.com/hiveeyes/hiveeyes-micropython-firmware

amotl avatar Jul 31 '19 11:07 amotl

@amotl thanks, you are right. It happens to me when - during development - I download a new version of my main.py to ESP32. In this case I don't have access to the variable declared in the old version so cannot call IsStarted

arpadtamasi avatar Aug 02 '19 12:08 arpadtamasi

Dear Árpád,

thanks for confirming these observations and also thanks for clarifying what you mean by "download" - I already became curious to ask ;].

In order to work around the "lost reference" problem, we just declared a global variable for holding that reference. For us, it is a "module-wide global" variable, living inside the namespace of terkin.api.http.

This module-wide global variable just called webserver [1] is assigned like outlined within [2].

Maybe this helps.

With kind regards, Andreas.

[1] https://github.com/hiveeyes/hiveeyes-micropython-firmware/blob/0deb953a4d241bb78ccf6aae76c932bcbb9fe95b/terkin/api/http.py#L30-L31 [2] https://github.com/hiveeyes/hiveeyes-micropython-firmware/blob/0deb953a4d241bb78ccf6aae76c932bcbb9fe95b/terkin/api/http.py#L57-L63

amotl avatar Aug 02 '19 13:08 amotl

Thanks, I give it a shot. I have no experience with Python neither with ESP that's why I'm confused. I'm just building a toy robot with my kids.

arpadtamasi avatar Aug 02 '19 13:08 arpadtamasi

Thanks, I give it a shot. I have no experience with Python neither with ESP that's why I'm confused.

I see. Just throwing in a webserver sounds easy, right? However, I believe you will make it. Just forget about the module stuff I have been rambling about, stay flat with your main.py and declare your variable as global right before where you are assigning it to be able to reference it even after a soft reboot usually being used while developing on the firmware, as you might currently be doing.

I'm just building a toy robot with my kids.

Good luck and enjoy the ride.

Let me know if you need any further help. From the top of my head, if you are playing with the webserver, you maybe want to amend it slightly in order to see any exceptions coming from the handler methods. Let me know when you are hitting a wall there.

amotl avatar Aug 02 '19 13:08 amotl

when you are hitting a wall there, not seeing any exceptions raised from the handler methods.

$ diff -u dist-packages/microWebSrv.py var/microWebSrv.py | colordiff
--- dist-packages/microWebSrv.py	2019-08-02 17:11:03.000000000 +0200
+++ var/microWebSrv.py	2019-08-02 17:14:50.000000000 +0200
@@ -375,6 +375,7 @@
                     else :
                         response.WriteResponseBadRequest()
             except :
+                print('ERROR handling webserver request\n', get_last_stacktrace())
                 response.WriteResponseInternalServerError()
             try :
                 if self._socketfile is not self._socket:
@@ -861,3 +862,12 @@
     # ============================================================================
     # ============================================================================

+
+import sys
+import uio
+
+def get_last_stacktrace():
+    buf = uio.StringIO()
+    exc = sys.exc_info()[1]
+    sys.print_exception(exc, buf)
+    return buf.getvalue()

amotl avatar Aug 02 '19 15:08 amotl

Hi amotl,

I tried to follow your work around but it didn't work.

My code looks like this: global webserver webserver = MicroWebSrv() webserver.Start(threaded=True) # Starts server in a new thread

Getting this error:

File "", line 27, in File "util/microWebSrv.py", line 230, in Start OSError: 112

Thanks

joseshiru avatar Oct 16 '19 14:10 joseshiru

It's failing here: self._server.listen(16)

joseshiru avatar Oct 16 '19 14:10 joseshiru

Same TCP port already open ? https://forum.micropython.org/viewtopic.php?t=4029

jczic avatar Oct 17 '19 11:10 jczic

I've tried with different ports without any success.

There's nothing else in my code using the same port.

Thanks.

joseshiru avatar Oct 17 '19 12:10 joseshiru

Ok, it's strange that you have this error 112. Just: a very new version of my micro web server will be released for MicroPython in a few days! For the moment, it works on Python (normal) and you can test it. At the moment, repository doesn't have description, keywords etc... but a great documentation is present :) I must fully test it on microPython, however, it must be works on it. Good luck, the link : https://github.com/jczic/MicroWebSrv2 👍

jczic avatar Oct 17 '19 19:10 jczic

Hello,

I released a fully new version (v2.0) of my web server here : github.com/jczic/MicroWebSrv2. Open source MIT, fully asynchronous, more robust, more fast and more efficient! It is delivered with a good documentation.

Thank you for your support and feedback. ☺️

Jean-Christophe Bos

jczic avatar Oct 20 '19 11:10 jczic

Perfect mate,

Gonna give it a try.

Thanks a lot.

Jose Zuma


From: J-Christophe Bos [email protected] Sent: Sunday, October 20, 2019 1:39:34 PM To: jczic/MicroWebSrv [email protected] Cc: Jose Zuniga Marin [email protected]; Comment [email protected] Subject: Re: [jczic/MicroWebSrv] Error 112 on ESP32 (#62)

Hello,

I released a fully new version (v2.0) of my web server here : github.com/jczic/MicroWebSrv2. Open source MIT, fully asynchronous, more robust, more fast and more efficient! It is delivered with a good documentation.

Thank you for your support and feedback. ☺️

Jean-Christophe Bos

Le jeu. 17 oct. 2019 à 14:33, Jose Zuniga Marin [email protected] a écrit :

I've tried with different ports without any success.

There's nothing else in my code using the same port.

Thanks.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jczic/MicroWebSrv/issues/62?email_source=notifications&email_token=AAD2ALAWYDIGBL57DA3VSPDQPBLSJA5CNFSM4IIFN4KKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBP5WQA#issuecomment-543152960, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD2ALALCK5EQJCSFWOHL6LQPBLSJANCNFSM4IIFN4KA .

--

Sincèrement,

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jczic/MicroWebSrv/issues/62?email_source=notifications&email_token=ABSFDHJE76C3DFLF4LRFKPLQPQ7PNA5CNFSM4IIFN4KKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBYIFPQ#issuecomment-544244414, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABSFDHO2UOAJMSXGJQVS7DDQPQ7PNANCNFSM4IIFN4KA.

joseshiru avatar Oct 20 '19 11:10 joseshiru