MATLAB Answers

thingspeak - Any way to disable "Transfer-Encoding: chunked"?

68 views (last 30 days)
Zachariah Belding
Zachariah Belding on 11 Jan 2021 at 16:05
Edited: Christopher Stapels on 12 Jan 2021 at 13:35
When updating a channel with an execute Talkback(https://www.mathworks.com/help/thingspeak/writedataandexecutetalkbackcommand.html), the thingspeak server uses a chunked style body. With weak and intermittent cellular connections, this can cause difficulties. Is there any way to disable this behavior? I believe updating a channel without Talkback does not use chunked encoding.

  0 Comments

Sign in to comment.

Accepted Answer

Christopher Stapels
Christopher Stapels on 12 Jan 2021 at 0:25
Edited: Christopher Stapels on 12 Jan 2021 at 13:35
Are you sending a very large command to your device? The talkback response should be quite small. We cannot change the encoding on the response that is sent from a TalkBack, but you can use a ThingSpeak channel as a proxy for TalkBack. Write the command to a channel and have the device read the channel at regular intervals or use MQTT to subscribe to the channel. The subscription will provide the channel contents when they are updated.

  3 Comments

Zachariah Belding
Zachariah Belding on 12 Jan 2021 at 2:33
Thank you for your help. Yes, the talkback is quite small. Just a short command. Here is an example of the response from the server when everything works fine:
HTTP/1.1 200 OK
Date: Sat, 09 Jan 2021 02:45:11 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 200 OK
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
Access-Control-Allow-Headers: origin, content-type, X-Requested-With
Access-Control-Max-Age: 1800
ETag: W/"51f2a616a1d535be278670432ed2af33"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: f4358076-c083-4650-93a4-2fb48a7e1e0b
X-Runtime: 0.081324
X-Powered-By: Phusion Passenger 4.0.57
Server: nginx/1.9.3 + Phusion Passenger 4.0.57
86
{"executed_at":"2021-01-09T02:45:11Z","position":null,"id":21346313,"command_string":"146wateron","created_at":"2021-01-09T02:44:35Z"}
0
When I run into trouble is when the reponse is broken up into multiple chuncks. I don't have an example handy, but I can get one. Any reason why a response body of around this size(86 bytes) would be broken up into multiple chunks?
Have talkback commands fallen out of popularity?
Vinod
Vinod on 12 Jan 2021 at 5:18
Try adding "&headers=false" to your request. That should shorten it up and cause the response to be less likely to be chunked.
Also, are you sending a HTTP/1.1 or HTTP/1.0 request? Try sending a HTTP/1.0 if your device cannot handle a HTTP/1.1 request.
Zachariah Belding
Zachariah Belding on 12 Jan 2021 at 11:55
"Try adding "&headers=false" to your request. That should shorten it up and cause the response to be less likely to be chunked."
Thank you! This will shorten the response quite a bit and reduce data usage!
HTTP/1.1 200 OK
Date: Tue, 12 Jan 2021 11:35:37 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 200 OK
ETag: W/"050a4384880d48b11dc203846aea209c"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 79cb41b5-e471-4a0e-9201-f0f45b21581b
X-Runtime: 0.074885
X-Powered-By: Phusion Passenger 4.0.57
Server: nginx/1.9.3 + Phusion Passenger 4.0.57
86
{"executed_at":"2021-01-12T11:35:37Z","position":null,"id":21390658,"command_string":"146wateron","created_at":"2021-01-12T11:33:06Z"}
0
After looking at my issue more, I have determined that I was wrong about the chunked encoding. I am working with raw tcp sockets and I was not giving the response enough time to be fully buffered in the cellular modem I am using. Adding a 250ms delay after the modem first tells me data is available seems to have fixed the issue.

Sign in to comment.

More Answers (0)

Products

Communities

More Answers in the  ThingSpeak Community

Community Treasure Hunt

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

Start Hunting!