cog in MATLAB Answers
上次活动时间: 2023-8-2

I am attempting to bulk write some JSON data to a ThingSpeak channel using the API. An example payload is: % Payload is data = { 'write_api_key': <my_api_write_key>, 'updates': [ {'field5': 833.205, 'field4': 6, 'field3': 775.648, 'field2': 24.2523, 'delta_t': 1, 'field1': 59.1391}, {'field5': 833.199, 'field4': 6, 'field3': 771.03, 'field2': 24.2844, 'delta_t': 2, 'field1': 59.1331}, {'field5': 833.208, 'field4': 6, 'field3': 750.343, 'field2': 24.3008, 'delta_t': 3, 'field1': 59.1405}, {'field5': 833.208, 'field4': 7, 'field3': None, 'field2': 24.2903, 'delta_t': 5, 'field1': 59.1479}, {'field5': 833.216, 'field4': 7, 'field3': 748.45, 'field2': 24.2965, 'delta_t': 6, 'field1': 59.1686}, {'field5': 833.21, 'field4': 8, 'field3': None, 'field2': 24.2914, 'delta_t': 7, 'field1': 59.1756}, {'field5': 833.204, 'field4': 8, 'field3': 738.847, 'field2': 24.2867, 'delta_t': 8, 'field1': 59.1943}, {'field5': 833.208, 'field4': 8, 'field3': 732.472, 'field2': 24.2814, 'delta_t': 10, 'field1': 59.1964}, {'field5': 833.212, 'field4': 8, 'field3': None, 'field2': 24.2599, 'delta_t': 11, 'field1': 59.1971}, {'field5': 833.207, 'field4': 8, 'field3': 737.475, 'field2': 24.2658, 'delta_t': 12, 'field1': 59.2122}, {'field5': 833.212, 'field4': 8, 'field3': None, 'field2': 24.2498, 'delta_t': 14, 'field1': 59.2161}, {'field5': 833.209, 'field4': 7, 'field3': 749.432, 'field2': 24.2503, 'delta_t': 15, 'field1': 59.2298}, {'field5': 833.208, 'field4': 7, 'field3': 760.224, 'field2': 24.2396, 'delta_t': 16, 'field1': 59.2308} ] } I am sending this payload programatically, in Python, with the requests library using the following command: response = requests.post(url='https://api.thingspeak.com/channels/<my_channel_id>/bulk_update.json', ... data=json.dumps(data)) This results in the response below: % Response { "status": "401", "error": { "error_code":"error_auth_required", "message":"Authorization Required", "details":"Please provide proper authentication details." } } I am certain that the API write key and channel_id are correct. I have used both for single writes successfully. I am using a free ThingSpeak account. I have also tried adding headers to the requests.post() call to indicate explicitly that this is json data. I'm not sure why this is occuring and would sincerely appreciate any pointers.

关于 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.