If you want an easy route: flash the esp8266 with Tasmota.
You’ll then be able to get at the data using the MQTT binding.
Related: Tasmota flashed Sonoff Basic with DHT22 via MQTT
Of course, if this is an exercise in getting your own code to work, check some similar projects to see how they handle MQTT.