The function does not work in ESP8266

Wouldn't it be better to omit the while at all and change it to a simple if?
Also the return; isn't really a good idea. loop() should loop - from start to end :wink: .