[SOLVED] Control humidity without delay function, can't figure it out

Hi, first of all i’m a complete new new newby and now am fiddling for 3 days with a problem I can’t resolve.
I want to send every 30 minutes info temp/hum to ubidots but without the delay, because I want to let the ESP8266 that i’m using to also monitor the humidity level and turn on or of the relay for the humidifier.

With some tutorials I figure to use the      currentTime = millis(); 
         if (currentTime - previousTime > sleepTime*1000) 
         {
        //send to ubidots
        }

When I use this, it will only send only the temperature to ubidots and not my temperature AND humidity. 

My complete code is here. I'm sorry for maybe the code is not completely clear, but thats because I'm not experienced with programming, but still want to make this happen :) 


    #include <DHT.h>
#include <ESP8266WiFi.h>

unsigned long previousTime = 0;
unsigned long currentTime;
int sleepTime = 60; // Time in seconds


#define DHTPIN D2
#define DHTTYPE DHT22
DHT dht (DHTPIN, DHTTYPE);

//humidity control points
#define SETPOINT 52
#define DEADBAND 2.5

//These just make the code easier to read
#define HUMIDIFIER D3 // where humidifier is connectec
#define ON false  //relay works sort of backwards. A low/0/false output is actually ON
#define OFF true //relay works sort of backwards. A high/1/true output is actually OFF


WiFiClient client;

// After creating an account on Ubidots, you'll be able to setup variables where you 
// will store the data. In order to post the measurements to the Ubidots variables,
// we need their "IDs", which are given on the website
String variable_id1 = "ubi_id temp";
String variable_id2 = "ubi_id hum";

// In addition, we'll need the API token, which is what prevents other users
// Ubidots to publish their data to one of your variables
String token = "Token";

// We'll also initialize the values for our Wi-Fi network
const char* ssid = "SSID";
const char* password = "wificode";

//////////////////////////////////////////////////////////////////////////////////
// Function Prototypes
void ubiSave_value(String, String);




void setup() 
{
  Serial.begin(9600);
  // put your setup code here, to run once:
  pinMode(HUMIDIFIER, OUTPUT);
  digitalWrite(HUMIDIFIER, OFF);

  dht.begin();


  // Debug messsages to indicate we're about to connect to the network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  // Use the scanNetworks method inside the Wi-Fi class to scan for any available Wi-Fi networks
  // nearby. If none are found, go to sleep
  int n = WiFi.scanNetworks();

  Serial.println("scan done"); 
  if (n == 0)
  {
    Serial.println("no networks found");
    Serial.println("Going into sleep");
// ESP.deepSleep(sleep_time * 1000000);
  }

  // If networks are found, attempt to connect to our Wi-Fi network
  WiFi.begin(ssid, password);

  // While the connection is not established, IDLE inside this while loop
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }


}

  

void loop() 
{

  delay(2000);

  //Read the temperature and humidity into floating point variables
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // Call our user-defined function ubiSave_value (defined below), and pass it both the 
  // measurements as well as the corresponding Ubidots variable IDs
  ubiSave_value(String(variable_id1), String(t));
  ubiSave_value(String(variable_id2), String(h));



  //Now begin the control logic
  if(digitalRead(HUMIDIFIER) == ON)
  {
    //If the humifier is on, check to see if the humidity is above setpoint
    if( h > SETPOINT + DEADBAND)
    {
      //We've reached the upper limit, so kill the humidifier
      digitalWrite(HUMIDIFIER, OFF);
      Serial.println("HUM IS UIT");
    }
  }
  else
    {
      //If the huidifier is off, check to see if the humidity is below setpoint
      if( h < SETPOINT - DEADBAND)
      {
        //We've reached the lower limit, so kick humidifier on
        digitalWrite(HUMIDIFIER, ON);
        Serial.println("HUM IS AAN");
      }
    
    }

}


////////////////////////////////////////////////////////////////////////////////
// User-defined functions
// We encapsulate the grunt work for publishing temperature and humidty values to Ubidots
// inside the function ubiSave_value
void ubiSave_value(String variable_id, String value)
{
  // Prepare the value that we're to send to Ubidots and get the length of the entire string
  // that's being sent
  String var = "{\"value\": " + value +"}"; // We'll pass the data in JSON format
  String length = String(var.length());

 // currentTime = millis(); //returns amount of time since arduino sketch started runnin in milliseconds.
 // if (currentTime - previousTime > sleepTime*1000) 
 //{


  // If we get a proper connection to the Ubidots API
  if (client.connect("things.ubidots.com", 80))
  {
    Serial.println("Connected to Ubidots...");
    delay(100);

    // Construct the POST request that we'd like to issue
    client.println("POST /api/v1.6/variables/"+variable_id+"/values HTTP/1.1");
    // We also use the Serial terminal to show how the POST request looks like
    Serial.println("POST /api/v1.6/variables/"+variable_id+"/values HTTP/1.1");
    // Specify the contect type so it matches the format of the data (JSON)
    client.println("Content-Type: application/json");
    Serial.println("Content-Type: application/json");
    // Specify the content length
    client.println("Content-Length: "+ length);
    Serial.println("Content-Length: "+ length);
    // Use our own API token so that we can actually publish the data
    client.println("X-Auth-Token: "+ token);
    Serial.println("X-Auth-Token: "+ token);
    // Specify the host
    client.println("Host: things.ubidots.com\n");
    Serial.println("Host: things.ubidots.com\n");
    // Send the actual data
    client.print(var);
    Serial.print(var+"\n");

//    previousTime = currentTime;
  
      
  
  }
  else
  {
    // If we can't establish a connection to the server:
    Serial.println("Ubidots connection failed...");
  }
  
  // If our connection to Ubidots is healthy, read the response from Ubidots
  // and print it to our Serial Monitor for debugging!
  while (client.available())
  {
    char c = client.read();
    Serial.print(c);
  }
  
  // Done with this iteration, close the connection.
  if (client.connected())
  {
    Serial.println("Disconnecting from Ubidots...");
    client.stop();
  }
//}

Serial.print("Klopt, currentTime is kleiner dan ");
    Serial.print(sleepTime);
    Serial.println(" seconden");
    delay(5000);

}

Hello, you should avoid to use the millis() function because it can be get overflow and sometimes you can experience different kind of issues. I suggest you to implement a NTP time routine like this, you should get the actual timestamp and to compare it with a stored timestamp to see if have passed 30 minutes, the main disvantage of this implementation is that you use more data to get the actual timestamp but if you use wifi this should not be a problem.

tnx for your message. At the moment for me that looks really complicated, but I will give it a try.