The function does not work in ESP8266

Why ?

It is legitimate for loop() to return to main() if there is no more code for it to execute. main() will then call loop() again