Any advice writing a MQTT Parse for the Automation Direct Stride MQTT Gateway?
I have tried hacking on several different parses without luck.
// prevent the code from running for normal inpputed variables (like from analysis or dashboards)
const mqtt_data = payload.find(data => data.variable === "payload" && data.metadata && data.metadata.mqtt_topic);
// Suppose that mqtt_data = [{ variable: "payload", value: "0.5,1.5", metadata: { mqtt_topic: "temp hum"} } ];
console.log(mqtt_data); // outputs content to Live Inspector.
if (mqtt_data) {
// Split the topic by the "/", to result in an array
const splited_topic = mqtt_data.metadata.mqtt_topic;
// splited_topic is [ 'temp', 'hum' ]
const splitted_value = mqtt_data.value;
// splited_topic is [ '0.5', '1.5' ]
// generate a serial based on timestamp. If you add more
// than one data, the serial will make sure it shows in the same line
// in a dynamic table widget for example.
const serie = String(new Date().getTime());
// now you should start building your normalized data to TagoIO following specifications at https://docs.tago.io/en/articles/34-sending-data
// remember to cast strings to Number to prevent issues in the future, like showing data in a chart.
payload = [
{ variable: splited_topic, value: Bool(splitted_value), serie }
];
}This text will be hidden
Below is a copy of the live inspector. Is this in JSON format? The heading of the topic needs to be changed to variable to match Tago format. Also, the gateway will send a keep alive message with its configuration. Is there a good way to implement this in Tago? Eventually, I would like to trigger an alert if connection is lost after 10 minutes.
Thanks in advance.
Jacob
`2021-10-02 16:19:01: [MQTT] Device publish {"topic":"alarm","payload":"{\"value\":1}","qos":1,"messageId":1031} 2021-10-02 16:19:01: Raw payload: [{"value":1,"metadata":{"mqtt_topic":"alarm"}}] 2021-10-02 16:19:01: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:19:05: [MQTT] Device publish {"topic":"lag","payload":"{\"value\":1}","qos":0} 2021-10-02 16:19:05: Raw payload: [{"value":1,"metadata":{"mqtt_topic":"lag"}}] 2021-10-02 16:19:05: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:19:23: [MQTT] Device publish {"topic":"count","payload":"{\"value\":8254}","qos":0} 2021-10-02 16:19:23: Raw payload: [{"value":8254,"metadata":{"mqtt_topic":"count"}}] 2021-10-02 16:19:23: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:20:54: [MQTT] Device publish {"topic":"alarm","payload":"{\"value\":\"\"}","qos":1,"messageId":4944} 2021-10-02 16:20:54: [MQTT] Device publish {"topic":"lag","payload":"{\"value\":\"\"}","qos":0} 2021-10-02 16:20:54: Raw payload: [{"value":"","metadata":{"mqtt_topic":"lag"}}] 2021-10-02 16:20:54: Raw payload: [{"value":"","metadata":{"mqtt_topic":"alarm"}}] 2021-10-02 16:20:54: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:20:54: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:20:55: [MQTT] Device publish {"topic":"count","payload":"{\"value\":\"\"}","qos":0} 2021-10-02 16:20:55: Raw payload: [{"value":"","metadata":{"mqtt_topic":"count"}}] 2021-10-02 16:20:55: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:20:56: [MQTT] Device publish {"topic":"alarm","payload":"{\"value\":1}","qos":1,"messageId":6124} 2021-10-02 16:20:56: Raw payload: [{"value":1,"metadata":{"mqtt_topic":"alarm"}}] 2021-10-02 16:20:56: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:20:56: [MQTT] Device publish {"topic":"lag","payload":"{\"value\":1}","qos":0} 2021-10-02 16:20:56: [MQTT] Device publish {"topic":"count","payload":"{\"value\":8300}","qos":0} 2021-10-02 16:20:56: Raw payload: [{"value":1,"metadata":{"mqtt_topic":"lag"}}] 2021-10-02 16:20:56: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:20:56: Raw payload: [{"value":8300,"metadata":{"mqtt_topic":"count"}}] 2021-10-02 16:20:56: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:20:59: [MQTT] Device publish {"topic":"alarm","payload":"{\"value\":\"\"}","qos":1,"messageId":9201} 2021-10-02 16:20:59: Raw payload: [{"value":"","metadata":{"mqtt_topic":"alarm"}}] 2021-10-02 16:20:59: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:20:59: [MQTT] Device publish {"topic":"lag","payload":"{\"value\":\"\"}","qos":0} 2021-10-02 16:20:59: Raw payload: [{"value":"","metadata":{"mqtt_topic":"lag"}}] 2021-10-02 16:20:59: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:21:00: [MQTT] Device publish {"topic":"alarm","payload":"{\"value\":1}","qos":1,"messageId":338} 2021-10-02 16:21:00: Raw payload: [{"value":1,"metadata":{"mqtt_topic":"alarm"}}] 2021-10-02 16:21:00: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:21:00: [MQTT] Device publish {"topic":"lag","payload":"{\"value\":1}","qos":0} 2021-10-02 16:21:00: Raw payload: [{"value":1,"metadata":{"mqtt_topic":"lag"}}] 2021-10-02 16:21:00: Connection refused, invalid payload: Field [variable] is missing 2021-10-02 16:22:36: [MQTT] Device publish {"topic":"count","payload":"{\"value\":8350}","qos":0} 2021-10-02 16:22:36: Raw payload: [{"value":8350,"metadata":{"mqtt_topic":"count"}}] 2021-10-02 16:22:36: Connection refused, invalid payload: Field [variable] is missing ------`