jczic / MicroWebSrv2

The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
https://github.com/jczic/MicroWebSrv2
MIT License
663 stars 97 forks source link

Cannot bind server on 0.0.0.0:80. #76

Open JohannesMaierhofer opened 2 years ago

JohannesMaierhofer commented 2 years ago

Hi, I'm trying to run MicroWebSrv2 on the Arduino RP2040 nano Connect via a wifi connection. But I ended up in MicroWebSrv2Exception: Cannot bind server on 0.0.0.0:80.

Here is my minimal example:

import network

SSID ='My_Nano_RP2040_Connect'   # Network SSID
KEY  ='1234567890'  # Network key (must be 10 chars)

# Init wlan module and connect to network
wlan = network.WLAN(network.AP_IF)
wlan.active(True)
wlan.config(essid=SSID, key=KEY, security=wlan.WEP, channel=2)
print("AP mode started. SSID: {} IP: {}".format(SSID, wlan.ifconfig()[0]))

from MicroWebSrv2 import *
from time         import sleep

mws2 = MicroWebSrv2()
mws2.SetEmbeddedConfig()
mws2.StartManaged()

# Main program loop until keyboard interrupt,
try :
    while True :
        sleep(1)
except KeyboardInterrupt :
    mws2.Stop()
JohannesMaierhofer commented 2 years ago

Additional information: The following line causes the issue, as it seems not available for the RP2 port of usocket. srvSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

concentrateddon commented 2 years ago

I'm successfully running MWS2 on a Pico W, but I did have to manually use Bind() to specify my IP address and port, once I connected the W to the WLAN and had an IP. Letting it default-bind to 0.0.0.0 wasn't working.

fschlaef commented 7 months ago

I'm successfully running MWS2 on a Pico W, but I did have to manually use Bind() to specify my IP address and port, once I connected the W to the WLAN and had an IP. Letting it default-bind to 0.0.0.0 wasn't working.

How did you manage to make it work ? Even manually binding the RPI Pico IP address and port, I am still getting the same error Cannot bind server on 192.168.1.113:8000, same with port 80 and IP 0.0.0.0