Skip to content

Commit 17bb5f0

Browse files
committed
fix wifi client not connected
1 parent eb5ba04 commit 17bb5f0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

wifi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def get_ipaddr(cls, ifname):
9191
return socket.inet_ntoa(fcntl.ioctl(
9292
s.fileno(),
9393
0x8915, # SIOCGIFADDR
94-
struct.pack('256s', ifname[:15])
94+
struct.pack('256s', ifname.encode('utf-8')[:15])
9595
)[20:24])
9696

9797
@classmethod
@@ -154,6 +154,9 @@ def start_as_client(cls):
154154
out = os.system("wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null 2>&1")
155155
out += os.system("dhclient -1 wlan0")
156156
print(out)
157+
ipaddr = cls.get_ipaddr("wlan0")
158+
if ipaddr is None or "169.254" in ipaddr:
159+
raise Exception()
157160
try:
158161
cls.register_ipaddr(cls.get_macaddr("wlan0"), cls.get_config().get('bot_name', 'CoderBot'), cls.get_ipaddr("wlan0"), "roberto.previtera@gmail.com")
159162
print("registered bot, ip: " + str(cls.get_ipaddr("wlan0") + " name: " + cls.get_config().get('bot_name', 'CoderBot')))

0 commit comments

Comments
 (0)