Hiverize / FiPy

4 stars 11 forks source link

`OSError: Network card not available` on first boot #42

Open amotl opened 1 year ago

amotl commented 1 year ago

Hi there,

@didilamken reported at ^1:

I wanted to install the latest version of FiPy-master from 10.05.2021, but there are errors right at the first boot:

Traceback (most recent call last):
  File "<stdin>", line 17, in <module>
  File "webserver.py", line 142, in <module>
  File "/flash/lib/microDNSSrv.py", line 19, in Create
  File "/flash/lib/microDNSSrv.py", line 161, in Start
OSError: Network card not available

With kind regards, Andreas.

amotl commented 1 year ago

I discovered a few other network-related issues here. Maybe those are related, or GH-33 fixes the problem already?

amotl commented 1 year ago

At ^2, I've recommended to improve the code base a bit.

At this spot, Python code is defined at the module level within the webserver.py file, so it is already invoked when the modules are being loaded. This should be avoided.

https://github.com/Hiverize/FiPy/blob/01b403bf97fd48a35d865423a8410dc89c3a0df4/webserver.py#L139-L142

The code should be encapsulated into a function that is only called when it makes sense, i.e. when the "network is there" [^3]. Perhaps the enable_ap() function could be used?

https://github.com/Hiverize/FiPy/blob/01b403bf97fd48a35d865423a8410dc89c3a0df4/main.py#L293-L306

[^3]: A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only the first time the module name is encountered in an import statement. -- https://docs.python.org/3/tutorial/modules.html#more-on-modules