物联传感器数据采集平台接口说明

物联传感器数据采集平台当前版本号:1.0.0.10

1.平台说明

  • 物联传感器数据采集平台是我公司开发的采用云技术对传感器数据进行采集和统计处理的平台项目之一。
  • 接口数据标准请参照《DF报文数据标准V2.1.5》,下载地址:http://www.xycnn.com/product/DF报文数据标准V2_1_5.pptx
  • 如果不是官网运行版本,请使用下面的接口时将api请求地址设定为正确地址。
  • 官网版本对不定期进行升级和功能扩展,如果您发现有新版本,请与获取初始版本的工作人员联系,获取最新版本。
  • 如果您发现有什么问题,可以在以下地址填写您的意见和建议:我要填写意见或者建议

2.平台开发api接口说明

  • 用户服务.用户服务.登录

  • 请求地址:http://sensor.xycnn.com/Services/Action/UserService.ashx
  • 请求方式:post/get
  • 请求参数示例:
    DFMsg =
                    {
                        "user": "123456@qq.com",//用户名
                        "pwd": "mypassword",//密码
                        "api": "UserService.UserService.LoginFormBrowser"//请求的服务.功能块.具体接口
                    }
                
  • 正确响应:
                    {"errorcode":"-1",
                      "errormsg":"用户已验证",
                      "token":"54744108633425114A2r0r1/8d0p6n0}3765432}111111111111111111111111",
                      "roles":"企业管理员"
                    }
                    
  • 错误响应:
                    {"errorcode":"5016",
                      "errormsg":"用户登录超时"
                    }
                    或
                    {"errorcode":"1",
                      "errormsg":"用户登录失败"
                    }
                    
  • 说明:
                    用户登录成功后返回的(票据)token请合理保存,服务端会将此票据保存2小时,超过两小时没有访问服务器时,此票据被回收。
                    

  • 传感器服务.传感器服务.获取本企业(指定分组)的传感器

  • 请求地址:http://sensor.xycnn.com/Services/Action/SensorService.ashx
  • 请求方式:post/get
  • 请求参数示例:
    DFMsg =
                    {
                        "token":"54744108633425114A2r0r1/8d0p6n0}3765432}111111111111111111111111",
                        "api": "SensorService.SensorService.GetSensorList"//请求的服务.功能块.具体接口
                        "orgName":"西安新敏电子",//传感器所属的组织结构名称
                        "groupName":"无线压力采集",//此项可填可不填
                        "sortWay":"设备编号排序", //排序方式,有两个设定值:"设备编号排序"或"数据最新排序",
                        "page":"1",              //支持分页。
                        "pageSize":"1000"        //每页显示的数量
                    }
                
  • 正确响应:
                    {
    	                "errorcode": "-1",
    	                "ds": [{
    		                "base": [
    			                ["Id", "Code", "Type", "Orgid", "ParaSetting", "Info", "Name", "CreateTime", "Typename", "PhysicalItemNum", "PhysicalItem0", "PhysicalItem1", "PhysicalItem2", "PhysicalItem3", "PhysicalItem4", "PhysicalItem5", "PhysicalItem6", "PhysicalItem7", "PhysicalItem8", "PhysicalItem9", "IsUsing"],
    			                ["8", "18030003", "4", "2", "{  \"jingdu\": \"108.916497\",  \"weidu\": \"34.21373\",  \"dianiang\": \"\",  \"xinhao\": \"\",  \"minWendu\": \"\",  \"maxWendu\": \"\",  \"tWendu\": \"\",  \"abnWendu\": \"\",  \"minShidu\": \"\",  \"maxShidu\": \"\",  \"tShidu\": \"\",  \"abnShidu\": \"\",  \"NormalSendTime\": \"\",  \"NormalSampleTime\": \"\",  \"AnormalSendTime\": \"\"}", "", "WiFi温湿度0003", "2018/3/30 0:00:00", "温度-湿度-电量-信号", "4", "3", "4", "1", "2", "", "", "", "", "", "", "True"],
    			                ["9", "18030002", "4", "2", "{  \"jingdu\": \"112.651233\",  \"weidu\": \"35.098988\",  \"dianiang\": \"30\",  \"xinhao\": \"15\",  \"minWendu\": \"10\",  \"maxWendu\": \"50\",  \"tWendu\": \"1\",  \"abnWendu\": \"0\",  \"minShidu\": \"12\",  \"maxShidu\": \"60\",  \"tShidu\": \"3\",  \"abnShidu\": \"0\",  \"NormalSendTime\": \"10\",  \"NormalSampleTime\": \"10\",  \"AnormalSendTime\": \"10\"}", "", "GPRS温湿度0002", "2018/3/30 0:00:00", "温度-湿度-电量-信号", "4", "3", "4", "1", "2", "", "", "", "", "", "", "True"],
    			                ["11", "18040001", "4", "2", "{  \"jingdu\": \"108.9\",  \"weidu\": \"34.2\",  \"dianiang\": \"20\",  \"xinhao\": \"10\",  \"minWendu\": \"11\",  \"maxWendu\": \"50\",  \"tWendu\": \"1\",  \"abnWendu\": \"0\",  \"minShidu\": \"10\",  \"maxShidu\": \"70\",  \"tShidu\": \"3\",  \"abnShidu\": \"0\",  \"NormalSendTime\": \"10\",  \"NormalSampleTime\": \"10\",  \"AnormalSendTime\": \"10\"}", "", "WIFI温湿度0004", "2018/4/25 0:00:00", "温度-湿度-电量-信号", "4", "3", "4", "1", "2", "", "", "", "", "", "", "True"],
    			                ["19", "18050010", "4", "2", "{  \"jingdu\": \"\",  \"weidu\": \"\",  \"dianiang\": \"15\",  \"xinhao\": \"10\",  \"minWendu\": \"10\",  \"maxWendu\": \"50\",  \"tWendu\": \"1\",  \"abnWendu\": \"0\",  \"minShidu\": \"10\",  \"maxShidu\": \"80\",  \"tShidu\": \"3\",  \"abnShidu\": \"0\",  \"NormalSendTime\": \"10\",  \"NormalSampleTime\": \"10\",  \"AnormalSendTime\": \"10\"}", "", "GRPC温湿度0001", "2018/5/14 0:00:00", "温度-湿度-电量-信号", "4", "3", "4", "1", "2", "", "", "", "", "", "", "True"]
    		                ],
    		                "data": [
    			                ["Id", "DeviceId", "Createtime", "Data1", "Data2", "Data3", "Data4", "Data5", "Data6", "Data7", "Data8", "Data9", "Data10", "IsReplenish"],
    			                ["5411", "18030003", "2018/4/25 16:19:58", "23.3", "46.7", "88", "21", "", "", "", "", "", "", ""],
    			                ["26403", "18050010", "2018/6/6 13:40:06", "28.1", "41.3", "28", "20", "", "", "", "", "", "", "False"],
    			                ["26622", "18030002", "2018/6/6 16:23:54", "32.2", "31.5", "34", "12", "", "", "", "", "", "", "False"],
    			                ["26968", "18040001", "2018/6/7 10:12:17", "28.4", "35.9", "45", "20", "", "", "", "", "", "", "False"]
    		                ]
    	                }, {}]
                    }
                    
  • 错误响应:
                    {"errorcode":"1",
                      "errormsg":"发生了错误"
                    }
                    
  • 说明:
                    数据集DS中的数据,base表示传感器的基础信息,
                    data是传感的最新测量数据记录。
                    

  • 传感器服务.传感器服务.通过编号获取传感器信息

  • 请求地址:http://sensor.xycnn.com/Services/Action/SensorService.ashx
  • 请求方式:post/get
  • 请求参数示例:
    DFMsg =
                    {
                        "token":"54744108633425114A2r0r1/8d0p6n0}3765432}111111111111111111111111",
                        "api": "SensorService.SensorService.GetSensorByCode"//请求的服务.功能块.具体接口
                        "orgName":"西安新敏电子",//传感器所属的组织结构名称
                        "code":"18030006" //厂家对于传感器的编号
                        "startTime":"2018-06-06 0:0:0",//查询传感器数据开始时间,可不填,默认为三天之前时间
                        "endTime":"2018-06-09 23:59:59"//查询传感器数据结束时间,可不填,默认为当前时间
                    }
                
  • 正确响应:
                    {
    	                "num": "0",
    	                "errorcode": "-1",
    	                "ds": [{
    		                "base": [
    			                ["Id", "Code", "Type", "Orgid", "ParaSetting", "Info", "Name", "CreateTime", "Typename", "PhysicalItemNum", "PhysicalItem0", "PhysicalItem1", "PhysicalItem2", "PhysicalItem3", "PhysicalItem4", "PhysicalItem5", "PhysicalItem6", "PhysicalItem7", "PhysicalItem8", "PhysicalItem9", "Group", "IsUsing"],
    			                ["19", "18050010", "4", "2", "{  \"jingdu\": \"\",  \"weidu\": \"\",  \"dianiang\": \"15\",  \"xinhao\": \"10\",  \"minWendu\": \"10\",  \"maxWendu\": \"50\",  \"tWendu\": \"1\",  \"abnWendu\": \"0\",  \"minShidu\": \"10\",  \"maxShidu\": \"80\",  \"tShidu\": \"3\",  \"abnShidu\": \"0\",  \"NormalSendTime\": \"10\",  \"NormalSampleTime\": \"10\",  \"AnormalSendTime\": \"10\"}", "", "GRPC温湿度0001", "2018-05-14 0:00:00", "温度-湿度-电量-信号", "4", "3", "4", "1", "2", "", "", "", "", "", "", "8", "True"]
    		                ],
    		                "physicalItem": [
    			                ["Code", "Type", "Unit", "CreateTime", "Grit"],
    			                ["3", "温度", "℃", "2018-02-25 0:00:00", "10"],
    			                ["4", "湿度", "% RH", "2018-02-25 0:00:00", "10"],
    			                ["1", "电量", "%", "2018-02-25 0:00:00", "1"],
    			                ["2", "信号", "", "2018-02-25 0:00:00", "1"]
    		                ],
    		                "data": [
    			                ["Id", "DeviceId", "Createtime", "Data1", "Data2", "Data3", "Data4", "Data5", "Data6", "Data7", "Data8", "Data9", "Data10", "IsReplenish"],
    			                ["23696", "18050010", "2018-05-30 17:14:06", "26.2", "42.8", "34", "18", "", "", "", "", "", "", "False"],
    			                ["23695", "18050010", "2018-05-30 17:04:06", "26.2", "42.8", "34", "18", "", "", "", "", "", "", "True"],
    			                ["23692", "18050010", "2018-05-30 16:54:06", "26.2", "43.3", "34", "19", "", "", "", "", "", "", "False"],
    			                ["23688", "18050010", "2018-05-30 16:44:06", "26.3", "42.3", "34", "18", "", "", "", "", "", "", "False"],
    			                ["23686", "18050010", "2018-05-30 16:34:06", "26.2", "43.7", "34", "18", "", "", "", "", "", "", "False"],
    			                ["23685", "18050010", "2018-05-30 16:24:06", "26.2", "43.7", "34", "19", "", "", "", "", "", "", "False"],
    			                ["23681", "18050010", "2018-05-30 16:14:06", "26.2", "43.3", "34", "19", "", "", "", "", "", "", "False"],
    			                ["23679", "18050010", "2018-05-30 16:04:06", "26.1", "43.7", "34", "20", "", "", "", "", "", "", "False"],
    			                ["23676", "18050010", "2018-05-30 15:54:06", "26.1", "43.3", "34", "21", "", "", "", "", "", "", "False"],
    			                ["23673", "18050010", "2018-05-30 15:44:06", "26.2", "42.8", "34", "20", "", "", "", "", "", "", "False"],
    			                ["23671", "18050010", "2018-05-30 15:34:06", "26.1", "42.8", "34", "21", "", "", "", "", "", "", "False"]
    		                ]
    	                }, {}]
                    }
                    
  • 错误响应:
                    {"errorcode":"1",
                      "errormsg":"发生了错误"
                    }
                    
  • 说明:
                    数据集DS中的数据,base表示传感器的基础信息,physicalItem是此传感器所包含的物理量。
                    data是传感的测量数据记录。
                    

  • 传感器服务.传感器服务.启用或关闭传感器数据读取

  • 请求地址:http://sensor.xycnn.com/Services/Action/SettingService.ashx
  • 请求方式:post/get
  • 请求参数示例:
    DFMsg =
                    {
                        token: "54744108633425114A2r0r1/8d0p6n0}3765432}111111111111111111111111",
                        api: "SettingService.SettingService.UserOrStopDevice",
                        Id: sensorId,    //传感器ID,注意不是出厂编号。sensorId需要通过上面的“通过编号获取传感器信息”来获取,然后在这里给传感器。
                        IsUsing:"True",  //字符串形式的True或者False,True表示启用,False表示停用。
                        orgName:orgName  //组织结构的名称。
                    }
                
  • 正确响应:
                    {"errorcode":"-1","errormsg":"已停用"}
                    
  • 错误响应:
                    {"errorcode":"1",
                      "errormsg":"发生了错误"
                    }
                    
  • 说明:
                    操作需要其他结构数据支持,建议在本地保留传感器基础数据。
                    

