Giter Site home page Giter Site logo

iot-coap's Introduction

Build Status Version Code Climate Test Coverage Dependencies

NPM

NPM

Tested on: Node 0.10.32, and 0.11.13

#CoAP协议 IOT Framework

Mini Internet of Things System with CoAP Protocol. HTTP protocol With RESTful to https://github.com/phodal/iot

吊兰-MQTT协议,CoAP协议,WebSocket,物联网协议在线测试(Online test for IOT Protocol)

##提醒

代码不再添加功能,仅维护(修复bug),请使用https://github.com/phodal/diaonan

##Thanks to

##Install

1.Install

npm install iot-coap

2.Create index.js

var iotcoap         = require('iot-coap');

iotcoap.run();
iotcoap.rest.run();

注意:在db配置可以选择mongodb和sqlite3,替换所需要的数据库即可。(you can choice db on iot.js with 'sqlite' or 'mongodb')

创建iot.js(Create iot.js)

exports.config  = {
    "db_name": "iot.db",
    "mongodb_name": "iot",
    "mongodb_documents": "iot",
    "db": "mongodb",
    "table_name": "basic",
    "keys":[
        "id",
        "value",
        "sensors1",
        "sensors2"
    ],
    "db_table": "id integer primary key, value text, sensors1 float, sensors2 float",
    "mongodb_init":[
        {
            id: 1,
            value: "is id 1",
            sensors1: 19,
            sensors2: 20
        },
        {
            id: 2,
            value: "is id 2",
            sensors1: 20,
            sensors2: 21
        }
    ],
    "init_table":[
        "insert or replace into basic (id,value,sensors1,sensors2) VALUES (1, 'is id 1', 19, 20);",
        "insert or replace into basic (id,value,sensors1,sensors2) VALUES (2, 'is id 2', 20, 21);"
    ],
    "query_table":"select * from basic;",
    "rest_url": "/id/:id",
    "rest_post_url": "/",
    "rest_port": 8848
};

接着运行(run)

node index.js

##Test

###Firefox

  1. 安装copper插件(下载地址:https://addons.mozilla.org/en-US/firefox/addon/copper-270430/) (install copper plugins)

  2. 选上Debug Contrl (choice Debug Control)

  3. 在Accept, Content-Format选application/json

###Node GET

node method_test/get.js

###HTTP POST

curl -H "Content-Type: application/json" -d '{"id":3, "value":"dream","sensors1":12,"sensors2":13}' http://localhost:8848

物联网相关资料收集

##配置开发环境(Setup Dev)

1.Clone

[email protected]:phodal/iot-coap.git

2.Install Dependencies

npm install

注意: 在代码提交之前会跑测试、jslint语法检查,相关机制可以查看这篇文章nodejs jslint

  1. 安装有Nodejs的OS
  2. clone完代码后执行npm install

##交流

QQ群:348100589

##文档

CoAP与物联网系统

物联网系统与CoAP之Hello,World

CoAP与物联网系统之返回JSON

CoAP与物联网系统之返回XML

IoT CoAP 块传输——使用Block传输数据

构建基于CoAP SQLite Nodejs的物联网之查询数据

构建基于CoAP SQLite Nodejs的物联网之数据库

##IDE

感谢JetBrains为我们提供了数量不限的WebStorm的License。

License

© 2014 Phodal Huang. This code is distributed under the MIT license.

iot-coap's People

Contributors

gitter-badger avatar phodal avatar yangquan3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iot-coap's Issues

RESTful设计准则

下面RESTful准则是由HTTP,Apache的设计者Fielding大神提出的,很有参考价值:

An API is a user interface for a developer - so put some effort into making it pleasant
Use RESTful URLs and actions
Use SSL everywhere, no exceptions
An API is only as good as its documentation - so have great documentation

版本号放在URL中而非协议头中

尽量采用类似 https://www.foo.com/v1/ 结构,这样更加直观

Use query parameters for advanced filtering, sorting & searching
Provide a way to limit which fields are returned from the API
Return something useful from POST, PATCH & PUT requests
HATEOAS isn't practical just yet

尽可能使用JSON而非XML

XML有更好的可读性和结构性,但是JSON适合机器阅读,具有更好的效率和更小的空间。JSON天然的和JavaScript结合得很好,使得JSON更适合RESTful架构

You should use camelCase with JSON, but snake_case is 20% easier to read
Pretty print by default & ensure gzip is supported
Don't use response envelopes by default
Consider using JSON for POST, PUT and PATCH request bodies
Paginate using Link headers
Provide a way to autoload related resource representations
Provide a way to override the HTTP method
Provide useful response headers for rate limiting
Use token based authentication, transported over OAuth2 where delegation is needed
Include response headers that facilitate caching
Define a consumable error payload
Effectively use HTTP Status codes

url是不可配置的

    function url_sanity_check(url) {
        if(url.split('/')[2] == false){
            return false;
        }
        _.each(config["key"], function (array, index) {
            if(url.split('/')[1] === config["key"][index] ){
                return true;
            }
        });
    }

关于URL的配置应该放在iot.json中

TODO

#2014-09-03 的分格线

后续有真实硬件设备后需要增加调整的功能:
1)"key":[
"id",
"value",
"sensors1",
"sensors2"
],
应该改为
"key":[
"id",
"sensor",
"value",
"binary"
],
restful 格式为 coap://127.0.0.1/v1/id/1/sensor/2/value/{json}
或者 coap://127.0.0.1/v1/id/1/sensor/2/binary/{...bin}
2)上面的{}里面的内容必须包含两个键值,一个时间戳,一个数据
3) 客户端支持 highchart 来生成实时曲线
4)数据库要调整,大家多讨论讨论
index[primary key], id, sensor, value_ts, value_data

