Ubidots Community

Floating 4 subscribed variables independently - Arduino IDE

Hi Everybody,
I consider myself a newbie (coding for the last 1 year) and I am struggling for quite long time already, trying to float the 4 values from last subscription within a loop, in an independent way. In fact, my code works, but it keeps subscribing over and over and over. I would like to store the values in a float (for example), and only update the value if new values are given. Any help would be great!

My code looks like this:

So, I am trying to float the last value from ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL1), so I can use it in an "IF"statement, without needing to check it ever few milliseconds.

My code looks something like this.

void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
ubidots.setDebug(true); // uncomment this to make debug messages available
ubidots.connectToWifi(WIFI_SSID, WIFI_PASS);
ubidots.setCallback(callback);
ubidots.setup();
ubidots.reconnect();
dht.begin();

// Subscribe
ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL1); // Insert the dataSource and Variable’s Labels
ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL2); // Insert the dataSource and Variable’s Labels
ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL3); // Insert the dataSource and Variable’s Labels
ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL4); // Insert the dataSource and Variable’s

void loop()
{
if (!ubidots.connected())
{ ubidots.reconnect();
ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL1); // Insert the dataSource and Variable’s Labels
ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL2); // Insert the dataSource and Variable’s Labels
ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL3); // Insert the dataSource and Variable’s Labels
ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL4); // Insert the dataSource and Variable’s Labels
}

if (currentTime - previousTimeRelay >= CONTROL_FREQUENCY) {

        if (temperature< ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL1)  ) {  
                                digitalWrite(activator1, HIGH);  
                                }
        if (temperature< ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL2)  ) {  
                                digitalWrite(activator2, HIGH);  
                                }
        if (temperature< ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL3)  ) {  
                                digitalWrite(activator3, HIGH);  
                                }
        if (temperature< ubidots.subscribeLastValue(DEVICE_LABEL, VARIABLE_LABEL4)  ) {  
                                digitalWrite(activator4, HIGH);  
                                }

The code works well so far, but by using this syntax, the ESP32 keeps subscribing every few milliseconds over and over. I would like to keep the last values of VARIABLE_LABEL1, VARIABLE_LABEL2, VARIABLE_LABEL3 and VARIABLE_LABEL4 in a float independently (meaning that sometimes I will receive VARIABLE_LABEL1, AND/OR 2, AND/OR 3, AND/OR 4 , so I can use it without subscribing over and over.

Hope I was enough clear. Any help will be excelent!!
Thanks a lot
Best wishes,
Matias