Example #1
0
        public async void PublishSystemData()
        {
            List <System.Threading.Tasks.Task> task = new List <System.Threading.Tasks.Task>();

            if (_mqtt.IsConnected == false)
            {
                _mqtt.Connect(MqttSettings.MqttServer, MqttSettings.MqttPort, MqttSettings.MqttUsername, MqttSettings.MqttPassword);
            }

            if (_mqtt.IsConnected == true)
            {
                if (MqttSettings.IsComputerUsed)
                {
                    task.Add(Task.Run(() => PublishStatus()));
                }
                if (MqttSettings.CpuSensor)
                {
                    task.Add(Task.Run(() => _mqtt.Publish("cpuprosessortime", Processor.GetCpuProcessorTime())));
                }
                if (MqttSettings.FreeMemorySensor)
                {
                    task.Add(Task.Run(() => _mqtt.Publish("freememory", Memory.GetFreeMemory())));
                }
                if (MqttSettings.VolumeSensor)
                {
                    task.Add(Task.Run(() => PublishAudio()));
                }
                if (MqttSettings.MqttSlideshow)
                {
                    if (Properties.Settings.Default["MqttSlideshowFolder"].ToString().Length > 5)
                    {
                        string folder = @Properties.Settings.Default["MqttSlideshowFolder"].ToString();
                        task.Add(Task.Run(() => MqttCameraSlide(folder)));
                    }
                }
                if (MqttSettings.BatterySensor)
                {
                    task.Add(Task.Run(() => PublishBattery()));
                }
                if (MqttSettings.DiskSensor)
                {
                    task.Add(Task.Run(() => PublishDiskStatus()));
                }
                if (MqttSettings.EnableWebCamPublish)
                {
                    task.Add(Task.Run(() => PublishCamera()));
                }
                if (MqttSettings.ScreenshotEnable)
                {
                    task.Add(Task.Run(() => PublishScreenshot()));
                }
            }
            await Task.WhenAll(task).ConfigureAwait(false);
        }
Example #2
0
 private static void SendToMosquitto(string value)
 {
     try
     {
         if (!_clientConnected)
         {
             return;
         }
         client.Publish("car/REQUEST", new MqttPayload(value), QoS.AtLeastOnce, false);
     }
     catch (Exception ex)
     {
         Toaster(ex.Message, ToastPriority.Critical, ToastLength.Long);
     }
 }
Example #3
0
        void _client_ConnectionLost(object sender, EventArgs e)
        {
            //Console.WriteLine("Client connection lost\n");
            ColetorTopicoLog ctlm = new ColetorTopicoLog();

            ctlm.Id_ColetorTopico = 1;
            ctlm.DataHora         = getData();
            ctlm.Valor            = "lost";
            db.ColetorTopicoLog.Add(ctlm);
            db.SaveChanges();

            DateTime dt = DateTime.Now;

            _client.Publish("Desconectando", "MQTT Web Server - " + dt.ToShortTimeString(), QoS.BestEfforts, false);
        }
 void PublishSomething(string topic, MqttPayload payload)
 {
     //Console.WriteLine("Publishing on mqttdotnet/pubtest\n");
     // ComMessage = "Publishing on mqttdotnet/pubtest";
     //_client.Publish("mqttdotnet/pubtest", "Hello MQTT World", QoS.BestEfforts, false);
     _client.Publish(topic, payload, QoS.BestEfforts, false);
 }
Example #5
0
 protected override void Append(LoggingEvent loggingEvent)
 {
     if (mqttClient != null && mqttClient.IsConnected && mqttPreTopic != null)
     {
         mqttClient.Publish(mqttPreTopic + loggingEvent.Level.Name, new MqttPayload(loggingEvent.RenderedMessage), QoS.BestEfforts, false);
     }
 }