#2014-09-11 的分格线

  1. POST /v1/id/:id 创建设备
  2. PUT /v1/id/:id 编辑设备
  3. GET /v1/id/:id 查看设备
  4. DELETE /v1/id/:id 删除设备
  5. GET /v1/id/ 罗列设备
    6)除开第4没有参数,1,2,3的参数为
    {
    "name":"foo",
    "desc":"test foo",
    "local":"SHENZHEN",
    "latitude":114.07,
    "longitude":22.33
    }
  6. 设备信息专门用一个数据库,方便后期地图使用,格式为
    id integer primary key, name text, dest text, local text, latitude real, longitude real

#2014-09-12 的分格线

  1. POST /v1/id/:id/ch/:ch 创建通道
  2. PUT /v1/id/:id/ch/:ch 编辑通道
  3. GET /v1/id/:id/ch/:ch 查看通道
  4. DELETE /v1/id/:id/ch/:ch 删除通道
  5. GET /v1/id/:id/ch 罗列通道
    6)除开第4没有参数,其它1,2,3的参数为
    {
    "type":"value" // 可选"value", "GPS", "photo", "unknown"
    "name":"temperature",
    "desc":"test sensor1",
    "unit":"°C"
    }
    7)通道信息专门用一个数据库,方便刷设备下面的通道列表,采用联合主键
    id integer primary key, ch integer primary key, name text, desc text, unit text

#2014-09-13 的分格线

  1. POST /v1/id/:id/ch/:ch/ts/:ts 创建数据点
  2. PUT /v1/id/:id/ch/:ch/ts/:ts 编辑数据点
  3. GET /v1/id/:id/ch/:ch/ts/:ts 查看数据点
  4. DELETE /v1/id/:id/ch/:ch/ts/:ts 删除数据点
    5)除开第4没有参数,其它1,2,3的参数为下面,或者为更复杂的json数据类型,客户自解释
    {
    "val": 29.34
    }
    6)数据点信息专门用一个数据库,方便未来采用时间段查询,设备号查询,通道号查询
    idx integer primary key autoincrement, id integer ,ch integer, ts datetime, val text

use Promise Patterns

use Promise Design Pattern to replace the callback hell.

使用Promise设计模式来代替现在的回调。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.