コード例 #1
0
 def __init__(self, service):
     Characteristic.__init__(self,
                             constants.ADD_GATEWAY_CHARACTERISTIC_UUID,
                             ["read", "write", "notify"], service)
     self.add_descriptor(AddGatewayDescriptor(self))
     self.add_descriptor(OpaqueStructureDescriptor(self))
     self.notifyValue = string_to_dbus_encoded_byte_array("init")
コード例 #2
0
    def WriteValue(self, value, options):
        logger.debug('Write Add Gateway')
        try:
            self.notifyValue = string_to_dbus_encoded_byte_array("wait")

            addGatewayDetails = add_gateway_pb2.add_gateway_v1()
            addGatewayDetails.ParseFromString(bytes(value))
            miner_bus = dbus.SessionBus()

            logger.debug("Loading dbus com.helium.Miner")
            miner_object = miner_bus.get_object('com.helium.Miner', '/')
            sleep(DBUS_LOAD_SLEEP_SECONDS)
            miner_interface = dbus.Interface(miner_object, 'com.helium.Miner')
            sleep(DBUS_LOAD_SLEEP_SECONDS)

            logger.debug("Parsing onboarding values")
            owner = addGatewayDetails.owner
            fee = addGatewayDetails.fee
            amount = addGatewayDetails.amount
            payer = addGatewayDetails.payer

            logger.debug("Registering owner %s, fee %s, amount %s, payer %s" %
                         (owner, fee, amount, payer))
            # Calls https://github.com/helium/miner/blob/e55437beac4b46d15cbd079c9c8df045ffc0bf49/src/miner_ebus.erl#L50
            addMinerRequest = miner_interface.AddGateway(
                owner, fee, amount, payer)
            logger.debug("Adding Response")
            self.notifyValue = addMinerRequest
        except Exception:
            logger.exception("Unable to register gateway for unknown reason")
コード例 #3
0
 def __init__(self, service):
     Characteristic.__init__(self,
                             constants.ASSERT_LOCATION_CHARACTERISTIC_UUID,
                             ["read", "write", "notify"], service)
     self.add_descriptor(AssertLocationDescriptor(self))
     self.add_descriptor(OpaqueStructureDescriptor(self))
     self.notifyValue = string_to_dbus_encoded_byte_array("init")
コード例 #4
0
    def ReadValue(self, options):
        logger.debug("Read Ethernet Online from %s" %
                     self.ethernet_is_online_filepath)

        is_ethernet_online = read_ethernet_is_online(
            self.ethernet_is_online_filepath)
        logger.debug("Ethernet is online: %s" % is_ethernet_online)
        return string_to_dbus_encoded_byte_array(is_ethernet_online)
コード例 #5
0
    def wifi_remove_callback(self):
        if self.notifying:
            logger.debug('Callback WiFi Remove')
            value = string_to_dbus_encoded_byte_array(self.wifi_status)
            self.PropertiesChanged(constants.GATT_CHRC_IFACE, {"Value": value},
                                   [])

        return self.notifying
コード例 #6
0
    def connect_to_wifi_timeout(self):
        if self.notifying:
            logger.debug('Connect to WiFi Timeout')

            # Notify wifi status
            wifi_status = self.check_wifi_status()
            value = string_to_dbus_encoded_byte_array(wifi_status)
            self.PropertiesChanged(constants.GATT_CHRC_IFACE,
                                   {"Value": value}, [])

        return self.notifying
コード例 #7
0
    def StartNotify(self):

        logger.debug('Notify WiFi Remove')
        if self.notifying:
            return

        self.notifying = True

        value = string_to_dbus_encoded_byte_array(self.wifi_status)
        self.PropertiesChanged(constants.GATT_CHRC_IFACE, {"Value": value}, [])
        self.add_timeout(NOTIFY_TIMEOUT, self.wifi_remove_callback)
コード例 #8
0
    def run(self):
        if self.chrc.wifi_service and self.chrc.wifi_password:
            try:
                sleep(3)
                self.chrc.connect_to_wifi(self.chrc.wifi_service, self.chrc.wifi_password)
            except Exception as e:
                logger.exception("Wifi connect failed: %s" % str(e))

            # wipe out the wifi details
            self.chrc.wifi_service = ""
            self.chrc.wifi_password = ""  # nosec B105

            # Notify wifi status
            wifi_status = self.chrc.check_wifi_status()
            value = string_to_dbus_encoded_byte_array(wifi_status)
            self.chrc.PropertiesChanged(constants.GATT_CHRC_IFACE,
                                        {"Value": value}, [])
