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…
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.
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.
@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:
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…)
@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);
}
}