Immediate transmission of data

Hi to all
I making project to measure weight of beehive and send it to cloud.
ESP8622 read weight and send it to cayenne after this go to deep sleep for half hour.
Everything work OK if I don’t put ESP in sleep mode. I think it is not sending data immediate. How can I fix this? It is important for me to ESP stay wake as lees time as possible. Battery supply…
part of code:

Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
sensors_1.requestTemperatures();
temperatura = sensors_1.getTempCByIndex(0);
zajem_adc= analogRead(beri_senzor); // napetost na bateriji

Serial.print(“Reading: “);
// Serial.print(scale.get_units(), 3);
teza= scale.get_units(5), 3;
Serial.print (teza);
Serial.println(” kg”);
// Serial.print(" calibration_factor: ");
// Serial.print(calibration_factor);
// Serial.println();

if (digitalRead(TARA) == LOW) {
shrani_tara();
Serial.println(“tipka TARA.”);
}
Serial.print("zajem ADC ");
Serial.println(zajem_adc);
Serial.print(“temperatura “);
Serial.print(temperatura);
Serial.println(” st.C”);
baterija= 80;
Cayenne.loop();
delay(1000);

scale.power_down(); // put the ADC in sleep mode
Serial.print("gremo spat… ");
ESP.deepSleep(30e6); // ESP in deep sleep

}

CAYENNE_OUT_DEFAULT()
//CAYENNE_OUT(1)
{
long rssi = WiFi.RSSI(); // moč wifi signala
Cayenne.virtualWrite(0 , teza, “TEZA”, “kq”); // teža na tehnici (vključno z kompenzacijo temperature)
Cayenne.celsiusWrite(1, temperatura); // temperatura okolice
Cayenne.virtualWrite(2 , rssi, “RSSI”, “dbm”); // WiFi signal
Cayenne.virtualWrite(3, baterija, “bat”,"%"); // stanje baterije v %
}

Found solution.
I hope it will work.

Serial.print(“zajem ADC “);
Serial.println(zajem_adc);
Serial.print(“temperatura “);
Serial.print(temperatura);
Serial.println(” st.C”);
baterija= 80;
//Cayenne.loop();
long rssi = WiFi.RSSI(); // moč wifi signala
Cayenne.virtualWrite(0 , teza, “TEZA”, “kq”); // teža na tehnici (vključno z kompenzacijo temperature)
Cayenne.celsiusWrite(1, temperatura); // temperatura okolice
Cayenne.virtualWrite(2 , rssi, “RSSI”, “dbm”); // WiFi signal
Cayenne.virtualWrite(3, baterija, “bat”,”%”); // stanje baterije v %
// delay(1000);

scale.power_down(); // put the ADC in sleep mode
Serial.print("gremo spat… ");
ESP.deepSleep(30e6); /ESP in deep sleep

}

dont add publish code in the main loop. You can use a global variable to check whether the publish has happened or not.

boolena send = false;

void loop() {
if(send){
ESP.deepSleep(30e6); // ESP in deep sleep
}
}
CAYENNE_OUT_DEFAULT()
//CAYENNE_OUT(1)
{
long rssi = WiFi.RSSI(); // moč wifi signala
Cayenne.virtualWrite(0 , teza, “TEZA”, “kq”); // teža na tehnici (vključno z kompenzacijo temperature)
Cayenne.celsiusWrite(1, temperatura); // temperatura okolice
Cayenne.virtualWrite(2 , rssi, “RSSI”, “dbm”); // WiFi signal
Cayenne.virtualWrite(3, baterija, “bat”,"%"); // stanje baterije v %
send = true;
}

Hi
Understand.
But like you I must wait data to be send. This mean few more = more power consumption.
If I add it on main loop then data is send immediately. After 2.days no errors yet on sending

If it works then, you can keep it as it is.