/// <summary> /// Publishes temperature info to the broker every 10 s. /// </summary> public void ThreadBody() { //Send a message with temperature information every 10 seconds. double avgTemperature = 10.0; double addTemp = 0.0; double maxTemp = 40.0; while (true) { if (avgTemperature + addTemp > maxTemp) { addTemp = 0.0; } string tempString = (avgTemperature + addTemp).ToString(); String msgContent = JsonUtils.CreateJsonString(tempString + "°C", this.configuration); Message temperatureMessage = new Message(msgContent, CreateMessageProperties()); this.Publish(temperatureMessage); addTemp += 1.0; Thread.Sleep(10000); } }
/// <summary> /// Messages are filtered to only receive messages containing /// a "macAddress"-property set to its own macAddress and a source property set to mapping. /// A feedback message is sent back to the cloud. /// </summary> /// <param name="received_message">The message received from the gateway broker</param> public void Receive(Message received_message) { if (received_message.Properties["source"] == "mapping2device" && received_message.Properties["macAddress"] == this.configuration) //&& { //send a message to the mapper that cloud info has been received String receivedContent = Encoding.UTF8.GetString(received_message.Content, 0, received_message.Content.Length); String msgContent = JsonUtils.CreateJsonString(receivedContent + " returns", this.configuration); Message ackMessage = new Message(msgContent, CreateMessageProperties()); this.Publish(ackMessage); } }