Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions 8dev_emulate/nodes/clientNodeInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function putObjectInstance(objectInstance, description) {
}

class ClientNodeInstance extends EventEmitter {
constructor(lifetime, manufacturer, model, queueMode, endpointClientName, serverURI, clientPort) {
constructor(options) {
super();

this._state = 'stopped'; // eslint-disable-line no-underscore-dangle
Expand All @@ -112,32 +112,40 @@ class ClientNodeInstance extends EventEmitter {
this.updatesIterator = {};
this.observedResources = {};
this.registrationPath = '/rd';
this.listeningPort = clientPort;
this.listeningPort = options.clientPort;
this.updatesInterval = 10; // updates interval in seconds
this.endpointClientName = endpointClientName;
this.endpointClientName = options.endpointClientName;

this.coapServer = coap.createServer({ type: 'udp6' }, (req, res) => {
this.requestListener(req, res);
});
this.coapServer.listen(clientPort);
this.coapServer.listen(options.clientPort);
this.coapAgent = new coap.Agent({
type: 'udp6',
socket: this.coapServer._sock, // eslint-disable-line no-underscore-dangle
});

this.coapAgent.on('error', (error) => {
this.emit('error', error);
});
this.coapServer.on('error', (error) => {
this.emit('error', error);
});

this.requestOptions = {
host: serverURI,
port: 5555,
host: options.serverURI,
port: options.serverPort,
method: 'POST',
confirmable: 'true',
agent: this.coapAgent,
};

this.stateListener();

this.initiateSecurityObject(serverURI);
this.initiateServerObject(lifetime, queueMode);
this.initiateSecurityObject(options.serverURI);
this.initiateServerObject(options.lifetime, options.queueMode);
this.initiateAccessControlObject();
this.initiateDeviceObject(manufacturer, model, queueMode);
this.initiateDeviceObject(options.manufacturer, options.model, options.queueMode);
this.initiateConnectivityMonitoringObject();
this.initiateFirmwareObject();
this.initiateLocationObject();
Expand Down Expand Up @@ -787,6 +795,7 @@ class ClientNodeInstance extends EventEmitter {
break;
}
case 'registered': {
this.emit('registered');
break;
}
default: {
Expand Down
16 changes: 8 additions & 8 deletions 8dev_emulate/nodes/sensorInstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function humiditySensorHandle(averageHumidity = 70, fluctuation = 0.05) {
}

class Sensor3700 extends ClientNode {
constructor(lifetime, UUID, serverIP, clientPort) {
super(lifetime, '8devices', '8dev_3700', true, UUID, serverIP, clientPort);
constructor(options) {
super(options);

this.initialisePowerSourceVoltageResource();
this.initialisePowerMeasurementObject();
Expand Down Expand Up @@ -138,8 +138,8 @@ class Sensor3700 extends ClientNode {
}

class Sensor3800 extends ClientNode {
constructor(lifetime, UUID, serverIP, clientPort) {
super(lifetime, '8devices', '8dev_3800', true, UUID, serverIP, clientPort);
constructor(options) {
super(options);

this.initialisePowerSourceVoltageResource();
this.initialiseTemperatureSensorObject();
Expand Down Expand Up @@ -184,8 +184,8 @@ class Sensor3800 extends ClientNode {
}

class Sensor4400 extends ClientNode {
constructor(lifetime, UUID, serverIP, clientPort) {
super(lifetime, '8devices', '8dev_4400', true, UUID, serverIP, clientPort);
constructor(options) {
super(options);

this.initialisePowerSourceVoltageResource();
this.initialiseDigitalInputObject();
Expand Down Expand Up @@ -251,8 +251,8 @@ class Sensor4400 extends ClientNode {
}

class Sensor4500 extends ClientNode {
constructor(lifetime, UUID, serverIP, clientPort) {
super(lifetime, '8devices', '8dev_4500', true, UUID, serverIP, clientPort);
constructor(options) {
super(options);

this.initialisePowerSourceVoltageResource();
this.initialiseAnalogueInputOjbect();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
},
"homepage": "https://github.com/8devices/restserver-api#readme",
"dependencies": {
"coap": "git+https://github.com/mcollina/node-coap.git#v0.23.0",
"body-parser": "^1.18.2",
"coap": "^0.21.0",
"express": "^4.16.3",
"ip": "^1.1.5",
"node-rest-client": "^3.1.0"
Expand Down