421 |
421 |
422 def getWifiData(self): |
422 def getWifiData(self): |
423 """ |
423 """ |
424 Public method to get data related to the current WiFi status. |
424 Public method to get data related to the current WiFi status. |
425 |
425 |
426 @return tuple of two dictionaries containing the WiFi status data |
426 @return tuple of three dictionaries containing the WiFi status data |
427 for the WiFi client and access point |
427 for the WiFi client, access point and overall data |
428 @rtype tuple of (dict, dict) |
428 @rtype tuple of (dict, dict, dict) |
429 @exception OSError raised to indicate an issue with the device |
429 @exception OSError raised to indicate an issue with the device |
430 """ |
430 """ |
431 if self._deviceData["wifi_type"] == "picow": |
431 if self._deviceData["wifi_type"] == "picow": |
432 command = """ |
432 command = """ |
433 def wifi_status(): |
433 def wifi_status(): |
461 'essid': wifi.config('essid'), |
461 'essid': wifi.config('essid'), |
462 'country': rp2.country(), |
462 'country': rp2.country(), |
463 } |
463 } |
464 print(ujson.dumps(ap)) |
464 print(ujson.dumps(ap)) |
465 |
465 |
|
466 overall = { |
|
467 'active': station['active'] or ap['active'] |
|
468 } |
|
469 print(ujson.dumps(overall)) |
|
470 |
466 wifi_status() |
471 wifi_status() |
467 del wifi_status |
472 del wifi_status |
468 """ |
473 """ |
469 elif self._deviceData["wifi_type"] == "pimoroni": |
474 elif self._deviceData["wifi_type"] == "pimoroni": |
470 # TODO: not yet implemented |
475 # TODO: not yet implemented |
474 |
479 |
475 out, err = self._interface.execute(command) |
480 out, err = self._interface.execute(command) |
476 if err: |
481 if err: |
477 raise OSError(self._shortError(err)) |
482 raise OSError(self._shortError(err)) |
478 |
483 |
479 stationStr, apStr = out.decode("utf-8").splitlines() |
484 stationStr, apStr, overallStr = out.decode("utf-8").splitlines() |
480 station = json.loads(stationStr) |
485 station = json.loads(stationStr) |
481 ap = json.loads(apStr) |
486 ap = json.loads(apStr) |
|
487 overall = json.loads(overallStr) |
482 try: |
488 try: |
483 station["status"] = self.__statusTranslations[ |
489 station["status"] = self.__statusTranslations[ |
484 self._deviceData["wifi_type"] |
490 self._deviceData["wifi_type"] |
485 ][station["status"]] |
491 ][station["status"]] |
486 except KeyError: |
492 except KeyError: |
489 ap["status"] = self.__statusTranslations[self._deviceData["wifi_type"]][ |
495 ap["status"] = self.__statusTranslations[self._deviceData["wifi_type"]][ |
490 ap["status"] |
496 ap["status"] |
491 ] |
497 ] |
492 except KeyError: |
498 except KeyError: |
493 ap["status"] = str(ap["status"]) |
499 ap["status"] = str(ap["status"]) |
494 return station, ap |
500 return station, ap, overall |
495 |
501 |
496 def connectWifi(self, ssid, password): |
502 def connectWifi(self, ssid, password): |
497 """ |
503 """ |
498 Public method to connect a device to a WiFi network. |
504 Public method to connect a device to a WiFi network. |
499 |
505 |