def loop(self): """Listens for MQTT messages """ if self._mqtt is None: raise IoTError("You are not connected to IoT Central") self._mqtt.loop()
def disconnect(self): """Disconnects from the MQTT broker """ if self._mqtt is None: raise IoTError("You are not connected to IoT Central") self._mqtt.disconnect()
def send_device_to_cloud_message(self, message, system_properties=None): """Sends a device to cloud message to the IoT Hub """ if self._mqtt is None: raise IoTError("You are not connected to IoT Central") self._mqtt.send_device_to_cloud_message(message, system_properties)
def direct_method_called(self, method_name: str, data) -> IoTResponse: """Called when a direct method is invoked """ if self.on_command_executed is not None: # pylint: disable=E1102 return self.on_command_executed(method_name, data) raise IoTError("on_command_executed not set")
def send_property(self, property_name, data): """Updates the value of a writable property """ if self._mqtt is None: raise IoTError("You are not connected to IoT Central") patch_json = {property_name: data} patch = json.dumps(patch_json) self._mqtt.send_twin_patch(patch)
def send_telemetry(self, data): """Sends telemetry to the IoT Central app """ if self._mqtt is None: raise IoTError("You are not connected to IoT Central") if isinstance(data, dict): data = json.dumps(data) self._mqtt.send_device_to_cloud_message(data)
def update_twin(self, patch): """Updates the reported properties in the devices device twin """ if self._mqtt is None: raise IoTError("You are not connected to IoT Central") if isinstance(patch, dict): patch = json.dumps(patch) self._mqtt.send_twin_patch(patch)