Endpoint! dht22+nodemcuv3+thinger

Hello everybody, now i’m using dht 22 humidity and temperature sensor, i’ve made some dashboards to monitor microclimate in grow room, but now i want to make an endpoint to get a notification to my email when temperature or humidity will be too high. I’ve tried to use documentation and tutorials of how to use endpoint but nothing seems helped. Sorry for asking this, im just a beginner in arduino :confused:
Can someone can help me with the endpoint code? Im adding my code that im using right now

 #define _DEBUG_
#define _DISABLE_TLS_
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ThingerWifi.h>
#include <DHT.h>

    #define ONE_WIRE_BUS D2 // Data wire is plugged into port 2 on the Arduino
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature.

    #define USERNAME "xxx"
    #define DEVICE_ID "xxx"
    #define DEVICE_CREDENTIAL "xxx"

// Define and initialise the sensor
#define DHTPIN D1
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

    #define SSID "xxx"
    #define SSID_PASSWORD "xxx"

    ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

    void setup() {
       Serial.begin(115200);
    pinMode(BUILTIN_LED, OUTPUT);

    thing.add_wifi(SSID, SSID_PASSWORD);


// Define the 'thing' with a name and data direction
  thing["dht11"] >> [](pson& out){
    // Add the values and the corresponding code
    out["humidity"] = dht.readHumidity();
    out["celsius"] = dht.readTemperature();
  };
  
    sensors.begin();
    }

    void loop(void) {
    thing.handle();

    }

Es muy sencillo, tienes que crear un if para que cuando se cumpla mande la peticion al punto final con ese nombre y mandar el mensaje, eso en el arduino y en la plataforma en el endpoint tienes que crear un mail con el mismo nombre que la peticion .

algo asi:

void loop(){
        thing.handle();
        if (dht.readTemperature() > 25){
                thing.call_endpoint("email_temp");
        }
}

el endpoint tienes que crear un email con el identificador email_temp, igual que el nombre que creamos en el arduino.

Hello @Andrius_Grigas,

Endpoint definition is documented here: http://docs.thinger.io/console/#endpoints-create-endpoint

As @Rafaeldk17 tolds, it is really easy, just using the call_endpoint() instruction. However I will give you some aditional advises:

It is important to include any algorithm to avoid the repetitive call, note that with Rafael’s code, your device will be calling the endpoint whenever the temperature is above that value. We don’t want this, because hundreds of requests will be sent until the Thigner.io server blocks your device. To avoid this, just put an additional control variable.

On the other hand note that you can include the temperature value in the mail by adding a Pson as a parameter and you write the same output identification in the mail between double keys: {{<value_ID>}}

int sent; //control variable to avoid repetitive calls

void loop(){
        thing.handle();

        if (dht.readTemperature() > 25 && sent==0){
                pson data;
                data["temp"]= dht.readTemperature();
                thing.call_endpoint("email_temp", data);
                sent==1;
        }

        if(temperature<25) sent=0;
}

then the mail body would be: The temperature is: {{temp}}