[SOLVED] Sending sensor data to Ubidots causes delay in my loop() function

Sending sensor data to Ubidots causes delay in my loop() function the causing other activities like taking temperature reading hand for a while (5 seconds or so). When I comment out this function from the code, everything works fine.

void sendToUbi()
{
ubiclient.save_value(idvari, String(temperature)); //this function is to post to ubidots and return True or False depending on the connection status
Serial.println(“The sensor value " + String(temperature) + " was sent to Ubidots”); //print the sensor value
}

And here is my entire Code:

 #include <math.h>
    #include <Wire.h>
    #include <Servo.h> 
    #include <WiFi.h>
    #include <Ubidots.h>
    #include "rgb_lcd.h"
    #include "Timer.h"
    //#include <SoftwareSerial.h>
    
    //SoftwareSerial mySerial(11, 10); // RX, TX
    
    
    char ssid[] = "ROSTELE6";                                                 //your network SSID (name) 
    char pass[] = "XXXXXXXXXXXXX";                                                         //your network password (use for WPA, or use as key for WEP)
    String api = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";                             //your API Key number
    String idvari = "XXXXXXXXXXXXXXXXX";                                          //the number of the Ubidots variable
    String ctext = "{\"color\":\"blue\",\"status\":\"active\"}";
    Ubidots ubiclient(api);                                                             //with that you call the api with the prefix ubiclient
    
    byte p5[8] = {
      0x1F,
      0x1F,
      0x1F,
      0x1F,
      0x1F,
      0x1F,
      0x1F,
      0x1F
      };
    
    int a;
    int temperature;
    int B=3975;                  //B value of the thermistor
    float resistance;
    
    String readString;
    int val;
    int hum = 70.35;
    unsigned char base = 10;
    
    //Temperature Limits
    int maxTemp = 29;
    int minTemp = 28.5;
    
    //Declarations
    rgb_lcd lcd;
    Servo winServo;
    
    //Ubidots timer
    Timer t;
    
    void setup() 
    {    
    //Loading character
    lcd.createChar(0, p5);
       
    Serial1.begin(9600);
    Serial.begin(9600); 
    winServo.attach(3);
    lcd.begin(16, 2);
    //mySerial.begin(9600);
    
    
    //Start Screen
    lcd.print("--SmartGarden--");
    for (int i = 0; i < 16; i++) 
    {
            // scroll one position left:
            lcd.setCursor(i, 1);
            lcd.write((uint8_t)0);
     }
    lcd.clear();
    lcd.print("Connecting...");
    //connect to  wifi network
    boolean response;                                                                
    int status = WL_IDLE_STATUS;                                                                                                          
    response = ubiclient.WifiCon(ssid, pass, status, api);                            
    Serial.println(response);
                                                             
    //
    t.every(1000, sendToUbi);
    
    }
    
    
    void readTemp()
    {
       a=analogRead(0);
       resistance=(float)(1023-a)*10000/a;  
       temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;
        
       //Send temperature via Bluetooth
       Serial1.print(temperature);
       
       //print temperature to LCD
       lcd.clear();
       lcd.setCursor(0,0);
       lcd.print("Tmp:");
       lcd.print(temperature);
       //print humidity to LCD
       lcd.setCursor(8,0);
       lcd.print("Hm:");
       lcd.print("50"); 
    }
    void writeServo()
     {
      if (val != 0)
      {  
      //val = map(val, 0, 1023, 0, 180);     
      winServo.write(val);                  
      delay(10);    
      } 
     } 
    
     void sendToUbi()
     {
     ubiclient.save_value(idvari, String(temperature));                                                  //this function is to post to ubidots and return True or False depending on the connection status
     Serial.println("The sensor value " + String(temperature) + " was sent to Ubidots");                //print the sensor value     
     }                    
    
    void timerMax()
    {
      for (int i = 0; i < 60; i++) 
      {
            
       }
       winServo.write(180);
     }
     
    void loop() 
    {
      //read temperature
      readTemp();
      
      //Update ubidots timer
       t.update();
       
      while (Serial1.available()) { 
        char c = Serial1.read();
        readString += c; 
      }
      if (readString.length() >0)
        {
          Serial.println(readString);
        
           val = readString.toInt();
           if (val != 0)
           {  
           //val = map(val, 0, 1023, 0, 180);     
            winServo.write(val);                  
            delay(10); 
           readString = "";   
           } 
           //writeServo();
        
        
        if (readString == "1")     
           {
            digitalWrite(13, HIGH);
           }
         if (readString == "0")
           {
            digitalWrite(13, LOW);
           }
         readString = "";
      } 
    
      if (temperature >= maxTemp)
      {
        timerMax();
        
      }
      
    }

Hi @DannyGH it seems that your program has multiple libraries and you might be using up the SRAM memory required to make the requests to Ubidots, causing the delay. Can you share the output of the IDE when you compile your code? -->

The dynamic memory is what the program uses to allocate bytes during execution. If it’s too low, you might not be able to, for example, catch a response from a server.