Utilizing Email End Point

Email End Point - How to Send device data as JSON?

I understand thinger.io is fairly new, but I am having some difficulty finding any information on how to utilize this feature for simple email alerts on high temp to include the temperature that triggered the call.

I was able to get a reading from the DHT22 sensor.

  thing["Status"] >>[](pson& out){
out["Humidity"]=dht.readHumidity();
  };
unsigned long lastCheck = 0;

void loop() {
  delay(1000);
  thing.handle();
  unsigned long currentTS = millis();
  if(currentTS-lastCheck>=60000){
    lastCheck=currentTS;
    if(dht.readHumidity()>55){
      digitalWrite(6,HIGH);
       thing.call_endpoint("high_humidity_alert",thing["Status"]);
    }
  };

Can this reading be utilized in the Custom Body of the email endpoint?

Hi, this a recent feature and it is not currently documented.

To add a value in your email body, or a HTTP endpoint, you can set the key value inside double brackets, like {{Humidity}} in your case. You can add multiple values if you want. You can also set values without a key ({{}}) if your resource or data does not define an output key.

Hope it helps! :slight_smile:

1 Like

Hi @alvarolb I can’t get this working, I don’t know why, I have declarated in sketch’s setup this

  thing["Level"] >> outputValue(actualRelative);

And calling the endpoint, by this:

  thing.call_endpoint("endpoint_id");

At enpoint configuration this:

The actual level is {{Level}}% 
The actual level is {{actualRelative}}% 

I putted both definitions in order to discard which is the one that works, but when I receive the email, I got this

The actual level is {{Level}}%
The actual level is {{actualRelative}}%

I’m working with cloud server.

Thanks in advance.

Hi @ega, take a look to the documentation for sending data to endpoints. You need to include this information when calling the endpoint, so the back-end can use the information provided. Let me know if the following documentation solve your problem:

http://docs.thinger.io/arduino/#coding-using-endpoints-sending-data-to-endpoints

Yes!! many thanks for helping me even with this obvious doubts

I’ve invoqued the endpoint by this code

thing.call_endpoint("endpoint_id",thing["Level"]);

And I’ve received the data in mail using the following code:

The actual level is {{}}% 

@alvarolb Can I help you to improve the documentation? because I think this is really easy (after get it done of course), but before that I didn’t saw it really clear how can I get this done.

I would like to add an example of how to use email endpoint, with the sketch code, and email code, I think that is more easy for a beginner to understand this seeing a complete example.

Hi @ega! nice it worked! :slight_smile:

Any contribution you do to the documentation is really welcome! If you know how Github works, you can share it directly, or I can upload your docs and pictures if you want. Let me know!

I tried to do it directly, I guess you should approve the modifications before they become public :wink:

Hi @ega! I did not see the pull request. You probably submit the commit/push to your own fork. is it?

Yes, I think that I made the pull request, let me know if you still don’t see it

Hey @alvarolb, you did not tell me if you could see the github pull request dude!

Hi Team, not sure what am I doing wrong but it is it isn’t working for me. I do receive the email but there is no way to get the variable value on the body of the received mail.

this is my Yun scketch

//#define _DEBUG_
#define _DISABLE_TLS_

#include <BridgeSSLClient.h>
#include <ThingerYun.h>

#define USERNAME "OldNerd"
#define DEVICE_ID "Yun"
#define DEVICE_CREDENTIAL "xxxxxxxx"

ThingerYun thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
int ValLitros;

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

  // initialize bridge
  Bridge.begin();

  thing["led"] << digitalPin(LED_BUILTIN);
  thing["litros"] >> outputValue(ValLitros);
}

void loop() 
{
       ValLitros = random (300);
       if (ValLitros > 250)
       {
       //thing.call_endpoint("EP1");
       thing.call_endpoint("EP1",thing["litros"]);
       }

  thing.handle();
  delay (10000);
}

i did tried the following options for the call

1 - thing.call_endpoint("EP1",thing["litros"]);
2 - thing.call_endpoint("EP1",thing["ValLitros"]);

with no joy…

on the EndPoint I have tried the following options

1 - Consumo llegĂł a un nĂ­vel critico de {{ValLitros}} Litros
2 - "Consumo llegĂł a un nĂ­vel critico de {{ValLitros}} Litros"
3 - Consumo llegĂł a un nĂ­vel critico de {{litros}} Litros
4 - "Consumo llegĂł a un nĂ­vel critico de {{litros}} Litros"
5 - Consumo llegĂł a un nĂ­vel critico de {{}} Litros
6 - "Consumo llegĂł a un nĂ­vel critico de {{}} Litros"

none of them worked. Please let me know what am I doing wrong.

Gracias!!!

I have not used the email end recently, I do not have it implemented now, but according to my publication, it should work with option 1 on the call and option 5 on the endpoint.

I recommend that you avoid the use delay function, this causes the abnormal behavior in the thinger platform, use another method to control the loop or functions frequency.

@ega many thanks for your reply. I followed your suggestions (including deleting the delay function) but unfortunately there was no progress. Mail is received but the data value (litros) arrives empty.

Any other suggestion? Do you know if there is a way to contact Thinger directly (i guess Alvaro is the owner/developer)

Cheers!

Hi @OldNerd,
how are you defining your email endpoint? Please, share the body configuration.

Best.

Hi, this is how my Email body looks like:

{{}}

and this is what I get (empty body)

Consumo en nĂ­vel critico
Inbox
x

no-reply@thinger.io via amazonses.com
3:30 PM (2 hours ago)
to me

Hi

I tried again the endpoint call with a “thing” with just one resource and email body as {{}} but it didnt work,

I tried with a “thing” with more than one resource, defined as the next

thing["Distance"] >> [](pson& out)
{
  out["Feet"] = actualFeet;
  out["Inches"] = actualInch;
 };

The call is made by (asure that the call is made just one time by any way):

if(mail)
{
  thing.call_endpoint("endpoint_id",thing["Distance"]);
  mail=0;
}

The mail body:

  The actual distance is {{Feet}} feet and {{Inches}} inches.

And receive mail:

“The actual distance is 14 feet and 1 inches.”

Hope this helps,

Regards

HI @ega, so it seems it is a bug, doesn’t it?

Thinger gurus any remarks?

Best!

Surely it is, maybe it was lost unintentionally in some platform update.

Is your issue solved? can you send emails with values in the device?

If you need just one resource you can define the “thing” as I shown you with just one resource, its not needed to have more than one using that definition method.

@ega I solved the issue using the hints given by @JorgeTrincado in the post below which is basically the same approach you suggested. Many thanks

https://community.thinger.io/t/smart-freezer-with-thinger-io-climastick/538/3

It should be fixed now! Now you can use {{}} for sending values without keys. It is now even possible to add variables to the email subject :wink:

Best.