예제 #1
0
        public async Task PublishStatus(int id)
        {
            var obj = stateObjects.FirstOrDefault(p => p.Id == id);

            obj.Status = await GetCurtainStatus(obj.Id);

            var message = new MqttApplicationMessageBuilder()
                          .WithTopic("Home/Curtain/" + obj.Id.ToString() + "/Status")
                          .WithPayload(JsonConvert.SerializeObject(obj))
                          .WithAtLeastOnceQoS()
                          .Build();
            await _mqttHelper.Publish(message);
        }
    void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
    {
        List <byte> imageBufferList = new List <byte>();

        byte[] imageArray;
        if (photoCaptureFrame.pixelFormat == CapturePixelFormat.JPEG)
        {
            // Copy the raw IMFMediaBuffer data into our empty byte list.
            photoCaptureFrame.CopyRawImageDataIntoBuffer(imageBufferList);
            imageArray = imageBufferList.ToArray();
        }
        else
        {
            // Copy the raw image data into our target texture
            imageArray = ConvertAndShowOnDebugPane(photoCaptureFrame);
        }

        string data      = System.Convert.ToBase64String(imageArray);
        string pictureID = System.Guid.NewGuid().ToString();

        Log("sending picture via MQTT");
        Log("ID: " + pictureID);
        mqttHelper.Publish(outboundTopic, "{\"ID\":\"" + pictureID + "\",\"image\":\"" + data + "\"}");
    }
예제 #3
0
        public async Task OnReceiveData(string data)
        {
            var codes = new List <string>();

            if (data.IndexOf("01 50 01 01 01") == 0)
            {
                codes = data.Split(" ").ToList();
                if (!stateobjs.Any(p => p.Id == codes[5]))
                {
                    var obj = new HvacStateObject();
                    obj.Id                 = codes[5];
                    obj.Switch             = (SwitchState)int.Parse(codes[6]);
                    obj.TemperatureSet     = int.Parse(codes[7], System.Globalization.NumberStyles.HexNumber);
                    obj.Mode               = (WorkMode)int.Parse(codes[8]);
                    obj.Fan                = (Fanspeed)int.Parse(codes[9]);
                    obj.CurrentTemperature = int.Parse(codes[10], System.Globalization.NumberStyles.HexNumber);
                    stateobjs.Add(obj);
                    var message = new MqttApplicationMessageBuilder().WithTopic("Home/Sanling/" + codes[5] + "/Status")
                                  .WithPayload(JsonConvert.SerializeObject(obj))
                                  .WithAtLeastOnceQoS()
                                  .Build();
                    await _mqttHelper.Publish(message);
                }
                else
                {
                    var obj = stateobjs.FirstOrDefault(p => p.Id == codes[5]);
                    obj.Switch             = (SwitchState)int.Parse(codes[6]);
                    obj.TemperatureSet     = int.Parse(codes[7], System.Globalization.NumberStyles.HexNumber);
                    obj.Mode               = (WorkMode)int.Parse(codes[8]);
                    obj.Fan                = (Fanspeed)int.Parse(codes[9]);
                    obj.CurrentTemperature = int.Parse(codes[10], System.Globalization.NumberStyles.HexNumber);

                    var message = new MqttApplicationMessageBuilder().WithTopic("Home/Sanling/" + codes[5] + "/Status")
                                  .WithPayload(JsonConvert.SerializeObject(obj))
                                  .WithAtLeastOnceQoS()
                                  .Build();
                    await _mqttHelper.Publish(message);

                    if (obj.Id == "02")
                    {
                        if (obj.Switch == SwitchState.open)
                        {
                            await _lightHelper.SetBackgroudLight("0D", "25", 1);
                        }
                        else
                        {
                            await _lightHelper.SetBackgroudLight("0D", "25", 0);
                        }
                    }
                    if (obj.Id == "03")
                    {
                        if (obj.Switch == SwitchState.open)
                        {
                            await _lightHelper.SetBackgroudLight("0D", "26", 1);
                        }
                        else
                        {
                            await _lightHelper.SetBackgroudLight("0D", "26", 0);
                        }
                    }
                }
                await _lightHelper.UpdateACPanel();
            }
        }
예제 #4
0
        public async Task OnReceiveCommand(string Command)
        {
            if (Command == "01 01 0D") //门道感应器
            {
                await OpenDoor();

                var message = new MqttApplicationMessageBuilder().WithTopic("Home/Sensor/Door")
                              .WithPayload("1")
                              .WithAtLeastOnceQoS()
                              .Build();
                await _mqttHelper.Publish(message);
            }
            else if (Command == "01 00 0D")
            {
                await CloseDoor();

                var message = new MqttApplicationMessageBuilder().WithTopic("Home/Sensor/Door")
                              .WithPayload("0")
                              .WithAtLeastOnceQoS()
                              .Build();
                await _mqttHelper.Publish(message);
            }
            else if (Command == "02 01 0D") //过道探测器报警
            {
                await OpenAisle();

                var message = new MqttApplicationMessageBuilder().WithTopic("Home/Sensor/Aisle")
                              .WithPayload("1")
                              .WithAtLeastOnceQoS()
                              .Build();
                await _mqttHelper.Publish(message);
            }
            else if (Command == "02 00 0D")
            {
                await CloseAisle();

                var message = new MqttApplicationMessageBuilder().WithTopic("Home/Sensor/Aisle")
                              .WithPayload("0")
                              .WithAtLeastOnceQoS()
                              .Build();
                await _mqttHelper.Publish(message);
            }
            else if (Command == "03 01 0D") //烟雾探测器报警
            {
                var message = new MqttApplicationMessageBuilder().WithTopic("Home/Sensor/Smoke")
                              .WithPayload("1")
                              .WithAtLeastOnceQoS()
                              .Build();
                await _mqttHelper.Publish(message);

                _logger.LogInformation("烟雾探测器报警");
                _notify.Send("厨房烟雾");
            }
            else if (Command == "03 00 0D")
            {
                var message = new MqttApplicationMessageBuilder().WithTopic("Home/Sensor/Smoke")
                              .WithPayload("0")
                              .WithAtLeastOnceQoS()
                              .Build();
                await _mqttHelper.Publish(message);

                _logger.LogInformation("烟雾探测器取消报警");
                _notify.Send("厨房烟雾解除");
            }
            else if (Command == "04 01 0D") //主灯打开成功
            {
            }
            else if (Command == "04 00 0D") //主灯关闭成功
            {
            }
        }