Blog

Blog

PHODAL

IoT CoAP Node包创建与安装

在经过几天的努力之后,终于可以支持用

 npm install iot-coap

安装了。算是一个新的进步,然而虽然支持不是很完善,但是现在就先这样。。

安装IoT CoAP

在上面的描述中,我们已经知道安装方法是

npm install iot-coap

接着我们创建一个简单的server.js

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

iotcoap.run();

同时我们还需要配置好我们的数据库,对于当前来说,数据库应该是这样子的

{
    "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;"
}

创建IoT CoAP

而在创建node包的时候,我们需要一个package.json,有一些基础的信息

{
  "name": "iot-coap",
  "version": "0.0.6",
  "description": "Mini IoT CoAP Version",
  "repository": {
    "type": "git",
    "url": "git@github.com:gmszone/iot-coap.git"
  },
  "dependencies": {
    "coap": "0.8.0",
    "bl": "~0.9.0",
    "coap-cli": "0.3.0",
    "sqlite3": "2.2.7",
    "underscore": "1.6.0",
    "jstoxml": "0.2.2"
  },
  "keywords": [
    "coap",
    "iot",
    "internet of things"
  ],
  "author": [
    {
      "name": "Fengda HUANG",
      "url": "https://www.phodal.com/"
    }
  ],
  "license": "MIT",
  "devDependencies": {
    "pre-commit": "0.0.9",
    "chai": "~1.9.1",
    "mocha": "~1.21.4",
    "timekeeper": "0.0.4",
    "sinon": "~1.7.3"
  },
  "pre-commit": [
    "test"
  ],
  "scripts": {
    "test": "./node_modules/.bin/mocha --bail --reporter spec 2>&1"
  }
}

包含一些基本的信息如,包名,版本,依赖,作者等等,当然还包括了一个测试的脚本。而我们需要创建一个index.js,再export出iotcoap这个函数。最后我们就有了,一个简单的可以用的包,当然先包方法里面的内容给清了。

const coap             = require('coap')
      ,server          = coap.createServer({})
      ,fs              = require('fs')
      ,file            = './iot.json';

function iotcoap(){

}

iotcoap.run = function(){

};

module.exports = iotcoap;

我们便可以实现在步骤一的事情了。

关于我

Github: @phodal     微博:@phodal     知乎:@phodal    

微信公众号(Phodal)

围观我的Github Idea墙, 也许,你会遇到心仪的项目

QQ技术交流群: 321689806
comment

Feeds

RSS / Atom

最近文章

关于作者

Phodal Huang

Engineer, Consultant, Writer, Designer

ThoughtWorks 技术专家

工程师 / 咨询师 / 作家 / 设计学徒

开源深度爱好者

出版有《前端架构:从入门到微前端》、《自己动手设计物联网》、《全栈应用开发:精益实践》

联系我: h@phodal.com

微信公众号: 最新技术分享

标签