did stuff idk i'm cooked

This commit is contained in:
DasMoorhuhn 2024-06-22 22:37:24 +02:00
parent 2b1c12f273
commit 961fba65be
13 changed files with 53 additions and 24 deletions

View File

@ -1,4 +1,4 @@
FROM python:3.12
FROM python:3.12-alpine3.20
WORKDIR = /src
@ -8,8 +8,19 @@ COPY python/docker_entrypoint.sh /
RUN mkdir data
RUN apt-get update && \
apt-get install -y bluez sudo
# RUN apt-get update && \
# apt-get install -y bluez sudo
RUN apk add --no-cache \
sudo \
make \
bluez \
bluez-deprecated \
alsa-utils \
alsa-utils-doc \
alsa-lib \
alsaconf
RUN pip3.12 install -r requierements.txt && rm -f requierements.txt

View File

@ -5,14 +5,14 @@ Python gateway for the [custom firmware](https://github.com/atc1441/ATC_MiThermo
![](.media/41N1IH9jwoL._AC_SL1024_.jpg)
**Features:**
- [DONE] Make in runnable in a docker container (because only cool people are using docker)
- WIP
**TODOs:**
- [WIP] Can run on Raspberry Pi (3, 4, zero w) or any other Linux driven hardware which has BLE and WiFi support
- [WIP] Storing temperature, humidity and battery state as json in a text file
- [WIP] Implement a loop for fetching the data every x minute
- [WIP] Make discoveries async
- [TODO] Make docker image smaller. I mean shiiit 1GB D: should be possible to be under 500MB
- [WIP] Make docker image smaller. I mean shiiit 1GB D: should be possible to be under 500MB
- [TODO] Make a microPython version for using the raspberry pico w or any other microcontroller with BLE and WiFi support
- [TODO] Collect data from multiple devices/gateways
- [TODO] Command line tool for managing the devices
@ -21,6 +21,7 @@ Python gateway for the [custom firmware](https://github.com/atc1441/ATC_MiThermo
- [TODO] MQTT publishing
- [TODO] Maybe... a webinterface. But I suck at web stuff, so I don't know.
- [TODO] Implement other BLE Sensors
- [BROK] Make in runnable in a docker container (because only cool people are using docker)
**Current State**
@ -50,7 +51,7 @@ sudo python3 main.py
### Docker
Build docker container
Build docker container (Currently broken)
```bash
docker-compose build
```

View File

@ -0,0 +1,8 @@
from bluepy.btle import Scanner
scanner = Scanner(0)
print('Start scan...')
devices = scanner.scan(10)
for device in devices:
print('address : %s' % device.addr.upper())
print(device.getScanData())
print('')

13
log_to_json.py Normal file
View File

@ -0,0 +1,13 @@
import json
with open('history.txt', 'r') as file:
content = file.readlines()
lines = []
for line in content:
line = json.loads(line.strip())
lines.append(line)
with open('history.json', 'w') as file:
file.write(json.dumps(lines))

View File

@ -1,2 +1,5 @@
bluepy
pyyaml
pyyaml
bs4
lxml
requests

View File

@ -14,12 +14,10 @@ class Data:
def parse_data(self, val):
data_bytes = [int(val[i:i + 2], 16) for i in range(0, len(val), 2)]
if data_bytes[8] > 127: data_bytes[8] -= 256
if data_bytes[8] > 127:
print(data_bytes)
data_bytes[8] -= 256
self.timestamp = datetime.now().astimezone().replace(microsecond=0).isoformat()
self.mac = ":".join(["{:02X}".format(data_bytes[i]) for i in range(2, 8)])
self.mac = ":".join(["{:02X}".format(data_bytes[i]) for i in range(2, 8)]).upper()
self.temperature = (data_bytes[8] * 256 + data_bytes[9]) / 10
self.humidity = data_bytes[10]
self.battery_percent = data_bytes[11]

View File

@ -20,6 +20,5 @@ def get_devices():
return devices_list
def get_device(dev):
return next((d for d in get_devices() if d.mac == dev.addr.upper()), None)

View File

@ -2,7 +2,7 @@ from bluepy.btle import DefaultDelegate
from bluepy.btle import Scanner
from data_class import Data
from devices import get_devices as get_device_from_config
from devices import get_device
# This is the list, where the responses will be stored from the `handleDiscovery`
devices = []
@ -20,7 +20,7 @@ class ScanDelegate(DefaultDelegate):
data_obj = Data(val)
if self.is_atc_device(dev, data_obj):
device_from_config = self.get_device(dev)
device_from_config = get_device(dev)
devices.append([dev, data_obj, device_from_config])
@staticmethod
@ -35,17 +35,13 @@ class ScanDelegate(DefaultDelegate):
for device in devices:
if str(device[0].addr) == str(dev.addr): return False
device_from_config = self.get_device(dev)
device_from_config = get_device(dev)
try:print(f"Device: {dev.addr.upper()} ({dev.addrType}), RSSI: {dev.rssi} dB, Room: {device_from_config.room}")
except:print(f"Device: {dev.addr.upper()} ({dev.addrType}), RSSI: {dev.rssi} dB, Room: ?")
print(f'\tTemp: {data_obj.temperature}°C, Humid: {data_obj.humidity}%, Batt: {data_obj.battery_percent}%\n')
return True
@staticmethod
def get_device(dev):
return next((d for d in get_device_from_config() if d.mac == dev.addr.upper()), None)
def cleanup():
global devices

1
python/src/log_data.py Normal file
View File

@ -0,0 +1 @@
# TODO

View File

@ -1,7 +1,5 @@
from discovery import start_discovery
from data_class import Data
from loop import start_loop
from time import sleep
devices = start_discovery()

1
python/src/mqtt.py Normal file
View File

@ -0,0 +1 @@
# TODO