Ejemplo n.º 1
0
        void HandletxtLog(int index, int nodeID, int humi, int temp)
        {
            delZigbeeCallback dele = delegate(int _index, int _nodeID, int _humi, int _temp)
            {
                //send_info_to_server(index, nodeID, humi, temp);

                Debug.WriteLine(string.Format("node => {0}    humi =>  {1}    temp => {2}", _nodeID.ToString(), _humi.ToString(), _temp.ToString()));
                //首先检查列表中是否已经存在
                if (!this.itemDic.ContainsKey(_nodeID.ToString()))
                {
                    this.itemDic.Add(_nodeID.ToString(), false);

                    this.checkedListBox1.Items.Add(_nodeID.ToString());
                }
                //其次检查是否要发送
                bool bstate = this.itemDic[_nodeID.ToString()];
                if (bstate == true)
                {
                    //发送到服务器


                    string log =
                        string.Format("数据包号:{0} 节点ID:{1} 湿度:{2} 温度:{3}",
                                      _index.ToString(),
                                      _nodeID.ToString(),
                                      _humi.ToString(),
                                      _temp.ToString());
                    this.appendLog(log);
                }
            };

            this.Invoke(dele, index, nodeID, humi, temp);
        }
Ejemplo n.º 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);
        }