Hello everyone,
My current goal is to connect my Tasmota plug to my private WiFi. I would like to automate the connection process by directly sending an HTTP request to the device to set up the WiFi. My main problem is the web configuration page that automatically open when I connect to the Tasmota network. I would like to avoid this page
My application already retrieves the SSID and password of the WiFi network, and I can manually connect to the Tasmota network by entering these details on the web configuration page. However, I would like my application to do this automatically.
Here's my code :
func sendRequest(ssid : String, password : String, ip : String) {
let urlStr = "http://\(ip)/cm?cmnd=Backlog%20SetOption19%200;%20SetOption54%200;%20WifiConnect%20%22\(ssid)%22,%20%22\(password)%22"
guard let url = URL(string: urlStr) else {
print("Invalid URL.")
return
}
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
if let error = error {
print("Error: \(error)")
} else if let data = data {
let str = String(data: data, encoding: .utf8)
request_datas = str ?? "No callback"
}
}
task.resume()
}
func connectToWifi(ssid: String) {
let hotspotConfig = NEHotspotConfiguration(ssid: ssid)
hotspotConfig.joinOnce = true
NEHotspotConfigurationManager.shared.apply(hotspotConfig) { [self] (error) in
if let error = error {
connection_state = "Error: \(error.localizedDescription)"
}
else {
sendRequest(ssid: datas.temp_ssid, password: datas.password, ip: wifi_adress!)
isConnected = true
connection_state = "Connected"
}
}
}
}
Button {
connectToWifi(ssid: reseau)
} label: {
...
}
I'm retrieving the IP, password and SSID in another part of my code, which I know is correct.
I don't know if there's any ways I can do what I want, but I got a few ideas, which didn't work, like try to fill automatically the web form. I also have tried sending an HTTP request to set up the WiFi, but the configuration page still automatically opens. Does anyone know how I can automate the submission of the configuration form or prevent the web configuration page from displaying?
Any help would be greatly appreciated. Thank you in advance.
Best regards,
Gainder