This is a version of my Pi Sensor Reader for reading temperature and humidity values from an attached DHT22/AM2302 sensor and posting them to an HTTP endpoint, but written in Python for use with MicroPython on an ESP32 microcontroller.
Updates that fail to be sent — if the server is down, or you have no internet connection, etc. — will be written to the queue
directory and attempted to be re-posted every five minutes.
It requires a file called config.json
at the root of the src
directory, configured with your wifi network name and password, the GPIO pin that the DHT22 sensor is connected to, endpoint to periodically post data to, and the API key that protects that endpoint. An example file is given in config.example.json.
esp32-sensor-reader has four HTTP endpoints:
GET /
— Get the current temperature and humidity values.GET /log
— View the log file that's written to when errors occur.DELETE /log
— Clear the log file; this requires theX-API-Key
header to be set with the same value as what you're sending to the endpoint.GET /queue
— View the current queue of updates that failed to be sent and are awaiting re-sending.DELETE /queue
— Clear the queue; as above, it requires theX-API-Key
header to be set.POST /reset
— Restarts the ESP32; as above, it requires theX-API-Key
header to be set.
local_only
— If set totrue
, the ESP32 won't attempt to post sensor updates anywhere and will just run the local webserver for polling