sendWiFiConfigToDevice method
Sends configuration data for the sensor.
This method constructs a JSON payload with the provided configuration
parameters and sends it to the sensor. It also handles the potential
failure of the write operation through the optional onWriteFailure
callback. The sensor's state is made available through the returned
stream.
Parameters:
orgId: The organization ID for the configuration.certPem: The PEM certificate used for secure communication.publicKey: The public key for encryption.privateKey: The private key for decryption.url: The endpoint URL to which the sensor will connect.ssid: The SSID of the Wi-Fi network (optional).password: The password for the Wi-Fi network.onWriteFailure: Optional callback that is triggered if the write operation fails. The callback receives an Exception as an argument.
Returns: A Stream of SensorConfigStateEntity that emits updates regarding the sensor's configuration state after the data has been sent.
Note: Ensure that the provided configuration parameters are valid before calling this method. Handle the stream appropriately to manage resources effectively.
Implementation
Stream<SensorConfigStateEntity> sendWiFiConfigToDevice(
String orgId, String certPem, String publicKey, String privateKey, String url, String? ssid, String password,
{int target = 0, Function(Exception)? onWriteFailure}) {
writeData(_buildConfigureJson(orgId, certPem, publicKey, privateKey, url, ssid, password,target), onWriteFailure: onWriteFailure);
return _sensorConfigStateStream.stream;
}