mirror of
https://github.com/lehanspb/tuya-mqtt.git
synced 2025-12-18 08:13:23 +00:00
should fix #11
This commit is contained in:
@@ -3,5 +3,6 @@
|
|||||||
"port": 1883,
|
"port": 1883,
|
||||||
"topic": "tuya/",
|
"topic": "tuya/",
|
||||||
"mqtt_user": "",
|
"mqtt_user": "",
|
||||||
"mqtt_pass": ""
|
"mqtt_pass": "",
|
||||||
|
"qos": 2
|
||||||
}
|
}
|
||||||
|
|||||||
19
tuya-mqtt.js
19
tuya-mqtt.js
@@ -36,7 +36,9 @@ mqtt_client.on('connect', function (err) {
|
|||||||
debugMqtt("Verbindung mit MQTT-Server hergestellt");
|
debugMqtt("Verbindung mit MQTT-Server hergestellt");
|
||||||
connected = true;
|
connected = true;
|
||||||
var topic = CONFIG.topic + '#';
|
var topic = CONFIG.topic + '#';
|
||||||
mqtt_client.subscribe(topic);
|
mqtt_client.subscribe(topic, {
|
||||||
|
qos: CONFIG.qos
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
mqtt_client.on("reconnect", function (error) {
|
mqtt_client.on("reconnect", function (error) {
|
||||||
@@ -76,7 +78,7 @@ mqtt_client.on('message', function (topic, message) {
|
|||||||
|
|
||||||
if (exec == "command") {
|
if (exec == "command") {
|
||||||
var status = topic[6];
|
var status = topic[6];
|
||||||
if ( status == null ) {
|
if (status == null) {
|
||||||
device.onoff(message);
|
device.onoff(message);
|
||||||
} else {
|
} else {
|
||||||
device.onoff(status);
|
device.onoff(status);
|
||||||
@@ -109,7 +111,7 @@ function publishStatus(device, status) {
|
|||||||
var topic = CONFIG.topic + type + "/" + tuyaID + "/" + tuyaKey + "/" + tuyaIP + "/state";
|
var topic = CONFIG.topic + type + "/" + tuyaID + "/" + tuyaKey + "/" + tuyaIP + "/state";
|
||||||
mqtt_client.publish(topic, status, {
|
mqtt_client.publish(topic, status, {
|
||||||
retain: true,
|
retain: true,
|
||||||
qos: 2
|
qos: CONFIG.qos
|
||||||
});
|
});
|
||||||
debugTuya("mqtt status updated to:" + topic + " -> " + status);
|
debugTuya("mqtt status updated to:" + topic + " -> " + status);
|
||||||
} else {
|
} else {
|
||||||
@@ -140,7 +142,7 @@ function publishDPS(device, dps) {
|
|||||||
debugTuya("mqtt dps updated to:" + topic + " -> ", data);
|
debugTuya("mqtt dps updated to:" + topic + " -> ", data);
|
||||||
mqtt_client.publish(topic, data, {
|
mqtt_client.publish(topic, data, {
|
||||||
retain: true,
|
retain: true,
|
||||||
qos: 2
|
qos: CONFIG.qos
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(dps).forEach(function (key) {
|
Object.keys(dps).forEach(function (key) {
|
||||||
@@ -149,7 +151,7 @@ function publishDPS(device, dps) {
|
|||||||
debugTuya("mqtt dps updated to:" + topic + " -> dps[" + key + "]", data);
|
debugTuya("mqtt dps updated to:" + topic + " -> dps[" + key + "]", data);
|
||||||
mqtt_client.publish(topic, data, {
|
mqtt_client.publish(topic, data, {
|
||||||
retain: true,
|
retain: true,
|
||||||
qos: 2
|
qos: CONFIG.qos
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -169,10 +171,9 @@ TuyaDevice.onAll('data', function (data) {
|
|||||||
try {
|
try {
|
||||||
debugTuya('Data from device ' + this.type + ' :', data);
|
debugTuya('Data from device ' + this.type + ' :', data);
|
||||||
var status = data.dps['1'];
|
var status = data.dps['1'];
|
||||||
if (this.type == "lightbulb" && status == undefined) {
|
if (status != undefined) {
|
||||||
status = true;
|
|
||||||
}
|
|
||||||
publishStatus(this, bmap(status));
|
publishStatus(this, bmap(status));
|
||||||
|
}
|
||||||
publishDPS(this, data.dps);
|
publishDPS(this, data.dps);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugError(e);
|
debugError(e);
|
||||||
@@ -217,5 +218,5 @@ var tester = new MQTT_Tester();
|
|||||||
*/
|
*/
|
||||||
function onExit() {
|
function onExit() {
|
||||||
TuyaDevice.disconnectAll();
|
TuyaDevice.disconnectAll();
|
||||||
if(tester) tester.destroy();
|
if (tester) tester.destroy();
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user