예제 #1
0
        private void MqttClient_ApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
        {
            //throw new NotImplementedException();
            if (e.ApplicationMessage.Payload != null && !string.IsNullOrWhiteSpace(Encoding.UTF8.GetString(e.ApplicationMessage.Payload)))
            {
                CommunicationMessage mrcv = deserializeIt(e.ApplicationMessage.Payload);
                if (mrcv.id != instanceid)
                {
                    if (mrcv.msg.Equals("status"))
                    {
                        msg = mrcv.response;

                        Xamarin.Forms.Device.BeginInvokeOnMainThread(SetStatus);
                        //communicationmessage commmsg = new communicationmessage();
                        //commmsg.id = instanceid;
                        //commmsg.msg = diffresponse1;
                        //publishmessage(sendtopic, serializeit(commmsg));
                    }

                    else
                    {
                    }
                }
            }
        }
예제 #2
0
        public void SendCommmessage(CommunicationMessage msg)
        {
            //CommunicationMessage commMsg = new CommunicationMessage();
            //commMsg.id = instanceid;
            //commMsg.msg = diffResponse1;
            msg.id = instanceid;

            publishMessage(sendTopic, JsonConvert.SerializeObject(msg));
        }
예제 #3
0
        private void ConnectClient()
        {
            byte[] qosLevels = { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE };
            cl.Subscribe(reciveTopic, qosLevels);
            CommunicationMessage commMsg = new CommunicationMessage();

            commMsg.id       = instanceid;
            commMsg.msg      = "status";
            commMsg.response = "I started at " + DateTime.Now.ToString();;
            publishMessage(sendTopic, SerializeIt(commMsg));
        }
예제 #4
0
        private void Cl_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
        {
            if (e.Message != null && !String.IsNullOrWhiteSpace(Encoding.UTF8.GetString(e.Message)))
            {
                CommunicationMessage mrcv = deserializeIt(e.Message);

                if (mrcv.msg.Equals("StartPump"))
                {
                    CommunicationMessage commMsg = new CommunicationMessage();
                    commMsg.id  = instanceid;
                    commMsg.msg = "status";
                    sttask.getPmp().ManualStartPump();
                    commMsg.response = "I started Pump";

                    publishMessage(sendTopic, SerializeIt(commMsg));
                }
                else if (mrcv.msg.Equals("StopPump"))
                {
                    CommunicationMessage commMsg = new CommunicationMessage();
                    commMsg.id       = instanceid;
                    commMsg.msg      = "status";
                    commMsg.response = "I stopped Pump";
                    sttask.getPmp().ManulStopPump();

                    publishMessage(sendTopic, SerializeIt(commMsg));
                }
                else if (mrcv.msg.Equals("DeviceStatus"))
                {
                    CommunicationMessage commMsg = new CommunicationMessage();
                    commMsg.id       = instanceid;
                    commMsg.msg      = "status";
                    commMsg.response = "Heres the device status";
                    sttask.getLedBulb().Blink();
                    publishMessage(sendTopic, SerializeIt(commMsg));
                }
                else if (mrcv.msg.Equals("TimeSet"))
                {
                    DateTime.Parse(mrcv.response);
                    SetTime(DateTime.Parse(mrcv.response));
                    CommunicationMessage commMsg = new CommunicationMessage();
                    commMsg.id       = instanceid;
                    commMsg.msg      = "status";
                    commMsg.response = "Time set to " + DateTime.Now.ToString();
                    publishMessage(sendTopic, SerializeIt(commMsg));
                }
                else
                {
                    //run = true;
                }
            }
        }