コード例 #9
0
    def ReadValue(self, options):

        logger.debug('Read WiFi SSID')
        active_connection = ""

        nmcli_custom.device.wifi_rescan()
        wifi_list_cache = nmcli_custom.device.wifi()

        for network in wifi_list_cache:
            ssid_str = str(network.ssid)

            if (is_valid_ssid(ssid_str)):
                if (network.in_use):
                    logger.debug("SSID in use: %s" % ssid_str)
                    active_connection = ssid_str
                else:
                    logger.debug("SSID not in use: %s" % ssid_str)
            else:
                logger.debug("Ignoring SSID: %s" % ssid_str)

        return string_to_dbus_encoded_byte_array(active_connection)
コード例 #10
0
 def ReadValue(self, options):
     return string_to_dbus_encoded_byte_array(constants.WIFI_REMOVE_VALUE)
コード例 #11
0
 def ReadValue(self, options):
     logger.debug('Read Lights')
     return string_to_dbus_encoded_byte_array(DEFAULT_LIGHTS_VALUE)
コード例 #12
0
 def ReadValue(self, options):
     return string_to_dbus_encoded_byte_array(constants.WIFI_SSID_LABEL)
コード例 #13
0
 def ReadValue(self, options):
     return string_to_dbus_encoded_byte_array(self.onboarding_key_label)
コード例 #14
0
 def ReadValue(self, options):
     logger.debug('Read Firmware')
     return string_to_dbus_encoded_byte_array(self.firmware_version)
コード例 #15
0
 def ReadValue(self, options):
     logger.debug('Read Serial Number')
     return string_to_dbus_encoded_byte_array(self.formatted_eth_mac_address)
コード例 #16
0
 def ReadValue(self, options):
     logger.debug('Read Mac Address')
     return string_to_dbus_encoded_byte_array(self.eth0_mac_address)
コード例 #17
0
 def ReadValue(self, options):
     return string_to_dbus_encoded_byte_array(
         constants.WIFI_CONFIGURED_SERVICES_LABEL)
コード例 #18
0
 def ReadValue(self, options):
     return string_to_dbus_encoded_byte_array(
         constants.ADD_GATEWAY_KEY_LABEL)
コード例 #19
0
 def ReadValue(self, options):
     logger.debug('Read WiFi Remove')
     return string_to_dbus_encoded_byte_array(self.WIFI_STATUSES)
コード例 #20
0
 def ReadValue(self, options):
     return string_to_dbus_encoded_byte_array(constants.MAC_ADDRESS_LABEL)
コード例 #21
0
 def ReadValue(self, options):
     logger.debug("Read Public Key")
     self.shared_state.load_public_key()
     logger.debug("Read Public Key: %s", self.shared_state.public_key)
     return string_to_dbus_encoded_byte_array(self.shared_state.public_key)
コード例 #22
0
 def AddGatewayCallback(self):
     if self.notifying:
         logger.debug('Callback Assert Location')
         value = string_to_dbus_encoded_byte_array("")
         self.PropertiesChanged(constants.GATT_CHRC_IFACE, {"Value": value},
                                [])
コード例 #23
0
 def ReadValue(self, options):
     return string_to_dbus_encoded_byte_array(constants.PUBLIC_KEY_LABEL)
コード例 #24
0
 def ReadValue(self, options):
     logger.debug("Read Onboarding Key")
     # Onboarding key is always identical to public key
     self.shared_state.load_public_key()
     logger.debug("Onboarding key:  %s" % self.shared_state.public_key)
     return string_to_dbus_encoded_byte_array(self.shared_state.public_key)
コード例 #25
0
 def ReadValue(self, options):
     return string_to_dbus_encoded_byte_array(
         constants.ASSERT_LOCATION_LABEL)
コード例 #26
0
 def ReadValue(self, options):
     return string_to_dbus_encoded_byte_array(constants.DIAGNOSTICS_LABEL)
コード例 #27
0
 def ReadValue(self, options):
     logger.debug('Read Manufacturer')
     return string_to_dbus_encoded_byte_array(MANUFACTURER_NAME)
コード例 #28
0
    def ReadValue(self, options):
        logger.debug('Read WiFi Connect')

        wifi_status = self.check_wifi_status()
        return string_to_dbus_encoded_byte_array(wifi_status)
コード例 #29
0
 def ReadValue(self, options):
     logger.debug('Read Firmware')
     # Intentionally reading the env variable each time in case it changes over
     # the application's lifetime
     firmware_version = os.getenv('FIRMWARE_VERSION')
     return string_to_dbus_encoded_byte_array(firmware_version)
コード例 #30
0
 def ReadValue(self, options):
     return string_to_dbus_encoded_byte_array(
         constants.ETHERNET_ONLINE_LABEL)