예제 #1
0
 static void mqc_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
 {
     string msg = new string(Encoding.UTF8.GetChars(e.Message));
     // here we take data [2] (Light) and [3] (poti)
     lastXivelyData2 = (msg.Split('\n')[2].Split(',')[2]); // in this case take 2nd datapoint and get value
     lastXivelyData3 = (msg.Split('\n')[3].Split(',')[2]); // in this case take 3rd datapoint and get value
     Debug.Print("xive light: " + lastXivelyData2);
     Debug.Print("xive thresh: " + lastXivelyData3);
     // since this repeatedly hangs try it on a new thread ....
     var t = new Thread(ActionForXivelyData);
     t.Start();
 }
예제 #2
0
파일: Main.cs 프로젝트: ATXcoder/M2MCaster
        private void client_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            string msg = System.Text.Encoding.UTF8.GetString(e.Message);
            string topic = e.Topic;
            string flag = e.DupFlag.ToString();

            log.Info("Message recieved on topic: " + topic);

            //Notify the plugins
            foreach (var item in _Plugins)
            {
                IPlugin plug = _Plugins[item.Key];
                plug.Message(topic, msg);

            }
        }
예제 #3
0
        private static void Client_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            var msg = Encoding.UTF8.GetString(e.Message).Split('|');

            SensorPresenca sensor = new SensorPresenca();

            if (msg.Length == 3)
            {
                sensor.tempo = int.Parse(msg[0]);
                sensor.cruzamento = int.Parse(msg[1]);
                sensor.posicao = int.Parse(msg[2]);
                sensor.horario = DateTime.UtcNow.AddHours(-3);

                db.Add(sensor);

                Console.WriteLine("Dados gravados com sucesso...");
            }
        }
예제 #4
0
 private static void client_MqttMsgPublished(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishedEventArgs e)
 {
     Console.Write("Message " + e.MessageId + " has been sent.\n");
 }
예제 #5
0
        private void Client_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            MqttMessage m = new MqttMessage(e.Topic, e.Message, e.QosLevel, e.Retain);
            var t = new MqttTopic(e.Topic, e.QosLevel, true);
            AddTopic(t);

            if (OnMessageArrived != null)
                OnMessageArrived(this, new MessPublishEventArgs(m, e.DupFlag));
        }
