Пример #1
0
        void helper_RequestCompleted_addzigbeeInfo(object o)
        {
            deleControlInvoke dele = delegate(object ou)
            {
                string strUser = (string)ou;
                Debug.WriteLine(
                    string.Format("Form1.helper_RequestCompleted_getProduct-> response = {0}"
                                  , strUser));
                zigbeeInfo u2 = fastJSON.JSON.Instance.ToObject <zigbeeInfo>(strUser);
                if (u2.state == "ok")
                {
                    Debug.WriteLine("OK");
                }
                else
                {
                }
            };

            this.Invoke(dele, o);
        }
Пример #2
0
        void HandletxtLog(int index, string nodeID, int humi, int temp)
        {
            string            s1   = string.Empty;
            delZigbeeCallback dele = delegate(int _index, string _nodeID, int _humi, int _temp)
            {
                //send_info_to_server(index, nodeID, humi, temp);
                bool bChanged = false;//检查温度或者湿度是否发生了变化,只在发生变化时上传
                Debug.WriteLine(string.Format("node => {0}    humi =>  {1}    temp => {2}", _nodeID.ToString(), _humi.ToString(), _temp.ToString()));
                if (this.current_node_id == _nodeID.ToString())
                {
                    if (_humi > current_max_hum)
                    {
                        _humi = current_max_hum;
                    }
                    else
                    if (_humi < current_min_hum)
                    {
                        _humi = current_min_hum;
                    }

                    if (_temp > current_max_temp)
                    {
                        _temp = current_max_temp;
                    }
                    else if (_temp < current_min_temp)
                    {
                        _temp = current_min_temp;
                    }

                    this.lblCurrentHumunity.Text = _humi.ToString();
                    this.lblCurrentTemp.Text     = _temp.ToString();
                    this.progressHumunity.Value  = _humi;
                    this.progressTemp.Value      = _temp;

                    if (_humi != this.current_hum || _temp != this.current_temp)
                    {
                        bChanged = true;
                    }

                    this.current_hum  = _humi;
                    this.current_temp = _temp;

                    //其次检查是否要发送
                    if (bUploadZigbeeInfo == true && bChanged == true)
                    {
                        //发送到服务器
                        zigbeeInfo z = new zigbeeInfo();
                        z.node_id = _nodeID;
                        //z.startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        z.humi = _humi.ToString();
                        z.temp = _temp.ToString();
                        string         jsonString = fastJSON.JSON.Instance.ToJSON(z);
                        HttpWebConnect helper     = new HttpWebConnect();

                        string url = RestUrl.addZigbeeInfo;
                        helper.RequestCompleted += new deleGetRequestObject(helper_RequestCompleted_addzigbeeInfo);
                        helper.TryPostData(url, jsonString);
                    }
                }
                else
                if (!this.lbNodes.Items.Contains(_nodeID) && !this.lbNotUsedNodes.Items.Contains(_nodeID))
                {
                    //如果两个列表中均不存在该节点的ID,就添加到未使用节点列表中
                    this.lbNotUsedNodes.Items.Add(_nodeID);
                }
            };

            this.Invoke(dele, index, nodeID, humi, temp);
        }