Change Time Format in ThingSpeak Alert?

Chris on 1 Jun 2021
Latest activity Reply by Chris on 2 Jun 2021

The timestamp for the ThingSpeak Alerts I create look like this: "Time: 2021-06-01 06-21-45.001 -04:00" Using a dash (-) instead of a colon (:) between the hour and minutes and minutes and seconds seems very non-standard to me. I've always seen it with a colon.

Is there any way to change the dashes in the time part of the stamp to colons so the above looks like 06:21:45.001? (I presume this is set in "HeaderFields" but don't know how to change it.

Thanks.

Christopher Stapels
Christopher Stapels on 1 Jun 2021

Can you show how you are generating that timestamp with an alert? I think the standard ThingSpeak format is ISO 8601. The created_at timestamps generally adhere to this, and seen in this snippet from the write data page .

(Optional) Date when feed entry was created, in ISO 8601 format, for example: 2014-12-31 23:59:59. The date you specify must be unique within the channel. Time zones can be specified using the timezone parameter.

Chris
Chris on 1 Jun 2021

This comes out of a MATLAB Analyis:

alert_url= "https://api.thingspeak.com/alerts/send";

jsonmessage = sprintf(['{"subject": "%s", "body": "%s"}'], alert_subject,alert_body);

options = weboptions("HeaderFields", {'Thingspeak-Alerts-API-Key', alert_api_key; 'Content-Type','application/json'});

result = webwrite(alert_url, jsonmessage, options);

See this link: https://www.mathworks.com/help/thingspeak/analyze-channel-data-to-send-email.html on which it is based. The time has the same format in that example.

Christopher Stapels
Christopher Stapels on 1 Jun 2021 (Edited on 1 Jun 2021)

Thanks for pointing that out to me. You cannot change the format of the timestamp part of the response, but you can add a timestamp to the body message. For example, on the line that says alertBody = ' No water needed. '; you can add a timestamp. 'No water needed at 2021-06-01 12:43:24 You can use datetime with a format specifier to put the timestamp however you like it. Then add it to the alert body using sprintf .

Chris
Chris on 2 Jun 2021

OK, but is there a way to eliminate the default timestamp if I create my own? If so, please describe. Or do I end up with two timestamps--one formatted normally, and one with the odd default format? If so, I would hope you will consider changing the default.

Christopher Stapels
Christopher Stapels on 2 Jun 2021

I will log your request. Can you describe why you need the timestamp? Are you parsing the response with some other code?

Chris
Chris on 2 Jun 2021

Thanks. I am not parsing the response. I am using the alert to tell me about the time of a fault in a monitored system. I would rather use the time in the alert than the time of receipt of the email for that purpose.

Christopher Stapels
Christopher Stapels on 2 Jun 2021

Why does the format matter if you are not parsing the response?

Chris
Chris on 2 Jun 2021

bEcAuse I AM rEAding the RespoNSE and wouLD LIKe it in A norMAL formAT, oK?

Chris
1
Post
4
Replies