[Solved]Any way to know the name of the SSID and other info with wifisetup?
f3rn4nd0d last edited by m5-docs
Hello, as the title of this thread says, I need to perform specific actions depending of the SSID name. Any help with wifisetup? Thanks a lot!
@f3rn4nd0d You can get connecting SSID name and PSK on Arduino.
#include <WiFi.h> WiFi.SSID() WiFi.psk()
f3rn4nd0d last edited by
@salty_good thanks, but I'm developing a little client in python that will connect to several wifi networks. The idea is to publish a different message via MQTT depending of the wifi it has connected to. I need to do it in python, maybe I can import a different library that gives me more options than wifisetup.
ajb2k3 last edited by
Hi @f3rn4nd0d there is a wifi scanner script that comes with the uiflow firmware, heres the python code in that file, hope it helps.
from m5stack import * import network import utime as time lcd.clear() sta = network.WLAN(network.STA_IF) sta.active(True) while True: lcd.clear() lcd.setCursor(0, 0) lcd.print('wifi scan:') wifi_list = sta.scan() number = 1 for i in wifi_list: lcd.print(i.decode(), 20, number*13) number += 1 time.sleep(10)
f3rn4nd0d last edited by f3rn4nd0d
Well, I've managed to do on a different way, thanks a lot for your help. Here is the code:
#import wifisetup #wifisetup.auto_connect() import network from m5stack import * from m5ui import * from m5_pin import * from m5mqtt import M5mqtt from time import strftime, ticks_ms, ticks_diff, sleep_ms import utime import _thread def connect(ssid,auth,timeout=6000): from network import WLAN, STA_IF, AP_IF global uplink uplink = WLAN(STA_IF) uplink.active(True) uplink.connect(ssid, auth) started= ticks_ms() while True: if uplink.isconnected(): return True else: if ticks_diff(ticks_ms(), started) < timeout: sleep_ms(100) continue else: return False wlan = network.WLAN(network.AP_IF) while True: if connect('Wifi1', 'password1'): red='Wifi1' break elif connect('Wifi2', 'password2'): red='Wifi2' break print('connected to: ',red) ...