// simulate config command from iot central private static async Task <MethodResponse> OnConfigchanged(MethodRequest methodrequest, object usercontext) { ShowEventMessage?.Invoke("Receiving cloud to device message OnConfigchanged"); try { dynamic payload = JObject.Parse(methodrequest.DataAsJson); if (payload.version > Version) { Version = payload.version; ShowEventMessage?.Invoke($"Configuration updated to version {payload.version}"); await SendMessageFromDeviceToCloud("config", $"Configuration updated to version {payload.version}").ConfigureAwait(false); } else { ShowEventMessage?.Invoke($"no update required, already on {Version}"); await SendMessageFromDeviceToCloud("config", $"no update required, already on {Version}").ConfigureAwait(false); } } catch (Exception e) { await AzureIotCentralClient.SendMessageFromDeviceToCloud("alarm", $"Exception OnConfigchanged {e.Message} data {methodrequest.DataAsJson}").ConfigureAwait(false); } return(new MethodResponse(200)); }
// processes deviceupdate command from iot central => disable/enable device private static async Task <MethodResponse> OnDeviceChanged(MethodRequest methodrequest, object usercontext) { ShowEventMessage?.Invoke("Receiving cloud to device message OnSensorChanged"); try { dynamic payload = JObject.Parse(methodrequest.DataAsJson); String bluetoothaddress = payload.bluetoothaddress; String action = payload.action; // invoke sensor changed delegate await(SensorChanged?.Invoke(bluetoothaddress, null, action)).ConfigureAwait(false); } catch (Exception e) { // on exception inform iot central => disable/enable sensor await AzureIotCentralClient.SendMessageFromDeviceToCloud("alarm", $"Exception OnDeviceChanged {e.Message} data {methodrequest.DataAsJson}").ConfigureAwait(false); } return(new MethodResponse(200)); }