In this example, I am connecting an ESP8266 to MCP9808 I2C temperature sensor, which has a very good accuracy over a wide temperature range.
For complete details, go to my Instructables page :
Here is how it works:
1. Once the device is powered on, the first thing it does is to measure the temperature.
2. Next, it connects to the WiFi
3. It posts the data to the cloud (hosted on data.sparkfun.com)
4. It goes to deep sleep for about 2 minutes. Repeat #1.
In the event that it couldn't connect to the WiFi or find the sensor, it goes to deep sleep and then reset again.