Пример #1
0
 private void logToMQTT(string message)
 {
     if (platform != null)
     {
         CLEvent e = new CLEvent((int)CLEventType.LogMessage, message);
         try
         {
             platform.PostEvent(e);
         }
         catch
         {
         }
     }
 }
Пример #2
0
        private string topicFromEvent(CLEvent clEvent)
        {
            String topic = "";
            switch (clEvent.EventType)
            {
                case (int)CLEventType.TemperatureReading:
                case (int)CLEventType.AmbientLightReading:
                    topic = NDConfiguration.DefaultConfiguration.MQTT.SensorDataTopic + "/" + clEvent.SourceIdentifier;
                    break;

                case (int)CLEventType.LogMessage:
                    topic = NDConfiguration.DefaultConfiguration.MQTT.LogTopic;
                    break;

                default:
                    break;
            }

            return topic;
        }
        public virtual int PostEvent(CLEvent e)
        {
            if (!IsConnected || mqttClient == null) { return -1; }

            string topic = TopicFromEvent(e);
            string message = e.serialize();
            int returnCode = mqttClient.Publish(topic, Encoding.UTF8.GetBytes(message));
            return returnCode;
        }
        public int PostEvent(CLEvent e)
        {
            if (listenerThread == null) { return 1; }

            string topic = TopicFromEventType(e.EventType);
            string message = e.serialize();
            try
            {
                NetduinoMQTT.PublishMQTT(socket, topic, message);
            }
            catch
            {
                Disconnect();
                Connect(host, userName, password, port);
            }

            // do not log publish here with mqtt logger, it causes a call cycle

            return 0;
        }
Пример #5
0
 void OnRemoteXBeeUpdate(RemoteXBee xbee, Widget[] updateData)
 {
     if (upstreamMQTT != null)
     {
         foreach (Widget widget in updateData)
         {
             if (widget.Type == WidgetType.TemperatureSensor)
             {
                 CLEvent e = new CLEvent((int)CLEventType.TemperatureReading, widget.Value, xbee.SerialNumber);
                 upstreamMQTT.PostEvent(e);
             }
             if (widget.Type == WidgetType.AmbientLightSensor)
             {
                 CLEvent e = new CLEvent((int)CLEventType.AmbientLightReading, widget.Value, xbee.SerialNumber);
                 upstreamMQTT.PostEvent(e);
             }
             if (widget.Type == WidgetType.Switch)
             {
                 CLEvent e = new CLEvent((int)CLEventType.SwitchStateChange, widget.Value/*widget.Value > 0 ? "on" : "off"*/, xbee.SerialNumber);
                 upstreamMQTT.PostEvent(e);
             }
         }
     }
 }