Double checking a bulk upload csv url

Hello, I am currently trying to get some data uploaded to ThingSpeak via an ESP32 with an SD card attached, using the bulk update csv API.
I have tried to get it correct to the example on this page https://uk.mathworks.com/help/thingspeak/bulkwritecsvdata.html
My url currently looks like this:
http://api.thingspeak.com/channels/2288289/bulk_update.csv?write_api_key=7DN763HM8PFKF4R0&time_format=absolute&updates=2000-00-00T00%3A0%3A0+0000%2C0%2C0%2C0%2C001
%2C%2C%2C%2C%2C0.000000%2C0.000000%2C%2C
(In this example all the values are zero because I am currently just testing but even with fake data it is not working)
The error is due to bad syntax
Please can someone help? Thanks in advance

댓글 수: 5

Are you using a GET request? Bulk update need a POST.
Saul
Saul 2023년 10월 13일
편집: Christopher Stapels 2023년 10월 13일
Full code here:
void uploadToThingSpeak() {
display.fillScreen(BLACK);
display.setCursor(0, 0);
display.setTextColor(CYAN);
display.print("Uploading data...");
while (dataFile.available()) {
char line[100];
readLine(dataFile).toCharArray(line, 100);
Serial.println(line);
Serial.println();
char* arrline[12];
// printcsvFields(line);
getcsvFields(line, arrline);
// for (int j=0; j<7; j++) {
// Serial.println(arrline[j]);
// }
// Serial.println();
// std::string test = std::string("twenty") + arrline[1];
// Serial.println(test.c_str());
// Serial.println();
//Create an HTTP client
HTTPClient http;
char key[] = {"/bulk_update.csv?write_api_key="};
char time[] = {"&time_format=absolute&updates="};
char comma[] = {"%2C"};
//Create the ThingSpeak URL
std::string url = std::string("http://api.thingspeak.com/channels/") + SECRET_CH_ID + key + SECRET_WRITE_APIKEY + time + arrline[0] + comma + arrline[1] + comma + arrline[2] + comma + arrline[3] + comma + arrline[6] + comma + comma + comma + comma + comma + arrline[4] + comma + arrline[5] + comma + comma;
Serial.println(url.c_str());
Serial.println();
// Send the POST request
http.begin(url.c_str());
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) {
Serial.println("Uploaded successfully");
Serial.println();
} else {
Serial.println("Failed to upload");
Serial.println();
}
http.end();
// // can write any/all fields from lineord here, fields 8, 9 for this demo
// ThingSpeak.setField(1, arrline[0]);
// ThingSpeak.setField(2, arrline[1]);
// ThingSpeak.setField(3, arrline[2]);
// ThingSpeak.setField(4, arrline[3]);
// ThingSpeak.setField(5, arrline[4]);
// ThingSpeak.setField(6, arrline[5]);
// ThingSpeak.setField(7, arrline[6]);
// ThingSpeak.setField(8, arrline[7]);
// // write to the ThingSpeak channel
// int x = ThingSpeak.writeFields(SECRET_CH_ID, SECRET_WRITE_APIKEY);
// if(x == 200) {
// Serial.println("Channel update successful.");
// Serial.println();
// //short delay - test the limits allowed for this and number of lineords looped
// // tests Feb 2022, 12s fails after first write, 15s works OK
// delay(15000);
// }
// else {
// Serial.println("Problem updating channel. HTTP error code " + String(x));
// Serial.println();
// return;
// }
}
display.setCursor(0, 3);
display.print("Upload Complete!");
delay(3000);
}
Saul
Saul 2023년 10월 13일
I am only using four data fields because the timestamp is separate in this case, same as the latitude/longitude (please correct me if I'm wrong).
I am not sure how to then access the timestamp and lat/lon for analysis - if someone could point me in the right direction for that as well it would be great.
Have a look at this example to see a better way to generate a POST and do bulk updates on an ESP32.
I'm not sure what you mean about "using four data fields because the timestamp is separate in this case"
You can definitely post to all eight fields in a bulk update, have a look at the examples on the documentation page.
The ThingSpeak library parts in your code really threw me until I noticed they were all commented out. I suggest you clean up the code you post in a question to get best results if you get a chance. (remove sections you arent using)
Regarding the lat/lon question are you trying to understand how to read the lat lon data back from ThingSpeak? If so see the Read Data api, and condired the parameter 'location=true'
Saul
Saul 2023년 10월 13일
Thank you Christopher! I will look at this when I get a chance next week. Have a lovely weekend

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

답변 (0개)

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

도움말 센터File Exchange에서 Visualize Data에 대해 자세히 알아보기

태그

질문:

2023년 10월 13일

댓글:

2023년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by