private void onMqttMsgPublishReceived(MqttMsgPublishReceivedEventArgs e)
 {
     MqttMsgPublishReceivedEventHandler handler = MqttMsgPublishReceived;
     if (handler != null)
     {
         handler(this, e);
     }
 }
Ejemplo n.º 2
0
        private void MqttMsgPublishReceived(object sender, MqttMsgPublishReceivedEventArgs e)
        {
            string[] parts = e.Topic.Split(new char[] { '/' });
            string serialNumber = parts[parts.Length - 2];

            RemoteXBee xbee = xbeeWithSerialNumber(serialNumber);
            if (xbee == null)
            {
                return;
            }

            int eventType = Int32.Parse(parts[parts.Length - 1]);
            WidgetType wType;

            switch (eventType)
            {
                case (int)CLEventType.TemperatureReading:
                    wType = WidgetType.TemperatureSensor;
                    break;
                case (int)CLEventType.AmbientLightReading:
                    wType = WidgetType.AmbientLightSensor;
                    break;
                case (int)CLEventType.SwitchStateChange:
                    wType = WidgetType.Switch;
                    break;
                default:
                    return;
            }

            double value = Double.Parse(e.Message);
            xbee.setValueOfWidgetWithType(value, wType);
        }