How to add a timestamp to body?

3 次查看(过去 30 天)
Hello,
I have this in ThingHTTP body:
{"src":"013025819299","dst":"+420605555555","text":"ALARM"}
It works fine, but I need to insert timestamp inside it, like this:
{"src":"013025819299","dst":"+420605555555","text":"ALARM at %%timestamp%%"}
Is it possible? How to do it?
  3 个评论
Christopher Stapels
Christopher Stapels 2019-11-12
Just make sure you trigger the request with a react or timecontrol, not an external service.https://www.mathworks.com/help/thingspeak/thinghttp-app.html
%%datetime%% should work.
Zdenek Svezen
Zdenek Svezen 2019-11-12
If I insert %%datetime%% into body, nothing happens. It does not replace this tag with actual dat and time.
Plase help.

请先登录,再进行评论。

回答(5 个)

Christopher Stapels
Christopher Stapels 2019-11-12
编辑:Christopher Stapels 2019-11-12
You need to trigger the request with a TimeControl or React. I just tested it with a TimeControl, I'm sure I've tested with a React but not recently.
This is the result of a ThingHTTP with method POST, the URL https://api.thingspeak.com/update
and Body: api_key=XXXXXXXXXXXXXXXX&field1=%%datetime%% (with the write API key for XX)
I triggered it with a one time timecontrol that I set up just after reading your post.
  3 个评论
Christopher Stapels
Christopher Stapels 2019-11-12
I reccomend you use
{"src":"013025819299","dst":"+420605555555","text":"ALARM at %%datetime%%"}
in your thingHTTP body.
Then make sure you trigger the ThingHTTP using the TimeControl app. Select Apps > TimeControl when you are logged in to your ThingSpeak account.
Normally you might use the ThinkHTTP API key and a rest GET call to trigger a ThingHTTP.
If you have the %%datetime%% replacement key in the body and you trigger the ThingHTTP in your browser or any other way using the URL directly, it will not replace %%datetime%%. If you schedule a TimeControl or React to trigger the ThingHTTP, it will replace the test %%datetime%% with the time it was triggered.
You can also pass the time into the ThingHTTP when you call it using custom replacement keys. Have a look at the example POSTMAN Request Using Replacement Key on the https://www.mathworks.com/help/thingspeak/thinghttp-app.htmlThingHTTP documentation page.
Zdenek Svezen
Zdenek Svezen 2019-11-12
I have insert new TimeControl app.
And inserted %%datetime%% into ThingHTTP body and nothing :(

请先登录,再进行评论。


Christopher Stapels
Christopher Stapels 2019-11-12
Can you take screen shots of the thingHTTP and TimeControl settings? Make sure you blur out the api keys if you want to keep the information private.
What url are you sending to, or how are you finding out if the datetime was sucessfully replaced? Can you show the result?
  1 个评论
Zdenek Svezen
Zdenek Svezen 2019-11-12
ThingSpeak.png
TimeControl.png
But this set is called when time equals what is set in TimeControl and call ThingHttp.
It does not put timecode into it :(

请先登录,再进行评论。


Christopher Stapels
Christopher Stapels 2019-11-13
What time would you want to see in the response? I would have guessed you want to see the time it was called. It might help for you to describe your whole project so we can better help you.
  1 个评论
Zdenek Svezen
Zdenek Svezen 2019-11-13
From my alarm device I call ThingHTTP. This ThingHTTP sends me an SMS.
In this SMS I need time stamp.
I am not able to send the time from my device as a parameter so I need that ThingHTTP will add actual time stamp into its body (there is currently %%datetime%% tag).

请先登录,再进行评论。


Christopher Stapels
Christopher Stapels 2019-11-13
Yes this is the expected behavior. As described above, you need to call the thingHTTP with TimeControl or React to use the datetime replacement key.
You said "From my alarm device I call ThingHTTP.", which would not replace the datetime key.
But you also showed me a TimeControl set to call the thingHTTP. That workflow should work. When you allow the timeControl to call the thingHTTP, ThingSpeak should replace the datetime replacement key correctly. Do you observe that behavior?
What is the alarm device? Does it have a timestamp it could pass? You can use a custom replacement key.
  1 个评论
Zdenek Svezen
Zdenek Svezen 2019-11-13
Alarm device is Arduino and I do not have real time control module there.
Sou you suggest calling TimeControl which calls ThingHTTP? And timestamp will be added, right?
But TimeControl calls itself. :( How to call TimeControl?

请先登录,再进行评论。


Christopher Stapels
Christopher Stapels 2019-11-18
You should also be able to call the THingHTTP with React and the replacement key will work.
So have the device write data (for example write the number 1) to a channel and the react tied to the channel. The react threshold could be if the number were greater than 0.
The react calls your ThinkHTTP, which writes to the external service that you are trying to use. Its a few steps, but allows you to track when everything happened.

社区

更多回答在  ThingSpeak Community

类别

Help CenterFile Exchange 中查找有关 Read Data from Channel 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by