redis test 1
This commit is contained in:
1 parent
66e022bafe
commit
839f7602df
5 files changed
+46
-3
No files matched your search
@@ -184,6 +184,7 @@ ble-scanner/
|
||||
├─ ble.py # BLE helper functions to read temp+humidity data
|
||||
├─ 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
|
||||
|
||||
@@ -50,4 +50,4 @@ def hello():
|
||||
# --- Run --------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
# The scheduler runs in its own thread; the main thread serves Flask.
|
||||
app.run(host='0.0.0.0', port=5000, debug=False)
|
||||
app.run(host=bind_ip, port=api_port, debug=False)
|
||||
@@ -1,3 +1,22 @@
|
||||
# --- BLE & app config -------------------------------------------------
|
||||
MAC_PREFIX = "A4:C1:38" # 3 octets (change to what you need)
|
||||
SCAN_INTERVAL_MINUTES = 1 # how often to run the scan
|
||||
|
||||
MAC_PREFIX = "A4:C1:38"
|
||||
SCAN_INTERVAL_MINUTES = 1
|
||||
debug_output = False
|
||||
bind_ip = "0.0.0.0"
|
||||
api_port = 5000
|
||||
redis_port = 6379
|
||||
enable_redis = True
|
||||
|
||||
# --- This will store friendly names for MAC addresses -----------------
|
||||
comment_lookup =
|
||||
[
|
||||
{
|
||||
"mac": "A4:C1:38:00:11:10",
|
||||
"comment": "Living Room"
|
||||
},
|
||||
{
|
||||
"mac": "A4:C1:38:00:11:11",
|
||||
"comment": "Main Bedroom"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
import redis
|
||||
import json
|
||||
from config.py 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
|
||||
|
||||
@@ -52,6 +52,9 @@ def update_cache() -> None:
|
||||
if sensor.name == sensor_datum['name']:
|
||||
sensor.add_or_update(key="temp", value=sensor_datum['temp'])
|
||||
sensor.add_or_update(key="humidity", value=sensor_datum['humidity'])
|
||||
|
||||
if enable_redis:
|
||||
update_redis(get_sensor_details())
|
||||
|
||||
def scan_macs():
|
||||
new_macs = asyncio.run(_scan_once())
|
||||
|
||||
Reference in new issue
Block a user