adafruit / Adafruit_IO_Arduino

Arduino library to access Adafruit IO from WiFi, cellular, and ethernet modules.
Other
208 stars 108 forks source link

One of two feeds not initializing on get() during setup #144

Closed markvanpraet closed 3 years ago

markvanpraet commented 3 years ago

I have 2 feeds that I've set up to contain threshold values used in the sketch. During execution, when updated through io.adafruit.com, they are each handled properly. However, during setup, when I attempt to get() each of these values, only one triggers the retrieval of the latest value (photoresistorthreshold). The other (temperature) does nothing - regardless of order, and even when I comment out the working feed's get(). Code excerpts: ` AdafruitIO_Feed photoresistorthreshold = io.feed("Photoresistor Threshold"); // allows management of photoresistor threshold (can be finicky) AdafruitIO_Feed temperaturethreshold = io.feed("TemperatureThreshold"); // allows management of temperature threshold ///////////// .... void setup(){

Serial.begin(115200); // start serial port for debug while(! Serial); // wait for serial monitor to open // // Adafruit IO handshake // long unsigned int startConnect = millis(); Serial.print("Connecting to Adafruit IO"); io.connect(); // connect to io.adafruit.com while((io.status() < AIO_CONNECTED) && (millis() < (startConnect + connectTimeout))){ // wait for a connection or until timeout Serial.print("."); delay(500); } Serial.println(); Serial.println(io.statusText());

photoresistorthreshold->onMessage(handlePRThreshold); // set up handle to catch any changes to the light threshold from Adafruit IO temperaturethreshold->onMessage(handleTempThreshold); // set up handle to catch any changes to the temperature threshold from Adafruit IO

temperaturethreshold->get(); // force retrieval of most recent threshold data photoresistorthreshold->get(); // force retrieval of most recent threshold data

sensors.begin(); /////////////// ...... void handlePRThreshold(AdafruitIO_Data data) { int prThreshold = data->toInt(); // convert the data to integer alertLightR = prThreshold; // set the new reference threshold Serial.print("<-photo threshold: "); Serial.println(alertLightR); } // void handleTempThreshold(AdafruitIO_Data data) { float tempThreshold = data->toFloat(); // convert the data to integer alertTempC = tempThreshold; // set the new reference threshold Serial.print("<-temp threshold: "); Serial.println(alertTempC); }`

The "temperaturethreshold" get() call does NOT trigger during setup (only once executing). The photoresistor feed triggers at setup and during execution.

At this point, it's mostly just a PITA for testing as I have to always immediately update through the web when I restart the sketch, but it is curious behaviour.

brentru commented 3 years ago

The "temperaturethreshold" get() call does NOT trigger during setup (only once executing). The photoresistor feed triggers at setup and during execution.

I am not able to replicate this issue on my end with a Feather Huzzah ESP8266. I'm able to get() the retained values of three feeds during setup.

Adafruit IO connected.
received <- a a
received <- b b
received <- light is off.

Could you try updating the board support package for ESP8266? Is there anything else I could try?

markvanpraet commented 3 years ago

I believe the issue can be explained by a corrupt feed. After recreating a new feed the issue disappeared. The suspect feed's JSON was saved in an earlier post on this thread, but I have since deleted the feed. My problem can be considered resolved, but if anyone wants to dig deeper, they are welcome to. Thanks for following up though!