void Client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { var topicName = "Sensors_Events"; var receivedMessageStr = System.Text.Encoding.Default.GetString(e.Message); SensorMessage message; try { message = JsonConvert.DeserializeObject <SensorMessage>(receivedMessageStr); } catch (Exception ex) { Console.WriteLine($"Failed to Deserialize {receivedMessageStr}, message: {ex.Message}"); return; } var time = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); time = time.AddMilliseconds(message.Time); var addUserEndpoint = _bus.GetSendEndpoint(new Uri("rabbitmq://localhost/SensorCommands")).Result; //TODO: need to find out real id of the sensor var command = new UpdateSensorTempCommand(new Guid(), message.Name == "28-0000097100be" ? new Guid("f34bb461-ad5c-47b5-a6c9-33fc904955d1") : new Guid("f34bb461-ad5c-47b5-a6c9-33fc904955d2"), message.Temperature); addUserEndpoint.Send(command); Console.WriteLine($"Sent a UpdateSensorTempCommand"); }
public async Task <string> Get(Guid id, int temp) { var addUserEndpoint = await _bus.GetSendEndpoint(new Uri("rabbitmq://localhost/SensorCommands")); var newOb = new UpdateSensorTempCommand(new Guid(), id, temp); await addUserEndpoint.Send(newOb); return($"updated temp onsensor id: {newOb.SensorId} with temp {newOb.Temp}"); }