Example #6
0
        static void PublishSomething(string topic, string msg)
        {
            Console.WriteLine("Publishing on " + topic + ": " + msg + "\n");
            _client.Publish(topic, msg, QoS.AtLeastOnce, false);

            Console.WriteLine("Publishing to alias test2: " + msg + "\n");
            _client.PublishToAlias("test2", msg, QoS.AtLeastOnce, false);
        }
        /// <summary>
        /// Execute start up tasks
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            m_client = MqttClientFactory.CreateClient("tcp://192.168.0.50:1883", "MQTTKinect");
            m_client.Connect(cleanStart: true);
            m_client.Publish("text", "Kinect 2.0 just loaded!", QoS.BestEfforts, false);
            timer = System.DateTimeOffset.Now.AddSeconds(0.1f);

            if (this.bodyFrameReader != null)
            {
                this.bodyFrameReader.FrameArrived += this.Reader_FrameArrived;
            }
        }
Example #8
0
 public void Send(byte[] buffer, byte[] dstUuid, RoutingRule routingRule)
 {
     // mqttclient push msg to a thread-safe queue
     try
     {
         //todo uuid.ToString()
         //todo dstUuid arg have no use here
         handle.Publish(routingRule.MqttRule.GetPublishKey(uuid), new MqttPayload(buffer, 0), QoS.BestEfforts, false);
     }
     catch (Exception e)
     {
         Log.Error("MqttAdaptor Send throw exp:{0}", e);
     }
 }
Example #9
0
 public void Subscribe()
 {
     SystemEvents.SessionEnding += (sender, args) => _mqtt.Publish("", "off", true);
 }
        /// <summary>
        /// Draws a body
        /// </summary>
        /// <param name="joints">joints to draw</param>
        /// <param name="jointPoints">translated positions of joints to draw</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        /// <param name="drawingPen">specifies color to draw a specific body</param>
        private void DrawBody(IReadOnlyDictionary <JointType, Joint> joints, IDictionary <JointType, Point> jointPoints, DrawingContext drawingContext, Pen drawingPen)
        {
            // Draw the bones
            foreach (var bone in this.bones)
            {
                this.DrawBone(joints, jointPoints, bone.Item1, bone.Item2, drawingContext, drawingPen);
            }

            if (System.DateTimeOffset.Now.CompareTo(timer) < 0)
            {
                return;
            }
            timer = System.DateTimeOffset.Now.AddSeconds(timestep);

            //string topicBase = "kinect/";
            //topicBase += skeleton.TrackingId.ToString() + "/";

            string payLoad = "";

            foreach (var joint in joints.Values)
            {
                //Don't send any data if not tracked, could send only joint number in future
                if (joint.TrackingState == TrackingState.NotTracked)
                {
                    continue;
                }


                int jointVal   = (int)joint.JointType;
                int trackState = (int)joint.TrackingState;

                payLoad += jointVal.ToString("D2") + ";" +
                           joint.Position.X.ToString("N3") + ";" +
                           joint.Position.Y.ToString("N3") + ";" +
                           joint.Position.Z.ToString("N3") + ";" +
                           trackState.ToString("D1") + "/";
            }
            payLoad += "*";

            m_client.Publish("kinect",
                             payLoad,
                             QoS.BestEfforts,
                             false);

            // Draw the joints
            foreach (JointType jointType in joints.Keys)
            {
                Brush drawBrush = null;

                TrackingState trackingState = joints[jointType].TrackingState;

                if (trackingState == TrackingState.Tracked)
                {
                    drawBrush = this.trackedJointBrush;
                }
                else if (trackingState == TrackingState.Inferred)
                {
                    drawBrush = this.inferredJointBrush;
                }

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, jointPoints[jointType], JointThickness, JointThickness);
                }
            }
        }
Example #11
0
 public void PublishSomething(object message)
 {
     Debug.Log("Publishing on " + Topic);
     _client.Publish(Topic, message.ToString(), QoS.BestEfforts, false);
 }
