Issues sending dashboard keypad widget data to ESP32 via MQTT Relay

Hi everyone, Happy New Year to all!

I’m currently working on a solution for my client and exploring the functionality of TagoIO using a free plan account.

My current setup:

  • I have an ESP32 connected to my own Mosquitto broker (anonymous, local IP).
  • TagoIO is connected to the broker through MQTT Relay.
  • The uplink (ESP32 → Broker → Relay → TagoIO) works perfectly — I can see data from my ESP32 in TagoIO.

What I want to do:

  • Send data from the Dashboard Keypad widget back to my ESP32 using the Relay.
  • Only specific variable(s) (keypad only for now) needs to be sent.

What I tried:
I’ve seen a forum post suggesting using Analysis with Network.publishToRelay(). I created the following code:

import { Analysis, Network } from "jsr:@tago-io/sdk";

const network = new Network({
  token: "7b96139XXXXXXXXXXXXXX",
});

async function run(context, scope) {
  const keypadValue = scope?.find(v => v.variable === "keypad")?.value;
  if (!keypadValue) {
    context.log("No 'keypad' variable in scope.");
    return;
  }

  await network.publishToRelay({
    device: "3aee9eaXXXXXXXXXXXXXXXXXX",
    topic: "/device/esp32-02",
    message: JSON.stringify({ keypad: keypadValue }),
    options: { qos: 0 },
  });

  context.log("Keypad value sent via Relay:", keypadValue);
}

Analysis.use(run);

The issue I’m facing:

  1. I’m not sure how to trigger the Analysis automatically when someone presses a keypad button on the dashboard.

  2. I get this error when I run with analysis scope:

    error: Uncaught (in promise) “Invalid middleware_endpoint”

    [TagoIO Analysis] Error executing Deno analysis: 1

I prefer a solution that uses the MQTT communication method.
Thanks in advance for any guidance!

Hi Sam,

In regards to your questions,

  1. You can simply select the Analysis you wish to run once you’ve inputed the values to the keypad widget. You can select the Analysis to run inside the “Options” section.

  1. You need to add your middleware endpoint inside the MQTT network you’ve created:

1 Like

Hi Freddy,

Thank you! It works perfectly now, really appreciate your help! I’ll keep exploring TagoIO and see what else I can do.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.