@@ -10,11 +10,11 @@ module.exports = (RED) => {
|
|||||||
RED.nodes.createNode(this, config);
|
RED.nodes.createNode(this, config);
|
||||||
this.gateway = RED.nodes.getNode(config.gateway);
|
this.gateway = RED.nodes.getNode(config.gateway);
|
||||||
|
|
||||||
|
this.status({fill:"red", shape:"ring", text: "offline"});
|
||||||
|
|
||||||
if (this.gateway) {
|
if (this.gateway) {
|
||||||
this.on('input', (msg) => {
|
this.on('input', (msg) => {
|
||||||
// var payload = JSON.parse(msg);
|
|
||||||
var payload = msg.payload;
|
var payload = msg.payload;
|
||||||
//this.log("Received message from: " + payload.model + " sid: " + payload.sid + " payload: " + payload.data);
|
|
||||||
|
|
||||||
// Input from gateway
|
// Input from gateway
|
||||||
if(payload.sid) {
|
if(payload.sid) {
|
||||||
@@ -41,6 +41,7 @@ module.exports = (RED) => {
|
|||||||
// The Input Node
|
// The Input Node
|
||||||
function GatewayIn(n) {
|
function GatewayIn(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
this.gatewayNodeId = n.gateway;
|
||||||
this.gateway = RED.nodes.getNode(n.gateway);
|
this.gateway = RED.nodes.getNode(n.gateway);
|
||||||
this.group = "224.0.0.50";
|
this.group = "224.0.0.50";
|
||||||
this.port = 9898;
|
this.port = 9898;
|
||||||
@@ -48,6 +49,8 @@ module.exports = (RED) => {
|
|||||||
this.addr = n.ip;
|
this.addr = n.ip;
|
||||||
this.ipv = this.ip && this.ip.indexOf(":") >= 0 ? "udp6" : "udp4";
|
this.ipv = this.ip && this.ip.indexOf(":") >= 0 ? "udp6" : "udp4";
|
||||||
|
|
||||||
|
this.status({fill:"red", shape:"ring", text: "offline"});
|
||||||
|
|
||||||
var opts = {type:this.ipv, reuseAddr:true};
|
var opts = {type:this.ipv, reuseAddr:true};
|
||||||
if (process.version.indexOf("v0.10") === 0) { opts = this.ipv; }
|
if (process.version.indexOf("v0.10") === 0) { opts = this.ipv; }
|
||||||
var server;
|
var server;
|
||||||
@@ -84,10 +87,18 @@ module.exports = (RED) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
msg = { payload: jsonMsg };
|
msg = { payload: jsonMsg };
|
||||||
if(jsonMsg.token && this.gateway && jsonMsg.data.ip && jsonMsg.data.ip === this.gateway.ip) {
|
if(this.gateway && jsonMsg.data.ip && jsonMsg.data.ip === this.gateway.ip) {
|
||||||
this.gateway.lastToken = jsonMsg.token;
|
RED.nodes.eachNode((tmpNode) => {
|
||||||
if(!this.gateway.sid) {
|
if(tmpNode.type.indexOf("xiaomi-gateway") === 0 && tmpNode.gateway == this.gatewayNodeId) {
|
||||||
this.gateway.sid = jsonMsg.sid;
|
let tmpNodeInst = RED.nodes.getNode(tmpNode.id);
|
||||||
|
tmpNodeInst.status({fill:"blue", shape:"dot", text: "online"});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(jsonMsg.token) {
|
||||||
|
this.gateway.lastToken = jsonMsg.token;
|
||||||
|
if(!this.gateway.sid) {
|
||||||
|
this.gateway.sid = jsonMsg.sid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
@@ -144,6 +155,8 @@ module.exports = (RED) => {
|
|||||||
this.ipv = this.ip && this.ip.indexOf(":") >= 0 ? "udp6" : "udp4";
|
this.ipv = this.ip && this.ip.indexOf(":") >= 0 ? "udp6" : "udp4";
|
||||||
this.multicast = false;
|
this.multicast = false;
|
||||||
|
|
||||||
|
this.status({fill:"red", shape:"ring", text: "offline"});
|
||||||
|
|
||||||
var opts = {type:this.ipv, reuseAddr:true};
|
var opts = {type:this.ipv, reuseAddr:true};
|
||||||
if (process.version.indexOf("v0.10") === 0) { opts = this.ipv; }
|
if (process.version.indexOf("v0.10") === 0) { opts = this.ipv; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user