Iot-coap

物联网系统设计

This project is maintained by phodal

Build Status

NPM

NPM

物联网系统 CoAP版

这是一个开源的最小物联网系统的CoAP版,如果你还是一个初学者建议用HTTP版 https://github.com/phodal/iot

主要依赖库

install

npm install iot-coap

新建一个index.js

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

iotcoap.run();
iotcoap.rest.run(); //运行REST

创建iot.json

{
    "db_name": "iot.db",
    "table_name": "basic",
    "key":[
        "id",
        "value",
        "sensors1",
        "sensors2"
    ],
    "db_table": "id integer primary key, value text, sensors1 float, sensors2 float",
    "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
}

接着运行

node index.js

Test

node method_test/get.js

REST Test

POST

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

在线测试

  1. CoAP 修改url为

    coap://iot-coap.phodal.com

  2. RESTful 修改url为

    http://iot-coap.phodal.com:8896

文档

CoAP与物联网系统

物联网系统与CoAP之Hello,World

CoAP与物联网系统之返回JSON

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

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

Liscense

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