Working config node and xiaomi-ht node, added package.json
This commit is contained in:
@@ -5,12 +5,12 @@
|
||||
defaults: {
|
||||
gateway: {value:"", type:"xiaomi-gateway"},
|
||||
name: {value: ""},
|
||||
sid: {value: "", required: true, validate: RED.validators.regex(/^[a-f0-9]{14}$/)},
|
||||
sid: {value: "", required: true},
|
||||
temperature: {value: "{{temperature}}"},
|
||||
humidity: {value: "{{humidity}}"},
|
||||
output: {value: "0"}
|
||||
},
|
||||
inputs: 0,
|
||||
inputs: 1,
|
||||
outputs: 2,
|
||||
outputLabels: ["Temperature","Humidity"],
|
||||
icon: "thermometer-icon.png",
|
||||
@@ -18,6 +18,13 @@
|
||||
return this.name || "xiaomi-ht";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var node = this;
|
||||
|
||||
// Get the config node id from the select box:
|
||||
var configNodeID = $('#node-input-gateway').val();
|
||||
// Get the config node using the ID:
|
||||
var configNode = RED.nodes.node(configNodeID);
|
||||
|
||||
$("#node-input-output").change(function () {
|
||||
if ($(this).val() == "2") {
|
||||
$(".node-input-msg").show();
|
||||
@@ -29,6 +36,19 @@
|
||||
$(".node-input-msg").hide();
|
||||
$("#node-input-output").val(node.output);
|
||||
|
||||
$("#node-input-gateway").change(function () {
|
||||
|
||||
});
|
||||
|
||||
for (key in configNode.deviceList) {
|
||||
var device = configNode.deviceList[key];
|
||||
$('#node-input-sid').append('<option value="' + device.sid + '">' + device.desc + '</option>');
|
||||
}
|
||||
$('#node-input-sid').val(node.sid);
|
||||
},
|
||||
oneditsave: function() {
|
||||
var node = this;
|
||||
node.sid = $("#node-input-sid").val();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -43,9 +63,13 @@
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-sid"><i class="fa fa-id-badge"></i> Device SID</label>
|
||||
<input type="text" id="node-input-sid">
|
||||
<label for="node-input-sid"><i class="icon-tag"></i> Device</label>
|
||||
<select id="node-input-sid" placeholder="xiaomi gateway"></select>
|
||||
</div>
|
||||
<!--<div class="form-row">-->
|
||||
<!--<label for="node-input-sid"><i class="fa fa-id-badge"></i> Device SID</label>-->
|
||||
<!--<input type="text" id="node-input-sid">-->
|
||||
<!--</div>-->
|
||||
<div class="form-row">
|
||||
<label for="node-input-output"><i class="icon-tag"></i> Output</label>
|
||||
<select id="node-input-output" style="width:70%;">
|
||||
|
||||
@@ -17,44 +17,12 @@ module.exports = function(RED) {
|
||||
node.status({fill:"grey",shape:"ring",text:"battery"});
|
||||
|
||||
if (this.gateway) {
|
||||
|
||||
var opts = {type: node.gateway.udpv, reuseAddr:true};
|
||||
var server;
|
||||
|
||||
if (!udpInputPortsInUse.hasOwnProperty(node.gateway.port)) {
|
||||
node.log("New UDP socket");
|
||||
server = dgram.createSocket(opts); // default to udp4
|
||||
udpInputPortsInUse[node.gateway.port] = server;
|
||||
}
|
||||
else {
|
||||
node.warn(RED._("udp.errors.alreadyused", node.gateway.port));
|
||||
server = udpInputPortsInUse[node.gateway.port]; // re-use existing
|
||||
}
|
||||
|
||||
server.on('listening', function () {
|
||||
server.setBroadcast(true);
|
||||
try {
|
||||
server.setMulticastTTL(128);
|
||||
server.addMembership(node.gateway.group, null);
|
||||
node.log(RED._("udp.status.mc-group",{group:node.gateway.group}));
|
||||
|
||||
} catch (e) {
|
||||
if (e.errno == "EINVAL") {
|
||||
node.error(RED._("udp.errors.bad-mcaddress"));
|
||||
} else if (e.errno == "ENODEV") {
|
||||
node.error(RED._("udp.errors.interface"));
|
||||
} else {
|
||||
node.error(RED._("udp.errors.error",{error:e.errno}));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
server.on('message', function(msg, rinfo) {
|
||||
var payload = JSON.parse(msg);
|
||||
|
||||
node.on('input', function(msg) {
|
||||
// var payload = JSON.parse(msg);
|
||||
var payload = msg.payload;
|
||||
node.log("Received message from: " + payload.model + " sid: " + payload.sid + " payload: " + payload.data);
|
||||
|
||||
if (payload.sid == node.sid) {
|
||||
if (payload.sid == node.sid && payload.model == "sensor_ht") {
|
||||
var data = JSON.parse(payload.data)
|
||||
|
||||
if (data.voltage) {
|
||||
@@ -65,8 +33,6 @@ module.exports = function(RED) {
|
||||
} else {
|
||||
node.status({fill:"green",shape:"dot",text:"battery"});
|
||||
}
|
||||
} else {
|
||||
node.status({fill:"grey",shape:"ring",text:"battery"});
|
||||
}
|
||||
|
||||
if (node.output == "0") {
|
||||
@@ -100,30 +66,15 @@ module.exports = function(RED) {
|
||||
}
|
||||
});
|
||||
|
||||
node.on("input", function(msg) {
|
||||
// console.log("got input");
|
||||
});
|
||||
|
||||
node.on("close", function() {
|
||||
if (udpInputPortsInUse.hasOwnProperty(node.gateway.port)) {
|
||||
delete udpInputPortsInUse[node.gateway.port];
|
||||
}
|
||||
server.close();
|
||||
});
|
||||
|
||||
try { server.bind(node.gateway.port, null); }
|
||||
catch(e) { } // Don't worry if already bound
|
||||
|
||||
} else {
|
||||
// no gateway configured
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RED.httpAdmin.get('/udp-ports/:id', RED.auth.needsPermission('udp-ports.read'), function(req,res) {
|
||||
res.json(Object.keys(udpInputPortsInUse));
|
||||
});
|
||||
|
||||
RED.nodes.registerType("xiaomi-ht", XiaomiHtNode);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user