Donald Duck in Discussions
Ultima attività il 16 Apr 2022

I've had a Thingspeak channel since 2017. It's updated by a RPi running Raspbian Lite (the Raspberry Pi version of Debian Linux). The "Lite" means there's not much GUI stuff in there, and the RPi is run "headless" using SSH. To update my channel I use the linux utility curl to send http GET commands. curl is run at intervals from a bash script which loops indefinitely. This has worked fine for nearly 5 years until suddenly between 14:00 and 14:20 UTC on 13/4/22 (UK format) it stopped working, and I started getting HTTP error 400 responses. I haven't changed anything; I haven't updated the RPi OS for over a year, and the timestamp the bash script file is 2020. Status is enabled on the channel, and a little trial and error showed that the problem was caused by including a status update string which contained a space character. So the workaround is simple, just amend the status string to not have a space character, and all is well again. I can still send status updates with a string including a space character directly from a web browser, so what has happened to break curl after all this time? Channel status update strings including space chars I think it may be related to some updates on our end which tightened the rules around query parameters. For example, the browser automatically does some things like convert spaces to %20 - the ASCII value for space. In curl that is not automatic. So, you may have to update your curl string to include double quotes around the query parameters or manually convert the spaces to %20. Do either of those solutions resolve the issue for your device? Vinod, Thanks for your reply. No, your suggested fixes don't work. I had already tried single and double quoting the string when I was messing about earlier. I've just tried %20 and that doesn't work either. Maybe I should go back and read the curl documentation again, but not knowing what your end will accept now means that may not help resolve things much. A slightly more helpful error message rather than just a 400 failure and the the message "invalid constant string" would be good too. Maybe if you share your exact curl request with a placeholder for the api_key, I can suggest what the change needs to be. Vinod, I've just retried replacing spaces with %20 in the status string, and it's working now. So probably I had finger trouble before when I tried it, or possibly you've changed something else your end. Whatever, it's an easy fix for me to change the software that generates the string. Thanks for your help. I would suggest your documentation could do with an update or note. In Write Data the value type for the status parameter is defined as string. I can't find anywhere string is further defined, but in most contexts space characters are valid components of strings. Glad to hear you got it working. I appreciate the suggestion to improve the documentation to say status updates need to be URL encoded strings. Thanks! http 400 space characters

Informazioni su ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.