예제 #6
0
 private void client_MqttMsgPublishReceived(object sender,
                                            uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
 {
     AddSensor(e);
 }
예제 #7
0
 void client_EventPublished(Object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
 {
     try
     {
         Console.WriteLine("*** Message Received.");
         Console.WriteLine("*** Topic: " + e.Topic);
         Console.WriteLine("*** Message: " + System.Text.UTF8Encoding.UTF8.GetString(e.Message));
         Console.WriteLine("");
     }
     catch (InvalidCastException ex)
     {
     }
 }
예제 #8
0
        // Handle incoming messages
        private static void client_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            string publishReceived = Encoding.UTF8.GetString(e.Message);
            Console.WriteLine("Message received: "+publishReceived);

            switch (publishReceived)
            {
                case PAYLOAD_move12 :
                case "Pallet to Tester":
                    action_movAtoB();
                    while (true)
                    {
                        if (actionFinished == true)
                        {
                            publishOK = client.Publish(TOPIC_result, Encoding.UTF8.GetBytes(PAYLOAD_respOK));
                            actionFinished = false;
                            Console.WriteLine("publish OK and set actionFinished to false");
                            break;
                        }
                        //else if (actionFinished == false)
                            //Console.WriteLine("Waiting for Flag changed");
                    }
                    break;

                case PAYLOAD_move21 :
                case "Tester to Pallet":
                    action_movBtoA();
                    while (true)
                    {
                        if (actionFinished==true)
                        {
                            publishOK = client.Publish(TOPIC_result, Encoding.UTF8.GetBytes(PAYLOAD_respOK));
                            actionFinished = false;
                            Console.WriteLine("publish OK and set actionFinished to false");
                            break;
                        }
                        //else if (actionFinished == false)
                            //Console.WriteLine("Waiting for Flag changed");
                    }
                    break;

                default:
                    //Console.WriteLine("publishReceived has no event");
                    break;
            }
        }
예제 #9
0
파일: Mqtt.cs 프로젝트: robeat101/beakn
 void client_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
 {
     string message = new string(Encoding.UTF8.GetChars(e.Message));
     Console.WriteLine("Message Received - Topic: " + e.Topic + ", Message: " + message + ", QosLevel: " + e.QosLevel + ", Retain: " + e.Retain + ", DupFlag: " + e.DupFlag);
     rpi.Set(message);
 }
예제 #10
0
 private void MyMQTTClient_MqttMsgUnsubscribed(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgUnsubscribedEventArgs e)
 {
     if (OnMqttMsgUnsubscribed != null)
     {
         OnMqttMsgUnsubscribed(e);
     }
 }
예제 #11
0
        private void MyMQTTClient_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            string clientIdSender = "";
            var Data = new string(Encoding.UTF8.GetChars(e.Message));

            if (Data.Contains(ClientIdOnDataSeparator.ToString()))
            {
                string[] arrData = Data.Split(ClientIdOnDataSeparator);
                clientIdSender = arrData[0];
                Data = arrData[1];
            }

            if (OnMqttMsgPublishReceived != null)
            {
                OnMqttMsgPublishReceived(clientIdSender, Data, e.Topic, e.QosLevel, e.Retain);
            }
        }
        void MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            Debug.Print("Received status message from Tinamous: ");
            char[] message = Encoding.UTF8.GetChars(e.Message);
            var statusMessage = new string(message);
            Debug.Print("Status post received: " + statusMessage);

            if (statusMessage.ToLower().IndexOf("#water") > 0)
            {
                // Status post requesting we water.
                RaiseWaterReqested();
            }
        }
예제 #13
0
 private void Client_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
 {
     if (OnMessageArrived != null)
         OnMessageArrived(this, new MessPublishEventArgs(e.Topic,e.Message,e.DupFlag,e.QosLevel,e.Retain));
 }
        void mqtt_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            DateTime now = DateTime.Now;

            if (now < lastSystemRequestTime.AddSeconds(2) || e.Message.Length > 4096 || e.Topic.Length > 256) { return; }

            lastSystemRequestTime = now;

            var actionRequest = DecodeAction(e.Topic, Util.BytesToString(e.Message));
            if (actionRequest == null) { return; }

            string[] result = IotActionManager.Action(actionRequest);
            if (result != null) {
                Publish(ConfigurationManager.MqttDeviceAnnounce + ConfigurationManager.DeviceId, SystemConfig(result));
            }
        }
예제 #15
0
        // Handle incoming messages
        private static void client_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            string publishReceived = Encoding.UTF8.GetString(e.Message);
            Console.WriteLine("Message received: "+publishReceived);

            switch (publishReceived)
            {
                case PAYLOAD_move12 :
                    action_movAtoB();
                    break;

                case PAYLOAD_move21 :
                    action_movBtoA();
                    break;

                default:
                    //Console.WriteLine("publishReceived has no event");
                    break;
            }
        }
예제 #16
0
 // Handle subscription acknowledgements
 private static void client_MqttMsgSubscribed(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgSubscribedEventArgs e)
 {
     Console.WriteLine("Subscribed!");
 }
예제 #17
0
 /// <summary>
 ///     Publish command to the IBM Internet of Things Foundation. <br>
 /// </summary>
 void client_EventPublished(Object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
 {
     try
     {
         log.Info("*** Message Received.");
         log.Info("*** Topic: " + e.Topic);
         log.Info("*** Message: " + System.Text.UTF8Encoding.UTF8.GetString(e.Message));
         log.Info("");
     }
     catch (InvalidCastException ex)
     {
         log.Error(ex.ToString());
     }
 }