3.客户端调用说明

  • 适用情况说明
  • 对于非浏览器请求数据接口,由于本地没有默认的Session通道支持,会造成toekn无效,所以需要在客户端模拟Session通道,让客户端与服务器正常通讯。否则会报告没有权限。下面的实例分别列举了c#客户端的Session模拟与Java客户端的Session模拟,仅供参考。
  • C#编写Winform程序对客户端的Session保持实例
  • 界面事件处理
                        private void button1_Click(object sender, EventArgs e)
                        {
                            Request r = new Request();
                            string para= "DFMsg={\"user\":\"142761709@qq.com\",\"pwd\":\"123456\",\"api\":\"UserService.UserService.LoginFormBrowser\"}";
                            string server = "http://sensor.xycnn.com/Services/Action/UserService.ashx";
                            string str=r.GetData(server, para);
                            JObject obj = JObject.Parse(str);
                            string token = obj.GetValue("token").ToString();
                            server = "http://sensor.xycnn.com/Services/Action/SensorService.ashx";
                            string para2 = "DFMsg={\"token\":\"" + token + "\",\"api\":\"SensorService.SensorService.GetSensorList\",\"orgName\":\"西安新敏电子\",\"groupName\":\"\",\"sortWay\":\"设备编号排序\",\"page\":\"1\",\"pageSize\":\"1000\"}";
                            str = r.GetData(server, para2);
                        }
                    
    远程请求
                        internal string GetData(string serviceAddress, string stroo)
                        {
                            try
                            {
                                string strURL =  serviceAddress;
                                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
                                request.ContentType = "application/x-www-form-urlencoded";
                                if (Request.savedCookieContainer != null) {
                                    request.CookieContainer=Request.savedCookieContainer;
                                }
                                request.Method = "POST";
                                request.Timeout = 120000;
                                byte[] payload;
                                //将URL编码后的字符串加密后转化为字节9
                                payload = System.Text.Encoding.UTF8.GetBytes(stroo);
                                //设置请求的 ContentLength 
                                request.ContentLength = payload.Length;
                                //获得请 求流
                                Stream writer = request.GetRequestStream();
                                BufferedStream bsw = new BufferedStream(writer);
                                bsw.Write(payload, 0, payload.Length);
                                bsw.Flush();
                                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                                Stream s = response.GetResponseStream();
    
                                BufferedStream bs = new BufferedStream(s);
                                StreamReader r = new StreamReader(bs);
                                string str = r.ReadToEnd();
                                if (str.Equals("")) {
                                    str = "{\"errorcode\":\"5023\",\"errormsg\":\"远程服务无法访问。\"}";
                                }
                                bsw.Close();
                                bs.Close();
                                if (Request.savedCookieContainer == null) {
                                    Request.savedCookieContainer = new CookieContainer();
                                    Request.savedCookieContainer.Add(response.Cookies);
                                }
                                return str;
                            }
                            catch (Exception e1)
                            {
                                return "{\"errorcode\":\"5024\",\"errormsg\":\"" + e1.Message + "\"}";
                            }
                        }
                    
  • java程序对客户端的Session保持实例
  • 调用函数
                        public void test3(){
                            String para= "DFMsg={\"user\":\"142761709@qq.com\",\"pwd\":\"123456\",\"api\":\"UserService.UserService.LoginFormBrowser\"}";
                            String server = "http://localhost/Services/Action/UserService.ashx";
                            String str=getData(server, para);
                            JsonParser jParser=new JsonParser();
                            JsonObject obj= jParser.parse(str).getAsJsonObject();
                            String token = obj.get("token").getAsString();
                            server = "http://localhost/Services/Action/SensorService.ashx";
                            String para2 = "DFMsg={\"token\":\"" + token + "\",\"api\":\"SensorService.SensorService.GetSensorList\",\"orgName\":\"西安新敏电子\",\"groupName\":\"\",\"sortWay\":\"设备编号排序\",\"page\":\"1\",\"pageSize\":\"1000\"}";
                            str = getData(server, para2);
        	
                        }
                    
  • 远程请求
                        public String  getData(String path,String paras){
        	                try{
            	                URL url = new URL(path);
        	                HttpURLConnection connection = (HttpURLConnection) url
    				                .openConnection();
    
                            if (TestMain.cookies.size()>0) {
                                //发送cookie信息上去,以表明自己的身份,否则会被认为没有权限
            	                String cookie="";
            	                for(int i=0;i<cookies.size();i++){
            		                if(i>0){
            			                cookie+=";";
            		                }
            		                cookie+=cookies.get(i);
            	                }
            	                connection.setRequestProperty("Cookie", cookie);  
                            }
    		                connection.setConnectTimeout(120000);
    		                connection.setRequestMethod("POST");   
    		                connection.setDoOutput(true);
    		                OutputStreamWriter out = new OutputStreamWriter(
    				                connection.getOutputStream(), "utf-8");
    		                out.write(paras);
    		                out.flush();
    		                if(TestMain.cookies.size()<1){
    			                Map<String, List<String>> items=connection.getHeaderFields();
    			                 for (Entry<String, List<String>> entry:items.entrySet()) {
    			                      String key=entry.getKey();
    			                      if(key!=null&&key.equals("Set-Cookie")){
    				                      List<String> values=entry.getValue();
    				                      for(int i=0;i<values.size();i++){
    				    	                  String aValue=values.get(i).toString();
    				    	                  TestMain.cookies.add(aValue.split(";")[0]);	
    				                      }
    			                      }
    			                 }
    		                }
    		                out.close();
    		                String sCurrentLine = "";
    		                String sTotalString = "";
    		                InputStream l_urlStream = connection.getInputStream();
    		                BufferedReader l_reader = new BufferedReader(
    				                new InputStreamReader(l_urlStream,"utf-8"));
    		                while ((sCurrentLine = l_reader.readLine()) != null) {
    			                sTotalString += sCurrentLine;
    		                }				
    		                  System.out.println("result2:"+sTotalString); 
    		                  return sTotalString;
    		                }catch(Exception ex){
    			                ex.printStackTrace();
    			                return "{\"errorcode\":\"1\",\"errormsg\":\"网络请求异常\"}";
    		                }
                        }