Field 2 not updating
Dernière activité Réponse par Christopher Stapels
le 20 Déc 2023
Hello, I have followed the tutorial from https://www.halvorsen.blog/documents/technology/iot/arduino/resources/Arduino%20UNO%20R4%20WiFi%20and%20ThingSpeak.pdf to use an arduino Uno R4 wifi board to write sensor data to thingspeak, and the field 1 of random data is updating properly, but when I try to send data from analog pin A0 it will not update to field 2. I've been speaking with ChatGPT to try to resolve this issue, and it has offered several solutions that have simplified the code dramatically but the same problem persists. I wonder if this could be an error with the channel settings in my thingspeak channel? I cannot find any errors myself. ChatGPT suggested looking for the http responses to trouble shoot and both fields return -210, which it says means the API key is missing, but I have stored this key in the seperate arduino_secrets.h tab in the code, so both fields must be using the same API key, and since field 1 is working properly I don't think this is the issue. This is why I suspect there might be a deeper issue with my channel. I set it up about a year ago with a different experimental project, so maybe it has been corrupted over time. Any help is much appreciated! My current loop code reads as follows:
void loop() {
// Update field 1
float temperature = random(2000, 3000) / 100.0;
Serial.println(temperature);
ThingSpeak.setField(1, temperature);
ThingSpeak.writeFields(SECRET_CH_ID, SECRET_WRITE_APIKEY);
int response = ThingSpeak.writeFields(SECRET_CH_ID, SECRET_WRITE_APIKEY);
Serial.print("ThingSpeak write response code: ");
Serial.println(response);
delay(1000); // Add a delay to separate updates
// Update field 2
float button = analogRead(A0);
int buttonInt = static_cast<int>(button);
Serial.println(buttonInt);
ThingSpeak.setField(2, buttonInt);
ThingSpeak.writeFields(SECRET_CH_ID, SECRET_WRITE_APIKEY);
int response2 = ThingSpeak.writeFields(SECRET_CH_ID, SECRET_WRITE_APIKEY);
Serial.print("ThingSpeak write response code: ");
Serial.println(response2);
delay(19000); // Adjust the delay to maintain the total delay period
}
3 commentaires
Date décroissanteYou are allowing no time between subsequent writes to the two fields (in the same channel), when 15 seconds are required if you have a free account. See this post for the full explanation and solution.
Connectez-vous pour participer