How to include field value in ThingHTTP URL GET Request

조회 수: 5 (최근 30일)
Warren Stanley
Warren Stanley 2024년 7월 17일
댓글: Warren Stanley 2024년 7월 19일
I am trying to include a field value in a ThingHTTP GET request but have not been successful.
For example, I have have successfully used
to send a specifice value to an external site, but was unsuccessful when I tried to send a ThingSpeak channel field value in a similar way. I used the %% method, which works for ThingTweet, but that didn't seem to work here. e.g.
Am I doing something wrong, or is there an alternative method for doing this?

답변 (1개)

Sachin Lodhi
Sachin Lodhi 2024년 7월 18일
Hi Warren,
It looks like you are on the right track, but there are some things that need to be considered when using ThingHTTP for GET requests with dynamic data from ThingSpeak channels. The %% notation is indeed used for placeholders, but the setup must be done correctly in ThingHTTP.
Here is a step-by-step guide to help you set this up:
  1. Click Apps > ThingHTTP, and then click New ThingHTTP.
  2. The next step is to configure the ThingHTTP. See the following section to properly configure ThingHTTP. https://www.mathworks.com/help/thingspeak/thinghttp-app.html#bvtzy2y-1:~:text=New%20ThingHTTP.-,Specify%20settings,-.%20Not%20all%20settings
  3. Finally, test the ThingHTTP url. Once saved, You can use POSTMAN to try out your HTTP requests using the RESTful API for ThingSpeak.
If the above steps are correctly followed, the placeholder `%%channel_1234567_field_1%%` should be replaced with the actual value from the specified ThingSpeak channel and field.
Please note that if this does not resolve your query, then following these troubleshooting steps can help -
  1. Check Channel ID and Field Number: Ensure that the channel ID and field number are correct.
  2. Public or Private Channels: Replacement requests to private channels not owned by the same user as the ThingHTTP request return blank values.
  3. URL Encoding: Make sure the URL is properly encoded if it contains special characters.
If you follow these steps and ensure all configurations are correct, you should be able to successfully include a ThingSpeak channel field value in your ThingHTTP GET request.
I hope this helps!
  댓글 수: 2
Warren Stanley
Warren Stanley 2024년 7월 18일
Hi Sachin,
Thank you for your very detailed answer. I wonder if my issue is something to do with your troubleshooting step 2, as it seems my attempt to pass a value via ThingHTTP GET request works if I just try to pass a fixed number
but not if I try to use a place holder
which just passes a blank. I've tried other place holders like %%datetime%% and %%day%%, but get the same problem, so I don't think it's because of a mistake in my channel/field information..
Anyway, the requests I've been trying to send are to a MacroDroid webhook, where I can't really see what gets through. I will try sending the request to a different site of my own, where I can hopefully get a look at the full text of the request at the receiving end, and see what comes through.
Many thanks again.
Warren.
Warren Stanley
Warren Stanley 2024년 7월 19일
Hi again,
I've observed the full text of the URL that comes through on a server I set up. It seems the place holders don't get changed to the required value and the url text just comes through with the %%channel_1234567_field_1%% text exactly as I typed it originally. I double checked the channel and field information, and that seems ok, so not sure what else to try. Maybe the place holder code doesn't work when included in the URL itself, perhaps only when put in a message body or something?
Thanks again,
Warren.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Visualize Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by