This project reads data from a BME280 sensor and sends Temperature, Humidity and Pressure data to a Kafka broker allowing time series analytics.
Everything runs via Docker Compose, including the Kafka broker and the Python producer.
No Zookeeper required, Kafka in Kraft mode.
Just clone, build and check the Kafka topics!
You can also modify the docker-compose file so it mounts a volume for Kafka persistence.
Default values. Can be modified in the .env file
bme280-temperaturebme280-humiditybme280-pressure
git clone https://github.com/aranbarri/bme280-kafka
cd bme280-kafkaMake sure it’s connected to your host (e.g. Raspberry Pi) via I2C.
docker-compose up -dThe Python app will start sending sensor data to Kafka each SENSOR_PERIOD_SECONDS automatically. You should see the following logs in console.
-
You can read from the topics via console-consumer (Humidity topic example output):
bin/kafka-console-consumer.sh --bootstrap-server <kafkabroker>:<port> --topic bme280-humidity bin/kafka-console-consumer.sh --bootstrap-server <kafkabroker>:<port> --topic bme280-temperature bin/kafka-console-consumer.sh --bootstrap-server <kafkabroker>:<port> --topic bme280-pressure
docker-compose down -v🛠️ Notes
- Kafka runs in a container on port 9092.
- The app requires access to I2C (/dev/i2c-1); add privileges to the container if needed.
- Python dependencies are in requirements.txt [bme280pi, kafka-python]
- https://pypi.org/project/bme280pi/
This project uses environment variables to configure sensor data streaming to Apache Kafka. Below is a description of each variable defined in the .env file:
Variable Description
KAFKA_BOOTSTRAP_SERVERS Kafka bootstrap server address.
SENSOR_WAIT_SECONDS Wait time until the broker is Up.
SENSOR_PERIOD_SECONDS Time between sensor read and kafka produce. Default: 1 second
TOPIC_TEMP Kafka topic name for temperature readings.
TOPIC_HUM Kafka topic name for humidity readings.
TOPIC_PRES Kafka topic name for pressure readings.Default values:
KAFKA_BOOTSTRAP_SERVERS=kafka:9092
SENSOR_WAIT_SECONDS=30
SENSOR_PERIOD_SECONDS=1
MOCK=FALSE
TOPIC_TEMP=bme280-temperature
TOPIC_HUM=bme280-humidity
TOPIC_PRES=bme280-pressure
Make sure Kafka is accessible from the address specified in KAFKA_BOOTSTRAP_SERVERS.
When using MOCK=TRUE, ensure the application supports mock data generation.
Connection Diagram






