Humidity = dht11.GetHumidity ' Get humidity from readed measure
Temperature = dht11.GetTemperature ' Get temperature from readed measure Server.Initialize(51042, "server_NewConnection")ĭht11.Read11(DHT11pin.PinNumber) ' Reading the DHT11 measure But to maximize battery life, it should only make one reading and sleep again.ĭim humidity,temperature As Double ' Humidity/Temperature DHT11 readingsĭHT11pin.Initialize(2, DHT11pin.MODE_INPUT) Of course I could let ESP be awake like 10 seconds before sleeping, that would make it easier for the B4J program to connect to it. The server could try continuously try connect to the ESP but it would have to be somewhat lucky to hit the time window where ESP is awake. But if I press the Connect button, it continues to show the readings until ESP sleeps again. When the ESP wakes up again, B4J does not automatically reconnect. The B4J server sees that the ESP is disconnected and drops the connection. The problem with the ping method is that the ESP is sleeping between readings. But the server needs to be listening and it only starts listening when I press Connect and initiates the connection.
It wakes up X minutes later and sends a new reading etc. Ideally ESP takes just one reading from the DHT11 and sends it to the server and goes to sleep. The two ends need to be connected at the same time.