Skip to content

A simple MicroPython application written for an ESP32 microcontroller, used for reading temperature and humidity from a DHT22/AM2302 sensor and posting the results to an HTTP endpoint.

License

VirtualWolf/esp32-sensor-reader

Repository files navigation

esp32-sensor-reader

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.

Helpful tools

Setup

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.

Endpoints

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 the X-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 the X-API-Key header to be set.
  • POST /reset — Restarts the ESP32; as above, it requires the X-API-Key header to be set.

Options

  • local_only — If set to true, the ESP32 won't attempt to post sensor updates anywhere and will just run the local webserver for polling

About

A simple MicroPython application written for an ESP32 microcontroller, used for reading temperature and humidity from a DHT22/AM2302 sensor and posting the results to an HTTP endpoint.

Topics

Resources

License

Stars

Watchers

Forks

Languages