Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 112 on ESP32 #62

Open
arpadtamasi opened this issue Jul 31, 2019 · 13 comments
Open

Error 112 on ESP32 #62

arpadtamasi opened this issue Jul 31, 2019 · 13 comments

Comments

@arpadtamasi
Copy link

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

@amotl
Copy link

amotl commented Jul 31, 2019

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

@arpadtamasi
Copy link
Author

@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

@amotl
Copy link

amotl commented Aug 2, 2019

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

@arpadtamasi
Copy link
Author

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.

@amotl
Copy link

amotl commented Aug 2, 2019

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
Copy link

amotl commented Aug 2, 2019

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()

@joseshiru
Copy link

joseshiru commented Oct 16, 2019

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
Copy link

joseshiru commented Oct 16, 2019

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

@jczic
Copy link
Owner

jczic commented Oct 17, 2019

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

@joseshiru
Copy link

I've tried with different ports without any success.

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

Thanks.

@jczic
Copy link
Owner

jczic commented Oct 17, 2019

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
Copy link
Owner

jczic commented Oct 20, 2019 via email

@joseshiru
Copy link

joseshiru commented Oct 20, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants