Hey guys,
I’m trying to light the esp32 builtin led using an action but isn’t works(I’m totally a newbie).
I am using a code for ESP and by live inspector I have:
Blockquote
20:02:40:
[MQTT] Device connected
“Token Ending: f97b9 Client-ID: Sentinela Will-Message: true”
20:02:41:
[MQTT] Device publish
{ “topic”: “tago/data/post”, “payload”: “0600”, “qos”: 1, “messageId”: 1145 }
20:02:41:
Raw payload:
[ { “variable”: “payload”, “value”: “0600”, “metadata”: { “mqtt_topic”: “tago/data/post” } } ]
20:02:41:
Result of [device] payload parser:
[ { “variable”: “payload”, “value”: “0600”, “metadata”: { “mqtt_topic”: “tago/data/post” }, “serie”: “1627945361169” }, { “variable”: “umidsolo”, “value”: 6, “unit”: “%”, “serie”: “1627945361169” }, { “variable”: “led”, “value”: 0, “serie”: “1627945361169” } ]
20:02:41:
Bucket [a5f8]:
“3 Data Added”
20:02:41:
[MQTT] Device disconnected
“socket event: disconnect”
This is my payload parser:
const ignore_vars = ['messageId','topic','qos'];
payload = payload.filter(x => !ignore_vars.includes(x.variable));
const mqtt_payload = payload.find((data) => data.variable === "payload" || (data.metadata && data.metadata.mqtt_topic));
if (mqtt_payload) {
// Cast the hexadecimal to a buffer.
const buffer = Buffer.from(mqtt_payload.value, 'hex')
// Normalize the data to TagoIO format.
// We use Number function to cast number values, so we can use it on chart widgets, etc.
const data = [
{ variable: 'umidsolo', value: buffer.readInt8(0), unit: '%' },
{ variable: 'led', value: buffer.readInt8(1) },
//{ variable: 'temperature', value: buffer.readInt16BE(1) / 100, unit: '°C' },
//{ variable: 'humidity', value: buffer.readUInt16BE(3) / 100, unit: '%' },
];
// This will concat the content sent by your device with the content generated in this payload parser.
// It also adds the field "serie" to be able to group in tables and other widgets.
const serie = String(new Date().getTime());
payload = payload.concat(data).map(x => ({ ...x, serie }));
}
The parser result is:
{
"variable": "payload",
"value": "0400",
"metadata": {
"mqtt_topic": "tago/data/post"
},
"serie": "1627945571473"
},
{
"variable": "umidsolo",
"value": 4,
"unit": "%",
"serie": "1627945571473"
},
{
"variable": "led",
"value": 0,
"serie": "1627945571473"
}
I set an action to save data in the bucket and I think that its working well cause i can see that variables in my dashboard widget.
The problem is the method that I am working with the action to light the led or my code(Arduino MqttClient library example) isn’t working well.
I can see all msg in my terminal…device is sending data to tago but never received nothing from there.
There is an example with a code+payload parser + action to light a led?
Thanks in advance
Kind regards