First implementation of ThingSpeak, not every write is registered, pls look at my code
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stigh Aarstein
el 10 de Oct. de 2020
Comentada: Stigh Aarstein
el 12 de Oct. de 2020
Hi,
This is my first post here :)
I've implemented ThingSpeak in my code and see that some of my channel fields are not updated frequently. My code runs where one field updates based on motion (counting and uploading the count per count) and the others update per 30 seconds. As some are not updated as they should, I would like to know if I'm using the implementation correctly. Could anybody please look over and verify my usage?
void loop() {
/************************************************************************************************************
*** MOTION DELAY TURN OF LED/MOTOR DELAY ***
***********************************************************************************************************/
if (webCheckedTrue != "1") {
if (delayMotionRunning && ((millis() - delayMotionStart) > (timeMotionSeconds*1000))) {
static uint32_t hourTimer = millis();
if (millis() - hourTimer >= millisPerHour) {
hourTimer = millis();
motionCounter = 0;
}
motionCounter = motionCounter + 1;
digitalWrite(ledMotor, LOW);
digitalWrite(onMotor, LOW);
delayMotionRunning = false;
ThingSpeak.setField(3, motionCounter);
if (client.connect(thingspeakServer,80)) {
int x = ThingSpeak.writeFields(myChannelNumber, apiKey);
}
client.stop();
}
}
else {
if (delayMotionRunning && ((millis() - delayMotionStart) > (timeMotionSeconds*1000))) {
Serial.println("Motion IDLE...");
static uint32_t hourTimer = millis();
if (millis() - hourTimer >= millisPerHour) {
hourTimer = millis();
motionCounter = 0;
}
motionCounter = motionCounter + 1;
digitalWrite(onMotor, LOW);
delayMotionRunning = false;
ThingSpeak.setField(3, motionCounter);
Serial.println(motionCounter);
if (client.connect(thingspeakServer,80)) {
int x = ThingSpeak.writeFields(myChannelNumber, apiKey);
}
client.stop();
}
}
/************************************************************************************************************
*** AMOUNT DELAY TO CHCK BATTERY STATUS ***
***********************************************************************************************************/
if (voltDelay.justFinished()) {
getVolt();
voltDelay.repeat();
int memHeap = (ESP.getFreeHeap());
ThingSpeak.setField(1, voltage_V);
ThingSpeak.setField(4, memHeap);
if (client.connect(thingspeakServer,80)) {
int x = ThingSpeak.writeFields(myChannelNumber, apiKey);
}
client.stop();
}
/************************************************************************************************************
*** CHECK WEIGHT IF BELOW THRESHOLD_AMOUNT AND REPORT ***
***********************************************************************************************************/
if (amountDelay.justFinished()) {
scale.power_up();
float weight0 = scale.get_units(10);
ThingSpeak.setField(2, weight0);
if (weight0 > THRESHOLD_AMOUNT) {
sendSMTP();
}
scale.power_down();
amountDelay.repeat();
if (client.connect(thingspeakServer,80)) {
int x = ThingSpeak.writeFields(myChannelNumber, apiKey);
}
client.stop();
}
}
0 comentarios
Respuesta aceptada
Christopher Stapels
el 12 de Oct. de 2020
The free license is limited to one update per 15 seconds in a given channel. If you are updating different fields in the same channel asynchronously, there will be collisions where the write frequency requested is faster than the allowed frequency, so your request will be rejected. I reccomend using multiple channels for devices or processes.writing asynchronously.
Más respuestas (0)
Comunidades de usuarios
Más respuestas en ThingSpeak Community
Ver también
Categorías
Más información sobre REST API en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!