Good tutorial on multi threading ESP8266 running C++ https://learn.adafruit.com/multi-tasking-the-arduino-part-1/overview