Endpoint mail, can't make it work

Hi helpers, this should be a basic question but I have dealing with it for 3 days (which ChatGPT help) with no success…
See annexed are all the info I have available (for a very basic implementation), hope you can point out what I’m doing wrong…

This is the endpoint

This is the sketch

ESP32 is online

it works fine with IDE testing

this is the result I get when running it
errora

Many thank in advance!

Hi,

Can you please publish the “Inspector” messages of the device? this is located in the device’s page, in order to check the process.

Thanks @ega, here it goes:

{
“device”: “Consumo”,
“event”: “device_state_change”,
“product”: “”,
“state”: “connected”,
“ts”: 1747057064025,
“user”: “OldNerd”
}

looking forward for your help!

I would recommend to add the endpoint routine at the loop, and verify that the device is connected before trying to call the endpoint.

Currently your code is trying to get the endpoint at the setup function, but the device connects to cloud at the “thing.handle();” command, so it will never reach it at the setup function.

Hope this helps.

@ega Thanks again!
I did as you suggested but if fails, this is the inspector results:

{
“device”: “Consumo”,
“event”: “device_state_change”,
“product”: “”,
“state”: “connected”,
“ts”: 1747061639704,
“user”: “OldNerd”
}

and this is the sketch
void setup() {
Serial.begin(115200);
thing.add_wifi(WIFI_SSID, WIFI_PASSWORD);
delay(5000); // Aguarda conexão
}

void loop() {
// Nada a fazer
thing. handle(); // Mantén a conexão viva

float volume = 123.45;

pson data;
data[“volume”] = volume;
bool ok = thing.call_endpoint(“aviso_agua”, data);
if(ok){
Serial.println(“Email enviado com sucesso!”);
} else {
Serial.println(“Falha ao enviar email.”);
}
delay(30000); // Aguarda conexão
}

and this is the monitor response, even though it says

12:02:29.774 → Email enviado com sucesso!

nothing is arriving to my mail (which I’m sure is ok since the testing works fine)

Hi,

All the connection task are executed at the thing.handle(); command, I mean, are not executed at moment when thing.call_endpoint.... command runs, for example.

So what does the calling endpoint command do? It does set a flag to make the communication to the server’s endpoint, and will do it in the next thing.handle(); command executed right after is the flag setted.

Note that to get the confirmation you need to add a third parameter to thing.call_endpoint instruction, last one is the call confirmation and must be set to true to get it, by default it is initialized as false.

On the other hand I recommend to avoid to use the delay command, this stops the process at the uC and for sure may cause issues with thinger stay alive packets.

For testing purposes, I would make a routine that just run once to set the calling endpoint command and let it run indifenitely the thing.handle();, or to make easier just add another thing.handle(); just after the calling enpdoint line.

Hope this helps.

@ega many thanks for spending time with me! I have written to thinner.io asking for support but they say that your answer should be enough and decided to close the ticket!
I guess I have done all your recommendation but still failing miserably…I really don’t know what else to do…this is my code:

Well this forum is an official support channel, so for sure the answer given by this way should be enough for light support intervention.

If you want expedited and/or specific support under your terms, I guess you will need to hire official support.

Anyway I recreated your situation and was able to send mails without issues.

This is how the endpoint is set, just deleted my e-mail

This is the code I used (and how you should share yours, not by a print screen)

//here goes connection detail
bool sendAlert = 1;
//here goes the setup, just not included 
void loop()
{
  thing.handle();

  if (sendAlert)
  {
    pson data;
    float value = 1.234;
    data["subject"] = "Threshold warning";
    data["var"] = "Variable";
    data["value"] = value;

    bool result = thing.call_endpoint("mail", data, true);
    Serial.println(result);
    sendAlert = 0;
  }
}

this is the serial console output, the number 1 is the result
image

And the received mail:
image

By the way at the inspector I was not able to see the endpoint call, I thougth it should be shown there, but it did not show at all.

Hope this helps.

@ega I don’t have words to thanks you for being so patient.
I really fell like a complete moron but I can’t make it work

This is my EndPoint

newendpoint

and this is the code (not print screen)

#include <ThingerESP32.h>

#define WIFI_SSID “–”
#define WIFI_PASSWORD “–”

#define USERNAME “–”
#define DEVICE_ID “–”
#define DEVICE_CREDENTIAL “–”

ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
bool sendAlert = 1;

void setup() {
Serial.begin(115200);
thing.add_wifi(WIFI_SSID, WIFI_PASSWORD);
}

void loop() {
thing.handle();
if (sendAlert)
{
pson data;
float value = 1.234;
data[“subject”] = “Threshold warning”;
data[“var”] = “Variable”;
data[“value”] = value;

bool result = thing.call_endpoint("mail", data, true);
Serial.println(result);
sendAlert = 0;

}
}

this is the monitor:

08:05:38.078 → �������B��� a�Af! #�E (103) phy_comm: gpio[0] number: 2 is reserved

08:05:38.408 →

08:06:13.336 → 0

could I have some problems with the include?

Thanks again

Pretty weird… I do not see why such basic routine does not work.

I use the library thinger.io@ 2.31.0

Are you working with Arduino Ide or VSCode and Platformio?

I saw that the endpoint has an inspector too, did not made the test from my side because it is working, however I would recommend you to keep the endpoint’s inspector open to see if the device call reaches it.

@ega could you please send me your complete program, with setup and definitions (without the data of course) for me to check if I have everything OK?

