Пример #1
0
 def __activation2config(self):
     try:
         self.__pybytes_config = {
             'username': self.__pybytes_activation.json().get(
                 'username'),  # Pybytes username
             'device_id': self.__pybytes_activation.json().get(
                 'deviceToken'),  # device token
             'server': 'mqtt.{}'.format(constants.__DEFAULT_DOMAIN),
             'network_preferences':
             ['wifi'],  # ordered list, first working network used
             'wifi': {
                 'ssid': pycom.wifi_ssid_sta(),
                 'password': pycom.wifi_pwd_sta()
             },
             'ota_server': {
                 'domain': constants.__DEFAULT_SW_HOST,
                 'port': 443
             },
             'pybytes_autostart': True,
             'wlan_antenna': 0,
             'ssl': True,
             'dump_ca': True
         }
     except Exception as e:
         print_debug(2, 'Exception in __activation2config\n{}'.format(e))
Пример #2
0
 def smart_config(self, status=None, reset_ap=False):
     if status is None:
         return self.__smart_config
     if status:
         if reset_ap:
             pycom.wifi_ssid_sta(None)
             pycom.wifi_pwd_sta(None)
         if self.__pybytes_connection is not None:
             if self.isconnected():
                 print('Disconnecting current connection!')
                 self.disconnect()
             self.__pybytes_connection = None
         if not self.__smart_config:
             pycom.smart_config_on_boot(True)
             self.__smart_config = True
             self.__smart_config_setup()
     else:
         self.__smart_config = False
         pycom.smart_config_on_boot(False)
Пример #3
0
    def __read_activation(self):
        try:
            import urequest
        except:
            import _urequest as urequest

        from uhashlib import sha512
        print('Wifi connection established... activating device!')
        self.__pybytes_activation = None
        data = {
            "deviceType": os.uname().sysname.lower(),
            "wirelessMac": binascii.hexlify(machine.unique_id()).upper()
        }
        try:
            data.update({
                "activation_hash":
                binascii.b2a_base64(
                    sha512(
                        data.get("wirelessMac") + '-' +
                        '{}'.format(pycom.wifi_ssid_sta()) + '-' +
                        '{}'.format(pycom.wifi_pwd_sta())).digest()).decode(
                            'UTF-8').strip()
            })
        except:
            pass
        time.sleep(1)
        try:
            self.__pybytes_activation = urequest.post(
                'https://api.{}/esp-touch/register-device'.format(
                    constants.__DEFAULT_DOMAIN),
                json=data,
                headers={'content-type': 'application/json'})
            return True
        except Exception as ex:
            if self.__pybytes_activation is not None:
                self.__pybytes_activation.close()
            print('Failed to send activation request!')
            print_debug(2, ex)
            return False
Пример #4
0
 def __read_cb_config(self):
     config_block = {}
     try:
         config_block = {
             'userId':
             pycom.pybytes_userId(),
             'device_token':
             pycom.pybytes_device_token(),
             'mqttServiceAddress':
             pycom.pybytes_mqttServiceAddress(),
             'network_preferences':
             pycom.pybytes_network_preferences().split(),
             'wifi_ssid':
             pycom.wifi_ssid_sta()
             if hasattr(pycom, 'wifi_ssid_sta') else pycom.wifi_ssid(),
             'wifi_pwd':
             pycom.wifi_pwd_sta()
             if hasattr(pycom, 'wifi_pwd_sta') else pycom.wifi_pwd(),
             'extra_preferences':
             pycom.pybytes_extra_preferences(),
             'carrier':
             pycom.pybytes_lte_config()[0],
             'apn':
             pycom.pybytes_lte_config()[1],
             'cid':
             pycom.pybytes_lte_config()[2],
             'band':
             pycom.pybytes_lte_config()[3],
             'protocol':
             pycom.pybytes_lte_config()[4],
             'reset':
             pycom.pybytes_lte_config()[5]
         }
     except:
         pass
     return config_block
Пример #5
0
try:
    m = pycom.wifi_mode_on_boot()
    print("wifi_mode_on_boot", m, end=" ")
    print_wifi_mode(m)
    print()
except:
    pass
try:
    print("wifi_ssid", pycom.wifi_ssid())
    print("wifi_pwd", pycom.wifi_pwd())
except:
    pass
try:
    # v1.20.1.r1
    print("wifi_ssid_sta", pycom.wifi_ssid_sta())
    print("wifi_pwd_sta", pycom.wifi_pwd_sta())
    print("wifi_ssid_ap", pycom.wifi_ssid_ap())
    print("wifi_pwd_ap", pycom.wifi_pwd_ap())
except:
    pass


print("===== wlan =======================================")
wlan = WLAN()
try:
    print("sta_mac", binascii.hexlify(wlan.mac().sta_mac))
    print("ap_mac", binascii.hexlify(wlan.mac().ap_mac))
except:
    print("mac", binascii.hexlify(wlan.mac()))
print("is_connected", wlan.isconnected())
print("ssid", wlan.ssid())