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")
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")
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")
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)
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
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
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)
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}, [])
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)
def ReadValue(self, options): return string_to_dbus_encoded_byte_array(constants.WIFI_REMOVE_VALUE)
def ReadValue(self, options): logger.debug('Read Lights') return string_to_dbus_encoded_byte_array(DEFAULT_LIGHTS_VALUE)
def ReadValue(self, options): return string_to_dbus_encoded_byte_array(constants.WIFI_SSID_LABEL)
def ReadValue(self, options): return string_to_dbus_encoded_byte_array(self.onboarding_key_label)
def ReadValue(self, options): logger.debug('Read Firmware') return string_to_dbus_encoded_byte_array(self.firmware_version)
def ReadValue(self, options): logger.debug('Read Serial Number') return string_to_dbus_encoded_byte_array(self.formatted_eth_mac_address)
def ReadValue(self, options): logger.debug('Read Mac Address') return string_to_dbus_encoded_byte_array(self.eth0_mac_address)
def ReadValue(self, options): return string_to_dbus_encoded_byte_array( constants.WIFI_CONFIGURED_SERVICES_LABEL)
def ReadValue(self, options): return string_to_dbus_encoded_byte_array( constants.ADD_GATEWAY_KEY_LABEL)
def ReadValue(self, options): logger.debug('Read WiFi Remove') return string_to_dbus_encoded_byte_array(self.WIFI_STATUSES)
def ReadValue(self, options): return string_to_dbus_encoded_byte_array(constants.MAC_ADDRESS_LABEL)
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)
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}, [])
def ReadValue(self, options): return string_to_dbus_encoded_byte_array(constants.PUBLIC_KEY_LABEL)
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)
def ReadValue(self, options): return string_to_dbus_encoded_byte_array( constants.ASSERT_LOCATION_LABEL)
def ReadValue(self, options): return string_to_dbus_encoded_byte_array(constants.DIAGNOSTICS_LABEL)
def ReadValue(self, options): logger.debug('Read Manufacturer') return string_to_dbus_encoded_byte_array(MANUFACTURER_NAME)
def ReadValue(self, options): logger.debug('Read WiFi Connect') wifi_status = self.check_wifi_status() return string_to_dbus_encoded_byte_array(wifi_status)
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)
def ReadValue(self, options): return string_to_dbus_encoded_byte_array( constants.ETHERNET_ONLINE_LABEL)