{"id":18305544,"url":"https://github.com/etiennetremel/esp32-home-sensor","last_synced_at":"2025-10-30T15:42:25.201Z","repository":{"id":177832699,"uuid":"625505551","full_name":"etiennetremel/esp32-home-sensor","owner":"etiennetremel","description":"ESP32 DevKit v1 home sensor (bme280) with InfluxDB, Telegraf and Mosquitto MQTT","archived":false,"fork":false,"pushed_at":"2024-11-03T20:06:50.000Z","size":1116,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-21T06:51:14.626Z","etag":null,"topics":["docker-compose","embassy","esp-wifi","esp32","home-automation","homeassistant","influxdb","iot","mqtt","telegraf"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/etiennetremel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-09T10:20:26.000Z","updated_at":"2024-11-03T20:06:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"484265c1-fcef-4765-86fa-3da5b6683467","html_url":"https://github.com/etiennetremel/esp32-home-sensor","commit_stats":null,"previous_names":["etiennetremel/esp32-home-sensor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etiennetremel%2Fesp32-home-sensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etiennetremel%2Fesp32-home-sensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etiennetremel%2Fesp32-home-sensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etiennetremel%2Fesp32-home-sensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/etiennetremel","download_url":"https://codeload.github.com/etiennetremel/esp32-home-sensor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247366874,"owners_count":20927603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker-compose","embassy","esp-wifi","esp32","home-automation","homeassistant","influxdb","iot","mqtt","telegraf"],"created_at":"2024-11-05T15:34:52.451Z","updated_at":"2025-10-30T15:42:25.169Z","avatar_url":"https://github.com/etiennetremel.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"ESP-32 home sensor\n==================\n\n\u003e ESP32 DevKit v1 home sensor using the UART and I2C protocols. It supports\n\u003e various sensors to measure temperature, humidity and pressure. Such as the\n\u003e BME281, SCD30, SDS011, etc.\n\u003e Measurements are sent over TLS and the MQTTv5 protocol to [Mosquitto MQTT\n\u003e broker][mosquitto] and consumed by [Telegraf][telegraf] to persist into\n\u003e [InfluxDB][influxdb].\n\u003e It also supports over-the-air (OTA) automatic firmware upgrade.\n\n## Overview\n\n```mermaid\nflowchart LR\n    OutdoorSds011(fa:fa-microchip Sensor\u003cbr\u003e\u003csmall\u003e\u003ci\u003eSDS011\u003c/i\u003e\u003c/small\u003e)\n    OutdoorBme280(fa:fa-microchip Sensor\u003cbr\u003e\u003csmall\u003e\u003ci\u003eBME280\u003c/i\u003e\u003c/small\u003e)\n    Outdoor(fa:fa-microchip ESP32\u003cbr /\u003e\u003csmall\u003e\u003ci\u003eoutdoor front\u003c/i\u003e\u003c/small\u003e)\n    LivingRoomBme280(fa:fa-microchip Sensor\u003cbr\u003e\u003csmall\u003e\u003ci\u003eBME280\u003c/i\u003e\u003c/small\u003e)\n    LivingRoom(fa:fa-microchip ESP32\u003cbr /\u003e\u003csmall\u003e\u003ci\u003eliving room\u003c/i\u003e\u003c/small\u003e)\n    BedRoomScd30(fa:fa-microchip Sensor\u003cbr\u003e\u003csmall\u003e\u003ci\u003eSCD30\u003c/i\u003e\u003c/small\u003e)\n    BedRoom(fa:fa-microchip ESP32\u003cbr /\u003e\u003csmall\u003e\u003ci\u003ebedroom\u003c/i\u003e\u003c/small\u003e)\n    MQTT(fa:fa-tower-broadcast Mosquitto MQTT)\n    Telegraf(fa:fa-gear Telegraf)\n    InfluxDB(fa:fa-database InfluxDB)\n    InfluxDashboards(fa:fa-chart-line Influx\u003cbr\u003eDashboards)\n    HomeAssistant(fa:fa-house HomeAssistant)\n    OtaServer(fa:fa-upload\u003cbr\u003eOTA Server\u003cbr\u003eFirmware update)\n\n    subgraph Areas\n    direction TB\n    subgraph Outdoor Area\n    direction LR\n    OutdoorBme280--Read--\u003eOutdoor\n    OutdoorSds011--Read--\u003eOutdoor\n    end\n\n    subgraph Living Room Area\n    LivingRoomBme280--Read--\u003eLivingRoom\n    end\n\n    subgraph Bed Room Area\n    BedRoomScd30--Read--\u003eBedRoom\n    end\n    end\n\n    subgraph Influx Stack\n    Telegraf--\u003eInfluxDB\n    InfluxDB--\u003eInfluxDashboards\n    end\n\n    Outdoor-.Check version.-\u003eOtaServer\n    Outdoor--Publish--\u003eMQTT\n    LivingRoom--Publish--\u003eMQTT\n    LivingRoom-.Check version.-\u003eOtaServer\n    BedRoom--Publish--\u003eMQTT\n    BedRoom-.Check version.-\u003eOtaServer\n    MQTT--Subscribe--\u003eTelegraf\n    MQTT-.Subscribe.-\u003eHomeAssistant\n```\n\n## Getting started\n\n### Requirements\n\n- [espflash][espflash]\n- [espmonitor][espmonitor]\n- [espup][espup]\n\n### Pin-out\n\n| Sensor | Pin Sensor  | ESP32 DevKit v1 Pin |\n|--------|-------------|---------------------|\n| BME280 | SDA         | GPIO 21 / D21       |\n| BME280 | SCL         | GPIO 22 / D22       |\n| BME280 | GND         | GND                 |\n| BME280 | 3.3v        | 3v3                 |\n| SCD30  | SDA         | GPIO 21 / D21       |\n| SCD30  | SCL         | GPIO 22 / D22       |\n| SCD30  | GND         | GND                 |\n| SCD30  | 3.3v        | 3v3                 |\n| SDS011 | RX          | GPIO 17 / U2:TXD    |\n| SDS011 | TX          | GPIO 16 / U2:RXD    |\n| SDS011 | GND         | GND                 |\n| SDS011 | 5v          | 5v                  |\n\nNote: I2C devices share the same I2C bus (BME280, SCD30).\n\n### Available features\n\nThe following Cargo features allow you to enable/disable sensors and select the\nMQTT message format to use:\n\n| Feature | Description                       | Default |\n|---------|-----------------------------------|---------|\n| bme280  | Enable BME280 sensor              | no      |\n| sds011  | Enable SDS011 sensor              | no      |\n| influx  | Set MQTT payload format to Influx | yes     |\n| json    | Set MQTT payload format to Json   | no      |\n| tls     | Use TLS to connect to the MQTT    | yes     |\n| mtls    | Use MTLS to connect to the MQTT   | yes     |\n| ota     | Use over the air firmware upgrade | yes     |\n\nFor example, to only enable BME280 with JSON format:\n\n```bash\n. $HOME/export-esp.sh\n# enable BME280, SDS011 with MQTT message in JSON format (default)\ncargo espflash flash --release\n\n# enable BME280 with MQTT message in INFLUX format\ncargo espflash flash --release --features influx,bme280 --no-default-features\n\n# if enabling OTA, make sure to include the partitions parameters\ncargo espflash flash \\\n    --release \\\n    --features influx,tls,mtls,ota,bme280 \\\n    --no-default-features \\\n    -T ./partitions.csv \\\n    --erase-parts otadata\n```\n\n### Configuration\n\nBefore flashing the device, you will need to configure parameters in the\n`./cfg.toml` file, for example:\n\n```toml\nwifi_ssid = \"my-wifi\"\nwifi_psk = \"wifi-password\"\ndevice_id = \"esp32-outdoor\"\nmqtt_hostname = \"homie.local\"\nmqtt_port = 1883\nmqtt_username = \"esp32-outdoor\"\nmqtt_password = \"someranddompassword\"\nmqtt_topic = \"sensors\"\nlocation = \"outdoor\"\n\n# optional\nmeasurement_interval_seconds = 300\n\nota_hostname = \"my-ota.example.com\"\nota_port = 443\n\ntls_ca = \"\"\"\n-----BEGIN CERTIFICATE-----\n// your CA certificate here\n-----END CERTIFICATE-----\n\"\"\"\ntls_key = \"\"\"\n-----BEGIN RSA PRIVATE KEY-----\n// your private key here\n-----END RSA PRIVATE KEY-----\n\"\"\"\ntls_cert = \"\"\"\n-----BEGIN CERTIFICATE-----\n// your certificate here\n-----END CERTIFICATE-----\n```\n\n### TLS\n\nTo enable `TLS` (mqtts), update the `cfg.toml` config to include the CA certificate:\n\n```toml\ntls_ca = \"\"\"\n-----BEGIN CERTIFICATE-----\n// your CA certificate here\n-----END CERTIFICATE-----\n\"\"\"\n```\n\nThen make sure to enable the `tls` feature when you flash:\n```bash\ncargo run --release --features influx,bme280,tls --no-default-features\n```\n\n### mTLS\n\nTo enable `mTLS`, update the `cfg.toml` config to include the CA, client\ncertificate and private key:\n\n```toml\ntls_ca = \"\"\"\n-----BEGIN CERTIFICATE-----\n// your CA certificate here\n-----END CERTIFICATE-----\n\"\"\"\ntls_key = \"\"\"\n-----BEGIN RSA PRIVATE KEY-----\n// your private key here\n-----END RSA PRIVATE KEY-----\n\"\"\"\ntls_cert = \"\"\"\n-----BEGIN CERTIFICATE-----\n// your certificate here\n-----END CERTIFICATE-----\n```\n\nThen make sure to enable both `tls` and `mtls` features when you flash:\n```bash\ncargo run --release --features influx,bme280,tls,mtls --no-default-features\n```\n\n## Development\n\nConnect the device via USB, then run the following command to run flash and\nretrieve logs from the device using espmonitor:\n\n```bash\nespup install\n\n. $HOME/export-esp.sh\n\ncargo run --release\n\n# or run specific features/sensors\ncargo run --release --features json,bme280 --no-default-features\n```\n\n## Flashing\n\nConnect the device via USB, then flash it with the following command:\n\n```bash\n. $HOME/export-esp.sh\ncargo espflash flash --release\n```\n\n## Infrastructure deployment\n\n## Docker Compose\n\nDocker Compose is used to setup the infrastructure. It is composed of 4 services:\n\n- InfluxDB - persistent storage and basic dash-boarding\n- Mosquitto - MQTT broker\n- Telegraf - consume MQTT messages and store them in the database\n- A bash job to setup InfluxDB user/token\n\nFirst, review/adjust environment variables in `./infra/influxdb.env`. Then, for\neach device (one per line) define a username/password in `./infra/mqtt.auth`\nfile. For example:\n\n```yaml\nesp32-outdoor:a19sn#sA94k!a5o10\nesp32-indoor:a93KifAoBf7#01-jl\n```\n\nAfter what, run `docker compose up -d` to deploy the infrastructure.\n\nNote, you might have to restart all containers to get the environment variables\nre-populated into the container after being generated during initial boot.\n\nYou can visualise metrics by importing `./infra/influx-dashboard.json` as\ndashboard into InfluxDB.\n\n![InfluxDB dashboard](./dashboard.png)\n\n### Kubernetes\n\nAlternative deployment solution with Talos and Kubernetes can be found in the\n[etiennetremel/homie-lab][homie-lab] repository.\n\n### Setup Home Assistant or other providers\n\nIt's possible to change the payload format of the MQTT message to JSON instead\nof Influx by using the `--features json`.\n\nRefer to the [Home Assistant documentation][home-assistant] for details on how\nto set this up.\n\n![Home Assistant dashboard](./home-assistant.png)\n\n## Over the Air firmware upgrades (OTA)\n\nRefer to the [Over-the-Air firmware upgrades documentation][ota] for details on\nhow to use it.\n\n\u003c!-- page links --\u003e\n[espflash]: https://esp-rs.github.io/book/tooling/espflash.html\n[espmonitor]: https://esp-rs.github.io/book/tooling/espmonitor.html\n[espup]: https://esp-rs.github.io/book/installation/installation.html#espup\n[home-assistant]: ./docs/home-assistant.md\n[homie-lab]: https://github.com/etiennetremel/homie-lab\n[influxdb]: https://www.influxdata.com\n[mosquitto]: https://mosquitto.org\n[ota]: ./docs/ota-firmware-upgrade.md\n[telegraf]: https://www.influxdata.com/time-series-platform/telegraf/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetiennetremel%2Fesp32-home-sensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fetiennetremel%2Fesp32-home-sensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetiennetremel%2Fesp32-home-sensor/lists"}