简体   繁体   中英

Connecting to Wifi via python script - for Raspberry Pi3

Hello, I'm currently developing in Pyqt5 for raspberry Pi, and I need to make the Wifi connection inside my ui_window

The problem is, there are some libraries, but with all of them, at least I get 2 errors. like: If I do try this one: https://github.com/emlid/pywificontrol I get a message saying:

File "/home/pi/Desktop/pywificontrol-master/wificontrol/ init .py", line 1, in from wificontrol import WiFiControl ImportError: cannot import name 'WiFiControl'

If I do try this one: https://pypi.org/project/python-wifi/

I get a message saying: File "/home/pi/.local/lib/python3.5/site-packages/pythonwifi/iwlibs.py", line 1228, in init TypeError: cannot use a str to initialize an array with typecode 'c

I did try some other libraries, but all of them without success. Most of them are unmaintained.

So, guys, someone that has already worked with something similar.. could u give me some advice? I'm really stuck in this problem as I must let the user of the software chooses which Wifi connection he wants to use. He will be using a touch lcd display, and need to choose the connection.

If you want to install WiFi for python 3 you can write this command:

sudo python3 -m pip install wifi

it works perfectly for my raspberry pi3

To do that, you can use the os.system() function and connect to the network by execute this bash command:

$ iwconfig wlan0 essid name key password

Replace wlan0 n'y tour network interface, name by the network's name and password by the actual password

So the python code is:

import os
interface = 'wlan0'
name = ‘Wifi’
password = ‘password’
os.system('iwconfig ' + interface + ' essid ' + name + ' key ' + password)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM