From aaccbbe668df9aa2f26dcd17904e1d28e4095e07 Mon Sep 17 00:00:00 2001 From: matt Date: Tue, 13 Oct 2026 02:48:05 -0700 Subject: [PATCH] redis test 4 --- README.md | 2 +- ble-redis.py | 20 ++++++++++++++++++++ scanner.py | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 ble-redis.py diff --git a/README.md b/README.md index 8391c64..86270ed 100644 --- a/README.md +++ b/README.md @@ -182,9 +182,9 @@ The Python code is split across multiple files with different files having code ble-scanner/ ├─ app.py # Flask + Scheduler + API ├─ ble.py # BLE helper functions to read temp+humidity data +├─ ble-redis.py # Redis functions for Websocket support ├─ scanner.py # Async BLE scan + cache logic ├─ config.py # Shared constants (prefix, interval, etc.) -├─ redis.py # Redis functions for Websocket support ├─ requirements.txt # Python VENV requirements ├─ run.sh # Run API from shell ├─ scanner.py # Handles scanning for Mii sensors, other helper functions diff --git a/ble-redis.py b/ble-redis.py new file mode 100644 index 0000000..45de8fe --- /dev/null +++ b/ble-redis.py @@ -0,0 +1,20 @@ + +import redis +import json +from config import * + +#################################################### +### Redis Functions +#################################################### +if enable_redis: + r = redis.Redis(host=bind_ip, port=redis_port) + +def update_redis(data): + # push data to redis + # Publish to the Redis channel that the WS server is listening on + r.publish('temp_hum', json.dumps(data)) + if debug_output: + print("=== Stats Redis Update ===") + print(json.dumps(data, indent=2)) + return True + diff --git a/scanner.py b/scanner.py index 8bd80c0..048a55f 100644 --- a/scanner.py +++ b/scanner.py @@ -8,7 +8,7 @@ from typing import Set, Iterable from config import * from sensors import * from ble import * -from redis import * +from ble-redis import * # In-memory cache + thread-safe lock _mac_cache: Set[str] = set()