balena-labs-research / python-wifi-connect Goto Github PK
View Code? Open in Web Editor NEWAn API for controlling Wi-Fi connections on balena devices.
License: MIT License
An API for controlling Wi-Fi connections on balena devices.
License: MIT License
So iset up this up with balena-starter-interface but I'm running in to this isse.
Setup:
OpenBalena
generic-amd64-2.115.1-v14.11.1.img
[2023-05-24T12:57:04.234Z] [2023-05-24 12:57:04] - [INFO] - Checking for previously configured Wi-Fi connections...
[2023-05-24T12:57:19.546Z] [2023-05-24 12:57:19] - [INFO] - Adding connection of type HOTSPOT
[2023-05-24T12:57:19.587Z] [2023-05-24 12:57:19] - [ERROR] - Connection failed.
[2023-05-24T12:57:19.588Z] Traceback (most recent call last):
[2023-05-24T12:57:19.588Z] File "/app/common/wifi.py", line 126, in connect
[2023-05-24T12:57:19.588Z] Pnm.Settings.AddConnection(conn_dict)
[2023-05-24T12:57:19.589Z] File "", line 4, in AddConnection
[2023-05-24T12:57:19.589Z] File "/root/.local/lib/python3.8/site-packages/dbus/proxies.py", line 141, in __call__
[2023-05-24T12:57:19.589Z] return self._connection.call_blocking(self._named_service,
[2023-05-24T12:57:19.590Z] File "/root/.local/lib/python3.8/site-packages/dbus/connection.py", line 652, in call_blocking
[2023-05-24T12:57:19.590Z] reply_message = self.send_message_with_reply_and_block(
[2023-05-24T12:57:19.590Z] dbus.exceptions.DBusException: org.freedesktop.NetworkManager.Settings.Connection.InvalidProperty: 802-11-wireless-security.psk: property is invalid
[2023-05-24T12:57:19.591Z] Traceback (most recent call last):
[2023-05-24T12:57:19.591Z] File "/app/common/wifi.py", line 126, in connect
[2023-05-24T12:57:19.591Z] Pnm.Settings.AddConnection(conn_dict)
[2023-05-24T12:57:19.591Z] File "", line 4, in AddConnection
[2023-05-24T12:57:19.592Z] File "/root/.local/lib/python3.8/site-packages/dbus/proxies.py", line 141, in __call__
[2023-05-24T12:57:19.592Z] return self._connection.call_blocking(self._named_service,
[2023-05-24T12:57:19.592Z] File "/root/.local/lib/python3.8/site-packages/dbus/connection.py", line 652, in call_blocking
[2023-05-24T12:57:19.592Z] reply_message = self.send_message_with_reply_and_block(
[2023-05-24T12:57:19.592Z] dbus.exceptions.DBusException: org.freedesktop.NetworkManager.Settings.Connection.InvalidProperty: 802-11-wireless-security.psk: property is invalid
[2023-05-24T12:57:19.593Z]
[2023-05-24T12:57:19.593Z] During handling of the above exception, another exception occurred:
[2023-05-24T12:57:19.593Z]
[2023-05-24T12:57:19.593Z] Traceback (most recent call last):
[2023-05-24T12:57:19.594Z] File "run.py", line 68, in
[2023-05-24T12:57:19.594Z] connect()
[2023-05-24T12:57:19.594Z] File "/app/common/wifi.py", line 166, in connect
[2023-05-24T12:57:19.594Z] raise WifiHotspotStartFailed
[2023-05-24T12:57:19.594Z] common.errors.WifiHotspotStartFailed
An issue in the wrapper for NetworkManager means after 24 hours of the devices running you may not be able to scan for new networks: seveas/python-networkmanager#87
A fix has been found, but it hasn't been merged for some time. As soon as it is will bump the version and apply the fix: seveas/python-networkmanager#85
In the meantime, I have dropped to 2.1 which resolves this issue.
I'm trying to get this working with the starter-interface, but it seems nothing is running on port 9090. You can check the docker-compose file here.
Logs from the python-wifi-connect container:
[2023-03-05 17:53:59] - [INFO] - Checking for previously configured Wi-Fi connections...
command failed: Resource busy (-16)
[2023-03-05 17:54:12] - [WARNING] - IW resource busy. Retrying...
[2023-03-05 17:54:12] - [WARNING] - IW is unable to complete the request. This can happen on some devices and is usually nothing to worry about.
[2023-03-05 17:54:13] - [INFO] - Adding connection of type HOTSPOT
[2023-03-05 17:54:15] - [INFO] - Connection active.
[2023-03-05 17:54:15] - [INFO] - Listening on 172.17.0.1 port 9090
Payload from starter-interface:
{
"message": "\u001b[31mconnect ECONNREFUSED 127.0.0.1:9090\u001b[39m",
"name": "Error",
"stack": "Error: \u001b[31mconnect ECONNREFUSED 127.0.0.1:9090\u001b[39m\n at AxiosError.from (/app/node_modules/axios/dist/node/axios.cjs:789:14)\n at RedirectableRequest.handleRequestError (/app/node_modules/axios/dist/node/axios.cjs:2744:25)\n at RedirectableRequest.emit (node:events:525:35)\n at eventHandlers.<computed> (/app/node_modules/follow-redirects/index.js:14:24)\n at ClientRequest.emit (node:events:513:28)\n at Socket.socketErrorListener (node:_http_client:494:9)\n at Socket.emit (node:events:513:28)\n at emitErrorNT (node:internal/streams/destroy:151:8)\n at emitErrorCloseNT (node:internal/streams/destroy:116:3)\n at process.processTicksAndRejections (node:internal/process/task_queues:82:21)",
"config": {
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
},
"adapter": [
"xhr",
"http"
],
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 30000,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"env": {},
"headers": {
"Accept": "application/json, text/plain, */*",
"User-Agent": "axios/1.2.3",
"Accept-Encoding": "gzip, compress, deflate, br"
},
"baseURL": "http://127.0.0.1:9090/",
"method": "get",
"url": "v1/connection_status"
},
"code": "ECONNREFUSED",
"status": null
}```
This looks like a neat solution, but unfortunately I'm not able to start the container. When I try to do so I get the following message:
Traceback (most recent call last):
File "run.py", line 30, in <module>
device = get_device()
File "/app/common/wifi.py", line 248, in get_device
[(x.DeviceType, x) for x in Pnm.NetworkManager.GetDevices()]
File "<string>", line 8, in GetDevices
File "/root/.local/lib/python3.8/site-packages/NetworkManager.py", line 550, in to_python
val = fixups.base_to_python(val)
File "/root/.local/lib/python3.8/site-packages/NetworkManager.py", line 607, in base_to_python
return [fixups.base_to_python(x) for x in val]
File "/root/.local/lib/python3.8/site-packages/NetworkManager.py", line 607, in <listcomp>
return [fixups.base_to_python(x) for x in val]
File "/root/.local/lib/python3.8/site-packages/NetworkManager.py", line 620, in base_to_python
return globals()[classname](val)
File "/root/.local/lib/python3.8/site-packages/NetworkManager.py", line 348, in __new__
klass = device_class(obj.Get('org.freedesktop.NetworkManager.Device', 'DeviceType', dbus_interface='org.freedesktop.DBus.Properties'))
File "/root/.local/lib/python3.8/site-packages/NetworkManager.py", line 368, in device_class
return {
KeyError: dbus.UInt32(30, variant_level=1)
I'm not very familiar with both NetworkManager and Python. Is this something that needs to be fixed in python-networkmanager
? I've experienced a similar issue with wifi-connect for which I did find this issue. I've scanned my network using the nmcli
on the host, and there are no WPA3 networks in the list.
Thanks for your effort and please let me know if there is anything I can check or try!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.