Contenido principal

Resultados de

Hello, I need help with a simple example. I am trying to do a simple bulk update using JSON in Javascript, using this parm, header and body:
$.post("https://api.thingspeak.com/channels/xxxxxxxxx/bulk_update.json" ,{
"Content-Type": "application/json",
"write_api_key" : "xxxxxxxxxxxxxxxx",
"updates": [
{
"created_at": "2022-12-30 10:26:2 -0800",
"field1": 100,
"field2": 100,
"field3": 200,
"field5": 600
},
{
"created_at": "2022-01-12 10:27:2 -0800",
"field2": 100,
"field3": 200,
"field5": 600
}],
function(data){
console.log(data) // log anything returned to the console
}
});
When I run the above (Mac OS, Chrome, Javascript) I receive this error message:
Access to XMLHttpRequest at 'https://api.thingspeak.com/channels/1283582/bulk_update.json' from origin 'https://backpaqlabs.com'
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
api.thingspeak.com/channels/1283582/bulk_update.json:1
Failed to load resource: net::ERR_FAILED
Is there something wrong with the syntax or JSON payload that can cause this CORS error? I have tried both local command line and from my hosted server. I am starting to see CORS errors with Javascript getJSON calls as well, so wondering if there is something going on at the endpoint. In this example, I have literally taken it from the example in the doc, so I assume it should comply with the API endpoint. Does seem to work OK with same code on Postman and CURL, so I believe syntax is correct. Ideas?
Any help appreciated!
Niall
Niall
Última actividad el 14 de Abr. de 2021

Hi - I'm currently using the code from this article: https://uk.mathworks.com/help/thingspeak/continuously-collect-data-and-bulk-update-a-thingspeak-channel-using-an-arduino-mkr1000-board-or-an-esp8266-board.html

My plan was to use this so as to update my Thingspeak server every second with data recorded on my arduino of higher than 1Hz. I am currently taking vibration sensor data that for my project requires a higher sample rate than Thingspeak is able to handle naturally - thus I found bulk updates to be the solution.

I have gotten this to work as specified in the article - updates every 2 minutes with data points at every 15 seconds. I have gotten this as far as data points every second with an update to the server every 10 second - however the system fails at any data point shorter than a second. I believe this to be a problem with using delta_t but I am not sure.

To clarify I do not have a computer science background, this is currently a project I'm working on in Mechanical engineering and I've truly hit a wall with this problem. Any help would be appreciated!

My system is an Arduino MEGA 2560 with an ethernet shield - in the sample code they use RSSI to output sample data, I simply changed this to a random number between 0-50.