Commit 7c5a2eff authored by Levin Zimmermann's avatar Levin Zimmermann

playbook: Fix sensor installation for Debian 11

Previously it only worked with Debian 10. This commit reflects the
removal of the apt package 'python-pip' in Debian 11 and the change
of the i2c bus number.
parent 90ea4d1c
- name: Install apt package dependencies
apt:
pkg:
- python
- python-pip
- python3
- python3-pip
- i2c-tools
- python-smbus
- python3-smbus
state: present
- name: Install setuptools
pip:
name: setuptools
executable: pip2
executable: pip3
- name: Install bme280
pip:
name: bme280
executable: pip2
executable: pip3
# We need to set a different bus number depending
# on the debian version. For Debian 12 we may
# need another number again.
- name: Set bus number for debian bullseye
set_fact:
i2c_bus_number: 3
when: ansible_distribution == 'Debian' and ansible_distribution_release == 'Buster'
- name: Set bus number for debian bullseye
set_fact:
i2c_bus_number: 2
when: ansible_distribution == 'Debian' and ansible_distribution_release == 'bullseye'
- name: Solve python template to read sensor
template:
......@@ -27,8 +41,8 @@
set_olimex_sensor_permission_path: /usr/bin/olimex-sensor-set-sensor-permission
- name: Move script to grant access to sensor to file path
copy:
src: olimex-sensor-set-sensor-permission.sh
template:
src: olimex-sensor-set-sensor-permission.j2
dest: "{{ set_olimex_sensor_permission_path }}"
mode: 755
......
#!/bin/bash
chgrp slapsoft /dev/i2c-{{ i2c_bus_number }}
......@@ -6,9 +6,9 @@ from bme280 import bme280_i2c
from bme280.bme280 import read_all
bme280_i2c.set_default_i2c_address(int("0x77", 0)) # address of sensor 0x77
bme280_i2c.set_default_bus(int({{ i2c_bus_number }})) # i2c bus number 3 (i2c-3)
bme280_i2c.set_default_bus(int({{ i2c_bus_number }})) # depends on distro version
bme280.setup()
data = bme280.read_all()
print("{}\t{}\t{}".format(data.pressure,data.humidity,data.temperature))
print("{}\t{}\t{}".format(data.pressure, data.humidity, data.temperature))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment