0

I've written a simple python server for an IoT electronics school project. A "raspberry pi 3 model B rev 1.2" acts as the local station/server. I'm looking to create an AP which esp32's connect to, and communicate with the server on port 100 using a custom application level protocol.

The AP is created successfully (most of the time) in a separate thread using the command: sudo create_ap -n --no-dns -g 10.0.0.1 wlan0 test test1234

ron@raspberrypi:~/Desktop/livepark $ ./start_server.sh
current working dir: /home/ron/Desktop/livepark
starting server...
WARN: brmfmac driver doesn't work properly with virtual interfaces and
      it can cause kernel panic. For this reason we disallow virtual
      interfaces for your adapter.
      For more info: https://github.com/oblique/create_ap/issues/203
WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt
Config dir: /tmp/create_ap.wlan0.conf.JhUuwR5X
PID: 3404
Transmitting to channel 1...
No Internet sharing
hostapd command-line interface: hostapd_cli -p /tmp/create_ap.wlan0.conf.JhUuwR5X/hostapd_ctrl
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
wlan0: INTERFACE-DISABLED
wlan0 interface - gateway addr: 10.0.0.1

After starting the AP I'm trying to bind a listening socket:

print("wlan0 interface - gateway addr: " + WiFi_AP.wait_for_hotspot())  # print the IP address of the hotspot
time.sleep(1)
cloud_api.init_cloud_connection()

print("cloud connection initialized")
time.sleep(5)  # wait for socket to be ready

# opening socket using with statement, so it closes on its own when done
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
    # Allow reusing the port
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
    # bing server port to hotspot interface and port 100
    sock.bind((HOST, PORT))

    # opening cloud connection status thread with 5 sec delay
    status_thread = threading.Thread(target=cloud_api.cloud_status_update, args=5, daemon=True)
    status_thread.start()

    listen_for_clients(sock)

But I get an exception;

OSError: [Errno 99] Cannot assign requested address

I've tried a different local ip range for the gateway, i.e. 192.168.0.1/24, didn't work. Chatgpt suggested executables need special permissions to bind to ports under 1000, which I've given to the interpreter which is symlinked to by the venv.

it seems the issue might lie in "wlan0: INTERFACE-DISABLED" but I don't know how to change that. The OS installed is:

Linux raspberrypi 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian

P.s. when I create an AP using the same command from the code, open the same python interpreter in the venv my project uses, create a TCP socket and bind to 10.0.0.1:100, it all works. But when I run the python script it fails:

sudo create_ap -n --daemon --no-dns -g 10.0.0.1 wlan0 test test1234
Running as Daemon...
ron@raspberrypi:~ $ sudo create_ap --list-running
2524 wlan0
ron@raspberrypi:~ $ cd Desktop/
ron@raspberrypi:~/Desktop $ venv/bin/python3
Python 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import socket
 >>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 >>> sock.bind(('10.0.0.1', 100))
 >>> sock.listen
<built-in method listen of socket object at 0x7f82a5a440>
 >>> sock.listen()
5
  • always put full error message because there are other useful information. Commented Apr 15 at 17:07
  • ports smaller than 1024 are reserverd for system and they may need root provileges. Why not use something bigger - ie. popular 8000, 8080 Commented Apr 15 at 17:08
  • in some places you use sudo and maybe this makes difference. Commented Apr 15 at 17:11
  • BTW: you could ask on similar portal Raspberry Pi or on official forum Raspberry Pi Commented Apr 15 at 17:12
  • @furas I tried with a larger port number (42069) but that didn’t work either, I’ve tried with and without sudo, btw thank you for the other forum suggestion Commented Apr 17 at 1:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.