diff --git a/requirements.txt b/requirements.txt index 31e7040..c3c0b83 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1 @@ -requests - -#bme280 -adafruit-circuitpython-bme280 - -#sht20 -sensor -smbus -spidev \ No newline at end of file +esphome \ No newline at end of file diff --git a/sensor.service b/sensor.service deleted file mode 100644 index 846e22d..0000000 --- a/sensor.service +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=Reading sensors data with python -Wants=network-online.target -After=network-online.target - -[Service] -#ExecStartPre=/bin/bash -c 'source /etc/environment' -ExecStart=python /root/hassio-growbox/sensors/threadManager.py -WorkingDirectory=/root/hassio-growbox/sensors -Environment=PYTHONPATH=/root/hassio-growbox/env/lib/python3.9/site-packages -Restart=on-failure -EnvironmentFile=/etc/environment -#StartLimitIntervalSec=0 - -[Install] -WantedBy=multi-user.target diff --git a/sensors/bme280.py b/sensors/bme280.py deleted file mode 100644 index 18d5663..0000000 --- a/sensors/bme280.py +++ /dev/null @@ -1,60 +0,0 @@ -import os -import requests -import fcntl -import board -from adafruit_bme280 import basic as adafruit_bme280 -import syslog -import time - -syslog.openlog(facility=syslog.LOG_LOCAL0) - -LLA_TOKEN = os.getenv('TOKEN') - -i2c = board.I2C() -bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) - -# Create a lock file -lock_file = open('../lockfile.lock', 'w') - - -def sensing(): - # Acquire a lock on the lock file - fcntl.flock(lock_file, fcntl.LOCK_EX) - - # GET VALUES - air_temperature = str(round(bme280.temperature, 2)) - air_humidity = str(round(bme280.humidity, 2)) - air_pressure = str(round(bme280.pressure, 2)) - - # SEND VALUES - header = {'Authorization': 'Bearer ' + LLA_TOKEN, 'Content-Type': 'application/json'} - try: - requests.post('http://localhost:8123/api/states/sensor.air_temperature', headers=header, json={ - 'state': air_temperature, - 'attributes': { - 'unit_of_measurement': '°C' - } - }) - time.sleep(5) - requests.post('http://localhost:8123/api/states/sensor.air_humidity', headers=header, json={ - 'state': air_humidity, - 'attributes': { - 'unit_of_measurement': '%' - } - }) - time.sleep(5) - requests.post('http://localhost:8123/api/states/sensor.air_pressure', headers=header, json={ - 'state': air_pressure, - 'attributes': { - 'unit_of_measurement': 'mbar' - } - }) - #response.raise_for_status() - except requests.exceptions.RequestException as e: - syslog.syslog(syslog.LOG_WARNING, str(e)) - finally: - # Release the lock on the lock file - fcntl.flock(lock_file, fcntl.LOCK_UN) - - -sensing() diff --git a/sensors/sht20.py b/sensors/sht20.py deleted file mode 100644 index 8d33c4e..0000000 --- a/sensors/sht20.py +++ /dev/null @@ -1,53 +0,0 @@ -import os -import requests -import fcntl -from sensor import SHT20 -import syslog -import time - -syslog.openlog(facility=syslog.LOG_LOCAL0) - -LLA_TOKEN = os.getenv('TOKEN') - -sht = SHT20(1, 0x40) - -# Create a lock file -lock_file = open('../lockfile.lock', 'w') - - -def sensing(): - # Acquire a lock on the lock file - fcntl.flock(lock_file, fcntl.LOCK_EX) - - # GET VALUES - t = sht.temperature() - soil_temperature = str(round(t.C, 2)) - - h = sht.humidity() - soil_humidity = str(round(h.RH, 2)) - - # SEND VALUES - header = {'Authorization': 'Bearer ' + LLA_TOKEN, 'Content-Type': 'application/json'} - try: - requests.post('http://localhost:8123/api/states/sensor.soil_temperature', headers=header, json={ - 'state': soil_temperature, - 'attributes': { - 'unit_of_measurement': '°C' - } - }) - time.sleep(5) - requests.post('http://localhost:8123/api/states/sensor.soil_humidity', headers=header, json={ - 'state': soil_humidity, - 'attributes': { - 'unit_of_measurement': '%' - } - }) - #response.raise_for_status() - except requests.exceptions.RequestException as e: - syslog.syslog(syslog.LOG_WARNING, str(e)) - finally: - # Release the lock on the lock file - fcntl.flock(lock_file, fcntl.LOCK_UN) - - -sensing() diff --git a/sensors/threadManager.py b/sensors/threadManager.py deleted file mode 100644 index 0d65e05..0000000 --- a/sensors/threadManager.py +++ /dev/null @@ -1,17 +0,0 @@ -import os -import threading - - -# List of sensor reading scripts -scripts = ['bme280.py', 'sht20.py'] - - -def run_sensor_scripts(): - threading.Timer(45.0, run_sensor_scripts).start() - - # Loop through each script and run it while holding the lock - for script in scripts: - os.system('/root/hassio-growbox/env/bin/python ' + script) - - -run_sensor_scripts()