iot api json数据包格式

18 篇文章 0 订阅
16 篇文章 2 订阅

[REST api]


0417 api 设计


站点
====================================
创建一个新站点
POST /iot/api/sites/


http://localhost:8080/iot/api/sites  
[body]
{  
  "token" : "", //如果请求中不带token,系统生成唯一token  
  "name" : "REST Site",  //站点名字
  "description" : "REST site ", //站点描述  
  "metadata" : { } //可选,站点元数据 
}
  
[response]
{  
  "createdDate": "", //创建日期  
  "createdBy": "admin",  //创建者
  "deleted": false,  //是否被删除
  "token": "",  //返回token
  "name": "REST Site",  //站点名字
  "description": "",  //站点描述
  "metadata": {} //可选,站点元数据 
}  


根据token获取站点
GET /iot/api/sites/<string:token>


http://localhost:8080/iot/api/sites/<int:token>






根据token删除站点
DELETE /iot/api/sites/<string:token>


http://localhost:8080/iot/api/sites/<int:token>
[body]


[response]
{  
  "createdDate": "", //创建日期  
  "createdBy": "admin",  //创建者
  "deleted": false,  //是否被删除
  "token": "",  //token
  "name": "12",  //站点名字
  "description": "12",  //站点描述
  "metadata": {} //可选,站点元数据 
}   




租户
======================================================
创建一个新租户
POST /iot/api/tenants


curl -X GET http://127.0.0.1:5000/iot/api/tenants


curl -X GET http://127.0.0.1:5000/iot/api/tenants/test1


curl -X POST http://127.0.0.1:5000/iot/api/tenants 

-d '{"id":"test","name":"test tenant","authenticationToken":"","authorizedUserIds":["admin"],"metadata" : {}}'



curl -X DELET http://127.0.0.1:5000/iot/api/tenants






用户
======================================================
创建一个新用户
POST /iot/api/users


http://localhost:8080/iot/api/users
[body]
{
  "username": "", //用户名
  "password": "", //密码
  "firstName": "", //
  "lastName": "", //
  "status": "", //状态
  "metadata": "" //可选,元数据
}
[response]
{
  "createdDate": "", //创建日期
  "createdBy": "", //创建者
  "deleted": false, //是否被删除
  "username": "", //用户名
  "hashedPassword": "", //密码hash
  "firstName": "", //
  "lastName": "", //
  "lastLogin": "", //最近登录时间
  "status": "", //状态
  "metadata": "" //可选,元数据
}


根据username获取用户
GET /iot/api/users/<string:username>


http://127.0.0.1:8080/iot/api/users/<string:username>




根据用户名删除用户
DELETE /iot/api/users/<string:username>


http://127.0.0.1:8080/iot/api/users/<string:username>
[body]


[response]
{
  "createdDate": "",    //创建日期
  "createdBy": "",      //创建者
  "deleted": false,     //是否被删除
  "username": "",       //用户名
  "hashedPassword": "", //密码hash
  "firstName": "",      // 
  "lastName": "",       // 
  "lastLogin": "",      //最近登录时间
  "status": "",         //状态
  "metadata": ""        //可选,元数据
}
[error]
{
  "timestamp": 1523954254707,
  "status": 404,
  "error": "Not Found",
  "message": "InvalidUsername:Username does not exist.",
  "path": "/iot/api/users/111"
}


设备
========================================================
创建一个新设备
POST /iot/api/devices/


http://localhost:8080/iot/api/devices 
[body]
{  
  "hardwareId" : "test1234567",  //设备ID
  "siteToken" : "", //站点token   
  "comments" : "Equipment tracker."  //
  "status": "", //状态
  "metadata": "object" //
}
[response]
{  
  "createdDate": "", //创建日期 
  "createdBy": "admin",  //创建者
  "deleted": false,  //是否被删除
  "hardwareId": "test1234567",  //设备ID
  "siteToken": "",  //token
  "comments": "Equipment tracker.",  //注释
  "metadata": {}  //元数据
}  


根据设备ID获取设备信息
GET /iot/api/devices/<int:hardwareId>


http://127.0.0.1:8080/iot/api/devices/<int:hardwareId>






根据设备ID删除设备
DELETE /iot/api/devices/<int:hardwareId>


http://127.0.0.1:8080/iot/api/devices/<int:hardwareId>
[body]


[response]
{
  "createdDate": "",                    //创建日期
  "createdBy": "admin",                 //创建者
  "deleted": false,                     //
  "hardwareId": "test1234567",          //
  "siteToken": "",                      //            
  "comments": "Equipment tracker.",     //
  "metadata": {}                        //
}




事件
============================================================
存储设备数据###用户禁止调用
POST /iot/api/devices/<int:hardwareId>/events/


http://127.0.0.1:8080/iot/api/devices/<int:hardwareId>/events/


[body]
{
    "hardwareId" : "test1234567",        //设备ID
    "eventType" : "Measurements",      //事件类型
    "siteToken" : "bb105f8d-3150-41f5-b9d1-db04965668d3",    //token
    "eventDate" : ISODate("2018-03-22T05:45:40.499Z"), //
    "receivedDate" : ISODate("2018-03-22T07:40:56.884Z"), //
    "metadata" : { 
    
    },  
    "measurements" : [                  //数据  
        {
            "name" : "engine.temperature",
            "value" : 166.08
        },
        {
            "name" : "fuel.level",
            "value" : 82.94
        }
    ]   
}
[response]
....




获取设备数据
GET /iot/api/devices/<int:hardwareId>/events/?resum=1


http://127.0.0.1:8080/iot/api/devices/<int:hardwareId>/events/?resum=1


[response]


{
"hardwareId" : "test1234567", //设备ID
    "eventType" : "Measurements", //事件类型
    "siteToken" : "bb105f8d-3150-41f5-b9d1-db04965668d3", //token
    "eventDate" : ISODate("2018-03-22T05:45:40.499Z"),
    "receivedDate" : ISODate("2018-03-22T07:40:56.884Z"),
    "metadata" : { 
    
    },  
    "measurements" : [ //数据 
        {
            "name" : "engine.temperature",
            "value" : 166.08
        },
        {
            "name" : "fuel.level",
            "value" : 82.94
        }
    ]   

}


资料:
http://www.jikexueyuan.com/course/837.html
http://www.cnblogs.com/vovlie/p/4178077.html
https://blog.openshift.com/rest-web-services-with-python-mongodb-and-spatial-data-in-the-cloud-part-2/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值