Also I could share with you (by private message) my USERNAME, DEVICE_ID, DEVICE_CREDENTIAL for you to test in your environment (I know, it is to much to ask…)

I’m using Arduino Ide Version: 2.3.6

@ega the good news:
I found there was a problem in my Endpoint and the code:
Endpoint: {{valeu}}
Code: data[“value”] = value;

I changed the order of “eu” and “ue”

The bad news, I fix it and still not working!

I used the basic example

#define THINGER_SERIAL_DEBUG

#include <ThingerESP32.h>
#include "arduino_secrets.h"

ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

bool sendAlert = 1;

void setup() {
  // open serial for debugging
  Serial.begin(115200);

  pinMode(16, OUTPUT);

  thing.add_wifi(SSID, SSID_PASSWORD);

  // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
  thing["GPIO_16"] << digitalPin(16);

  // resource output example (i.e. reading a sensor value)
  thing["millis"] >> outputValue(millis());

  // more details at http://docs.thinger.io/arduino/
}

void loop()
{
  thing.handle();

  if (sendAlert)
  {
    pson data;
    float value = 1.234;
    data["subject"] = "Threshold warning";
    data["var"] = "Variable";
    data["value"] = value;

    bool result = thing.call_endpoint("mail", data, true);
    Serial.println(result);
    sendAlert = 0;
  }
}

Do you have another routine in your code?

The endpoint inspector does show something?

Btw note how the code is properly shared, you should give the appropriate format, not paste the text, for complex code this helps the readability.

@ega, I have not any other routine, this is my code (finally I guess in the proper format…)

#define THINGER_SERIAL_DEBUG

#include <ThingerESP32.h>
#include "arduino_secrets.h"

ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

bool sendAlert = 1;

void setup() {
  // open serial for debugging
  Serial.begin(115200);

  pinMode(16, OUTPUT);

  thing.add_wifi(SSID, SSID_PASSWORD);

  // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
  thing["GPIO_16"] << digitalPin(16);

  // resource output example (i.e. reading a sensor value)
  thing["millis"] >> outputValue(millis());

  // more details at http://docs.thinger.io/arduino/
}

void loop()
{
  thing.handle();

  if (sendAlert)
  {
    pson data;
    float value = 1.234;
    data["subject"] = "Threshold warning";
    data["var"] = "Variable";
    data["value"] = value;

    bool result = thing.call_endpoint("mail", data, true);
    Serial.println(result);
    sendAlert = 0;
  }
}

this is what I get in the serial monitor

11:22:22.769 -> �������������zzY�g��cDK �[NETWORK] Starting connection...
11:22:23.065 -> [NETWORK] Connecting to network Trebbiano600
11:22:23.165 -> E (105) phy_comm: gpio[0] number: 2 is reserved
11:22:23.165 -> 
11:22:53.061 -> [NETWORK] Cannot connect!
11:22:58.069 -> [THINGER] Writing bytes: 70 [FAIL]
11:22:58.069 -> [THINGER] Expected: 70
11:22:58.069 -> [THINGER] Wrote: 0
11:22:58.069 -> 0
11:22:58.069 -> [NETWORK] Starting connection...
11:22:58.069 -> [NETWORK] Connecting to network Trebbiano600
11:22:59.650 -> [NETWORK] Connected to WiFi!
11:22:59.683 -> [NETWORK] Getting IP Address...
11:22:59.683 -> [NETWORK] Got IP Address: 172.16.10.27
11:22:59.683 -> [NETWORK] Connected!
11:22:59.683 -> [_SOCKET] Connecting to iot.thinger.io:25202...
11:22:59.683 -> [_SOCKET] Using secure TLS/SSL connection: yes
11:23:04.664 -> [_SOCKET] Connected!
11:23:04.664 -> [THINGER] Authenticating. User: OldNerd Device: Consumo
11:23:04.664 -> [THINGER] Writing bytes: 43 [OK]
11:23:05.453 -> [THINGER] Authenticated
11:23:23.021 -> [THINGER] Writing bytes: 2 [OK]
11:23:23.187 -> [THINGER] Available bytes: 2
11:24:23.032 -> [THINGER] Writing bytes: 2 [OK]
11:24:23.231 -> [THINGER] Available bytes: 2
11:25:23.009 -> [THINGER] Writing bytes: 2 [OK]
11:25:23.174 -> [THINGER] Available bytes: 2
11:26:23.026 -> [THINGER] Writing bytes: 2 [OK]
11:26:23.155 -> [THINGER] Available bytes: 2

The endpoint inspector does not show anything!

The issue is that your device cannot get the connection at first try, tries to get endpoint, does not reach it and never tries again.

What would I recommend? add a routine to check that the device is successfully logged at the platform and then execute the sendAlert routine.

Hope this helps.

@ega, i finally got it working, with the code below it sends the mail (and i receive it!) every 1 minute.
Many, many thanks for your support,
Regards from Brazil…

#include <ThingerESP32.h>
#include "arduino_secrets.h"

ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

// interval
unsigned long ultimaChamada = 0; //initial time
unsigned long intervalo = 60000; // 1 minute


void setup() {
  // open serial for debugging
  Serial.begin(115200);
  thing.add_wifi(SSID, SSID_PASSWORD);
}

void loop()
{
  thing.handle();
  
if (millis() - ultimaChamada > intervalo) {
  ultimaChamada = millis();
  pson data;
    float value = 1.234;
    data["subject"] = "Threshold warning";
    data["var"] = "Variable";
    data["value"] = value;

    bool result = thing.call_endpoint("mail", data, true);
    Serial.println(result);
  }
}