So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Bonzo
#76383 I have a solar/battery powered setup in my greenhouse and it is communicating via wireless Udp to a Pi.

I am not sure if the Pi is sleeping but sometimes the Nodemcu does not receive a request for the data and so it stays on an extra 10 or maybe 30min waiting. As you can guess this is not good for my battery life.

The logic is every 10 min step the Pi sends a signal to the Nodemcu and the Nodemcu sends the packet back to the Pi. The Nodemcu then goes into deep sleep for 9min waking in time for the next signal from the pi. The deep sleep command is in the waiting for the packet section of the code.

I assume I can not add an Arduino delay as that stops the code and I can not see a timeout option in the wifiudp library. Please can somebody suggest a good way to do this.

I have thought about using an Arduino timer instead of a delay but there may be something in the ESPLibrary I am including?

Code: Select allvoid loop()
      if (!bme.begin()) { 
        Serial.println("Could not find a valid BME280 sensor, check wiring!");
        while (1);
      int packetSize = Udp.parsePacket();
      if (packetSize)
        // receive incoming UDP packets
        Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
        int len =, 255);
        if (len > 0)
          incomingPacket[len] = 0;
        Serial.printf("UDP packet contents: %s\n", incomingPacket);
        // send back a reply, to the IP address and port we got the packet from
        Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
        delay(1000); // Need a delay otherwise the data is not sent Was 3000
        delay(1000); // Need a delay otherwise the loop starts again before deep sleep