Is it possible to do so?
if <Connecting to a specific wifi network>:
Action
Re: Is it possible to make a connection to a certain Wi Fi network as a condition?
Try:
Code: Select all
#!/usr/bin/env python
import subprocess
try:
ssid = subprocess.check_output(["iwgetid", "-r"]).rstrip()
except subprocess.CalledProcessError:
ssid = ""
if ssid == "mySSID" :
ActionHere
Re: Is it possible to make a connection to a certain Wi Fi network as a condition?
lmarmisa wrote: ↑Mon Jul 02, 2018 8:41 amTry:Code: Select all
#!/usr/bin/env python import subprocess try: ssid = subprocess.check_output(["iwgetid", "-r"]).rstrip() except subprocess.CalledProcessError: ssid = "" if ssid == "mySSID" : ActionHere
Code: Select all
#!/usr/bin/env python
import subprocess
from time import sleep
try:
ssid = subprocess.check_output(["iwgetid", "-r"]).rstrip()
except subprocess.CalledProcessError:
ssid = ""
while True:
if ssid == "MySSID" :
print("Connect")
else:
print("No connect")
sleep(1)
Re: Is it possible to make a connection to a certain Wi Fi network as a condition?
Did you put the name of your SSID in to the following line?
You can of course add
to your code to see what wifi network is detected.
Code: Select all
if ssid == "MySSID"
Code: Select all
print(ssid)
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter
Pi Interests: Home Automation, IOT, Python and Tkinter
Re: Is it possible to make a connection to a certain Wi Fi network as a condition?
Yes, I put the name of my SSID in to the following linescotty101 wrote: ↑Mon Jul 02, 2018 12:29 pmDid you put the name of your SSID in to the following line?You can of course addCode: Select all
if ssid == "MySSID"
to your code to see what wifi network is detected.Code: Select all
print(ssid)
Code: Select all
if ssid == "MySSID"
Code: Select all
print(ssid)
bn98 it my ssid, but what is b?
Re: Is it possible to make a connection to a certain Wi Fi network as a condition?
b indicates that it is a python 3 "byte literal".
Try the following instead of the current if.
This decodes the "bytes literal" to a standard python string.
Try the following instead of the current if.
Code: Select all
if ssid.decode('ascii') == 'bn98':
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter
Pi Interests: Home Automation, IOT, Python and Tkinter
Re: Is it possible to make a connection to a certain Wi Fi network as a condition?
Many thanks!scotty101 wrote: ↑Mon Jul 02, 2018 2:10 pmb indicates that it is a python 3 "byte literal".
Try the following instead of the current if.This decodes the "bytes literal" to a standard python string.Code: Select all
if ssid.decode('ascii') == 'bn98':