在经过几天的努力之后,终于可以支持用
npm install 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;"
}
而在创建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 Idea墙, 也许,你会遇到心仪的项目