MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / setWifiNetwork

Method setWifiNetwork

src/astroprint/network/mac_dev.py:90–132  ·  view source on GitHub ↗
(self, bssid, password)

Source from the content-addressed store, hash-verified

88 ]
89
90 def setWifiNetwork(self, bssid, password):
91 for n in self.getWifiNetworks():
92 if n['id'] == bssid:
93 if n['secured']:
94 if not password or len(password) < 3:
95 self.logger.info("Missing password for a secured network")
96 time.sleep(2)
97 return {
98 'err_code': 'invalid_psk',
99 'message': 'Invalid Password'
100 }
101
102 elif password != 'pwd':
103 self.logger.info("Password invalid. Needs to be 'pwd'")
104
105 def action():
106 eventManager.fire(Events.INTERNET_CONNECTING_STATUS, {'status': 'connecting'})
107 time.sleep(2)
108 eventManager.fire(Events.INTERNET_CONNECTING_STATUS, {'status': 'failed', 'reason': "no_secrets"})
109
110 timer = threading.Timer(3, action)
111 timer.daemon = True
112 timer.start()
113
114 return {"name": n['name']}
115
116 else:
117 if n["id"] == 'C0:7B:BC:1A:5C:81':
118 self.logger.info("Open network with NO connection")
119
120 def action():
121 eventManager.fire(Events.INTERNET_CONNECTING_STATUS, {'status': 'connecting'})
122 time.sleep(2)
123 eventManager.fire(Events.INTERNET_CONNECTING_STATUS, {'status': 'failed', 'reason': "no_connection"})
124
125 timer = threading.Timer(3, action)
126 timer.daemon = True
127 timer.start()
128
129 return {"name": n['name']}
130
131 time.sleep(1)
132 return self._setActiveWifi(n)
133
134 def isAstroprintReachable(self):
135 return self.isOnline()

Callers

nothing calls this directly

Calls 3

getWifiNetworksMethod · 0.95
_setActiveWifiMethod · 0.95
startMethod · 0.45

Tested by

no test coverage detected