使用nodejs在乐山lwm2m服务器中的Iam新手, 我的问题是,当我在同一台服务器上同时运行所有 lwm2m引导服务器, lwm2m服务器和 nodejs客户端时,一切正常,但是我希望分别在不同服务器上的 lwm2m引导服务器和 lwm2m服务器,会发生以下错误:
Error during bootstrap write of security instance LwM2mObjectInstance [id=1, resources={0=LwM2mSingleResource [id=0, value=coap://serverIP:5683, type=STRING], 1=LwM2mSingleResource [id=1, value=false, type=BOOLEAN], 2=LwM2mSingleResource [id=2, value=3, type=INTEGER], 3=LwM2mSingleResource [id=3, value=[B@14f84ed2, type=OPAQUE], 4=LwM2mSingleResource [id=4, value=[B@26dd8bf3, type=OPAQUE], 5=LwM2mSingleResource [id=5, value=[B@45b87cb1, type=OPAQUE], 6=LwM2mSingleResource [id=6, value=3, type=INTEGER], 7=LwM2mSingleResource [id=7, value=[B@48ffc30a, type=OPAQUE], 8=LwM2mSingleResource [id=8, value=[B@1e279a19, type=OPAQUE], 9=LwM2mSingleResource [id=9, value=, type=STRING], 10=LwM2mSingleResource [id=10, value=123, type=INTEGER], 11=LwM2mSingleResource [id=11, value=1, type=INTEGER], 12=LwM2mSingleResource [id=12, value=0, type=INTEGER]}] on mahsa
org.eclipse.leshan.core.request.exception.TimeoutException: Request coap://151.242.43.51:41375/0/1 timed out
at org.eclipse.leshan.core.californium.CoapAsyncRequestObserver.onCancel(CoapAsyncRequestObserver.java:87)
at org.eclipse.californium.core.coap.Message.setCanceled(Message.java:695)
at org.eclipse.californium.core.coap.Request.setCanceled(Request.java:785)
at org.eclipse.californium.core.coap.Message.cancel(Message.java:888)
at org.eclipse.leshan.core.californium.CoapAsyncRequestObserver$1.run(CoapAsyncRequestObserver.java:111)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
2018-12-19 09:00:00,102 DEBUG BootstrapHandler$5 - Error during bootstrap write of security instance LwM2mObjectInstance [id=1, resources={0=LwM2mSingleResource [id=0, value=coap://159.65.89.246:5683, type=STRING], 1=LwM2mSingleResource [id=1, value=false, type=BOOLEAN], 2=LwM2mSingleResource [id=2, value=3, type=INTEGER], 3=LwM2mSingleResource [id=3, value=[B@14f84ed2, type=OPAQUE], 4=LwM2mSingleResource [id=4, value=[B@26dd8bf3, type=OPAQUE], 5=LwM2mSingleResource [id=5, value=[B@45b87cb1, type=OPAQUE], 6=LwM2mSingleResource [id=6, value=3, type=INTEGER], 7=LwM2mSingleResource [id=7, value=[B@48ffc30a, type=OPAQUE], 8=LwM2mSingleResource [id=8, value=[B@1e279a19, type=OPAQUE], 9=LwM2mSingleResource [id=9, value=, type=STRING], 10=LwM2mSingleResource [id=10, value=123, type=INTEGER], 11=LwM2mSingleResource [id=11, value=1, type=INTEGER], 12=LwM2mSingleResource [id=12, value=0, type=INTEGER]}] on mahsa
org.eclipse.leshan.core.request.exception.TimeoutException: Request coap://151.242.43.51:41375/0/1 timed out
at org.eclipse.leshan.core.californium.CoapAsyncRequestObserver.onCancel(CoapAsyncRequestObserver.java:87)
at org.eclipse.californium.core.coap.Message.setCanceled(Message.java:695)
at org.eclipse.californium.core.coap.Request.setCanceled(Request.java:785)
at org.eclipse.californium.core.coap.Message.cancel(Message.java:888)
at org.eclipse.leshan.core.californium.CoapAsyncRequestObserver$1.run(CoapAsyncRequestObserver.java:111)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
我为引导服务器运行以下命令:
java -jar leshan-bsserver-demo-1.0.0-M9-jar-with-dependencies.jar -lp 5681 -slp 5682 -wp 8000
而这个用于lwm2m服务器:java -jar leshan-server-demo-1.0.0-M9-jar-with-dependencies.jar -lp 5683 -slp 5684 -wp 8080
我的客户代码是:
var CoapNode=require('coap-node'),
SmartObject=require('smartobject');
const DEVICE_NAME = "client1";
const SERVER_IP = "serverIP";
const SERVER_PORT = 5681;
var so = new SmartObject();
// initialize your Resources
// oid = 'temperature', iid = 0
so.init('temperature', 0, {
_state: {
tempVal: 26
},
sensorValue: {
read: function (cb) {
console.log('read is called!');
cb(null, this._state.tempVal);},
write: function (val, cb) {
console.log('write is called: '
+val);
this._state.tempVal = val;
cb(null, this._state.tempVal);
}
},
units: 'cel'
});
var coapNode = new
CoapNode(DEVICE_NAME, so, {
lifetime: 300 });
coapNode.on('bootstrapped',
function (data) {
console.log('bootstrapped');
coapNode.registerAllCfg(function
(err, rsp) {
console.log(rsp);
});
});
coapNode.on('registered',function(){
setInterval(function () {
var analogVal = ((Math.random()
*(30-25+1))+25).toFixed(1);
so.write('temperature',0,
'sensorValue',analogVal,function(err,val){
if (!err)
console.log("timer
value written: " + val);
else
console.log("timer
write error: " + err);
});
}, 10 * 1000);
});
coapNode.on('deregistered',
function (msg) {
console.log('deregistered');
});
coapNode.on('offline', function
(msg) {
console.log('offline');
});
coapNode.on('reconnect', function
(msg) {
console.log('reconnect');
});
coapNode.on('error', function (err)
{
console.log(err);
});
coapNode.bootstrap(SERVER_IP,
SERVER_PORT, function (err, rsp) {
if(err) {
console.log(rsp);
} else {
console.log(rsp);
}
});