Example #12
0
 private void PublishMqtt(string topic, MqttPayload payload)
 {
     client.Publish(topic, payload, QoS.BestEfforts, false);
 }
Example #13
0
 public void Publish(string topic, string message, QoS qoS, bool retained)
 {
     StaticResources.messageQueue.Enqueue("时间:" + DateTime.Now.ToString() +
                                          "推送信息,信息ID为:" +
                                          mqtt.Publish(topic, new MqttPayload(message), qoS, retained));
 }
Example #14
0
 void PublishSomething()
 {
     Console.WriteLine("Publishing on mqttdotnet/pubtest\n");
     _client.Publish("mqttdotnet/pubtest", "Hello MQTT World", QoS.BestEfforts, false);
 }
 void PublishSomething()
 {
     Console.WriteLine("Publishing on globalchoices/357660090106246\n");
     _client.Publish("globalchoices/357660090106246", "Door Open", QoS.AtLeastOnce, false);
 }
Example #16
0
        public void PublishSystemData()
        {
            if (_mqtt.IsConnected == false)
            {
                _mqtt.Connect(MqttSettings.MqttServer, MqttSettings.MqttPort, MqttSettings.MqttUsername, MqttSettings.MqttPassword);
            }

            if (_mqtt.IsConnected == true)
            {
                if (MqttSettings.IsComputerUsed)
                {
                    PublishStatus();
                }
                if (MqttSettings.CpuSensor)
                {
                    try
                    {
                        _mqtt.Publish("cpuprosessortime", Processor.GetCpuProcessorTime());
                    }
                    catch (Exception)
                    {
                        //we ignore
                    }
                }
                if (MqttSettings.FreeMemorySensor)
                {
                    _mqtt.Publish("freememory", Memory.GetFreeMemory());
                }
                if (MqttSettings.VolumeSensor)
                {
                    PublishAudio();
                }
                if (MqttSettings.ScreenshotEnable)
                {
                    PublishScreenshot(Properties.Settings.Default["ScreenShotpath"].ToString());
                }
                if (MqttSettings.MqttSlideshow)
                {
                    if (Properties.Settings.Default["MqttSlideshowFolder"].ToString().Length > 5)
                    {
                        string folder = @Properties.Settings.Default["MqttSlideshowFolder"].ToString();
                        MqttCameraSlide(folder);
                    }
                }
                if (MqttSettings.BatterySensor)
                {
                    PublishBattery();
                }
                if (MqttSettings.DiskSensor)
                {
                    PublishDiskStatus();
                }
                if (MqttSettings.EnableWebCamPublish)
                {
                    PublishCamera(GLocalWebcamFile);
                }
            }
        }
Example #17
0
 void PublishSomething()
 {
     _client.Publish("/Testing/topic/", "Hello MQTT World", QoS.BestEfforts, false);
 }
 void PublishSomething()
 {
     Console.WriteLine("Publishing on mqttdotnet/pubtest\n");
     _client.Publish(strMQTT_TCP_Server_Topic, "Hello MQTT World abc 123dddddd", QoS.OnceAndOnceOnly, false);
 }
Example #19
0
 void client_Connected(object sender, EventArgs e)
 {
     _client.Subscribe("/test/client2", QoS.BestEfforts);
     _client.Publish("/test/client1", "1", QoS.BestEfforts, false);
 }
Example #20
0
 private void MqttC_Connected(object sender, EventArgs e)
 {
     log.Info("Mqtt Connect");
     mqttClient.Subscribe(mqttPreTopic + "set/#", QoS.BestEfforts);
     mqttClient.Publish(mqttPreTopic + "state", new MqttPayload("online"), QoS.BestEfforts, false);
 }
 public void Publish(object payload)
 {
     _client.Publish("iot-2/evt/iotsensor/fmt/json", JsonConvert.SerializeObject(payload), QoS.BestEfforts, false);
 }