Device Disabled after using Email Endpoint

I am working on email endpoint earlier on today.

It is meant to send an email when the temperature is higher than 31degree Celcius. I have done a stupid mistake to include the email endpoint calling in the for loop.
Thus I accidentally used the code to send an email at a very fast frequency (the frequency of for loop). So I have received an email whereby my Device is Disabled.

I deleted the line, and proceed to flash a new code again.

However, my Device is still locked! I know I can recreate the so-called device again. But I have set up the dashboard in that account. I dont want to abandon that account. May I know is there any way I can recover my account?

Also, I would like to call the email in 10 minute intervals. Can anyone please help me check if my code is error-free?

 //this is in the very top (global declaration)

unsigned long previousemailmillis = 0;
unsigned long currentmillis; 
const int emailinterval = 600000       // 10 minutes

//this is in for loop

currentmillis=millis();
if (currentmillis-emailpreviousmillis >= emailinterval)
    {
emailpreviousmillis = currentmillis;
if (h>=90 || t>=31)       //h is humidity and t is temperature
       {
       trigger();
       }
    }

//this is out of for loop
    void trigger()
    {
    pson data; 

data ["temperature"] = t;
data ["humidity"] = h;
thing.call_endpoint ("email_with_thinger", data);
}

The best solution is to delete you device and create a new one with the same ID.
Dashboard is independent from your device, you can easily map it to your new device by changing the settings in your widgets.

But if I deleted it, my dashboard data will all be gone, right? :cold_sweat:

Nope, if you save your data on a bucket, the bucket will still be there. You can check your data on the data bucket. After you create a new device, you can use bucket wirte to write to the same bucket if you wish.

Alright, thanks. Then can you check with my code? the 10 mins interval one. I am not sure if they wont spam the email in 10 minute intervals…

The best way to debug is to use Serial.print() to replace the endpoint call, so that you can check if the message is sent to your IDE at an interval you expect.

I just had a check, I found out that Thinger checks on the connectivity of the device every 10 seconds, with the code I wrote, it will send the email every time Thinger writes some bytes… That means my code will still send email at 10 second intervals (I guess it will be labelled as spam)… Is there any other way to optimize my code?

I am sorry if I asked some stupid questions… I am still new to Thinger platform and what it does…

Not really, your device will send message to the server to keep the connection when thing.handle() has been called. To check whether the endpoint function has been called, my only suggestions is to replace it by serial communication and check it offline.

I guess if you, after deleting the device, create a new one with the same ID, the dashboard will take it as the old one, havent tested but that is what logic says me.

As @Hans_Wu says, the best way to check the code is using the serial debug, so I would comment the trigger function call, and replace with a serial message, to see if it works ok, at simple sight it looks good, try it with serial messages to see how it works.

But, I would do it in other way, as your code is written you will check values (hum and temp) every 10 minutes, if the variables reach the threshold at minute 11, it will have to wait 9 minutes to send the notification.
I would use a boolean flag that will set to 1 when the mail is just sent … and will be set to 0 after 10 mins when the mail was sent, why? because in this way the mail will be sent just when the threshold is reached, of course if there had been at least 10 minutes after the last notification.

Hope this helps.