Posts: 17
Joined: Thu Jan 25, 2018 8:23 pm

Connect to internet using a python script/commandline

Fri Sep 14, 2018 11:33 pm

I have a Raspberry-Pi zero w and I want to connect it to the internet using a python script. I know the network ESSID and Password. Is there any python library that can do this?
Is there any way I can do it via command line? If there is, I can use the subprocess library to execute that command. I have used the following command but it doesnt seem to work:

sudo iwconfig wlan0 essid NETWORKID key s:PASSWORD

if seems to run successfully without any errors but it doesn't connect the raspberry-pi to the internet.

I know I can use nmcli, but for some reason, I am avoiding it. Is there any other way I can connect to the internet using a python script/commandline?

User avatar
Posts: 33637
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Connect to internet using a python script/commandline

Sat Sep 15, 2018 8:27 am

Take a look at rewriting your /etc/wpa_supplicant/wpa_supplicant.conf with the wpa_passphrase command

sudo sh -c "wpa_passphrase SSID password >> /etc/wpa_supplicant/wpa_supplicant.conf"

If you then kill and restart wpa_supplicant it will connect to the network you've just defined.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Return to “General discussion”

Who is online

Users browsing this forum: Imperf3kt and 24 guests