Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4766

MicroPython • Pico W WIFI AP mode not working with Thread

$
0
0
I use below firmware for my pico w
RPI_PICO_W-20240602-v1.23.0.uf2

The code below is for WIFI AP configuration.

Code:

def ap_mode_init(ssid, password):    """        Description: This is a function to activate AP mode        Parameters:        ssid[str]: The name of your internet connection        password[str]: Password for your internet connection        Returns: Nada    """        ip = '192.168.4.1'    subnet = '255.255.255.0'    gateway = '192.168.4.1'    dns = '8.8.8.8'    # Just making our internet connection    ap = network.WLAN(network.AP_IF)    ap.ifconfig((ip, subnet, gateway, dns))    ap.config(essid=ssid, password=password)    ap.active(True)        while ap.active() == False:        pass    print('AP Mode Is Active, You can Now Connect')    print('IP Address To Connect to:: ' + ap.ifconfig()[0])def start_listen():    s = wifi_socket.socket(wifi_socket.AF_INET, wifi_socket.SOCK_STREAM)   #creating socket object    s.bind(('192.168.4.1', 80))    s.listen(1)    print('WIFI Star to lisen')    while True:      conn, addr = s.accept()      print('Got a connection from %s' % str(addr))      request = conn.recv(1024)      print('Content = %s' % str(request))      response = web_page()      conn.send(response)      conn.close()
I tired to run the WIFI AP code in the thread like below, when I run there is no error, I can find the WIFI NAME, but I can not connect to it.

Code:

import time, _thread, machineimport wifi_ap import pico_lanwifi_ap.ap_mode_init('NAME', '12345678')time.sleep(60)second_thread =_thread.start_new_thread(wifi_ap.start_listen, ())
I added 60 between init and socket listen, then I can connect to WIFI NAME, but after 60s I can not access to 192.168.4.1:80.
even if I reconnect to WIFI NAME, then I can not connect again. and my PC wifi address become wrong one.

it shold be 192.168.4.x but now change to 169.254.235.132. seems AP mode not working after I start the thread of socket listen.
on the other hand, if I run without thread, then it working always.

Does anyone knows about this issue ?

Statistics: Posted by heveansome — Mon Jul 15, 2024 11:02 am — Replies 2 — Views 24



Viewing all articles
Browse latest Browse all 4766

Trending Articles