changes
This commit is contained in:
parent
db89541352
commit
d57becf736
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
.*~
|
||||
*.pyc
|
||||
.venv/
|
||||
__pycache__/
|
||||
|
6
env
6
env
@ -2,10 +2,12 @@ export MQTT_BROKER="172.23.1.102"
|
||||
export MQTT_PORT=1883
|
||||
export MQTT_BOXES='{
|
||||
"box1": {
|
||||
"label": "living_room"
|
||||
"label": "living_room",
|
||||
"windows": [ "street_side", "garden_side" ]
|
||||
},
|
||||
"box2": {
|
||||
"label": "kitchen"
|
||||
"label": "kitchen",
|
||||
"windows": [ "street_side", "garden_side", "garden_door" ]
|
||||
}
|
||||
}'
|
||||
export MQTT_BOX_TOPIC_PREFIXES='{
|
||||
|
@ -42,6 +42,11 @@ context['publish'] = PUBLISH_PREFIX
|
||||
# Load box configurations from JSON
|
||||
try:
|
||||
boxes = json.loads(BOXES_CONFIG)
|
||||
|
||||
# here, boxes store their internal state
|
||||
boxes['context'] = {}
|
||||
|
||||
# boxes structure added to global context to give process_message access to it
|
||||
context['boxes'] = boxes
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Error parsing JSON configuration for boxes: {e}")
|
||||
@ -83,6 +88,9 @@ def on_connect(client, userdata, flags, rc):
|
||||
# Generate topics based on configured box-specific prefixes and box label
|
||||
topics = {}
|
||||
for topic_key, prefix in box_topic_prefixes.items():
|
||||
if topic_key == 'window':
|
||||
for window in boxes.windows:
|
||||
|
||||
topics[topic_key] = f"{prefix}{label}"
|
||||
config["subscribe"] = topics # Store the generated topics
|
||||
|
||||
|
@ -1,9 +1,29 @@
|
||||
from loguru import logger
|
||||
|
||||
|
||||
# context
|
||||
# boxes: structure of boxes
|
||||
# client: MQTT client
|
||||
#
|
||||
# boxes['context']
|
||||
# store here what ever is require to represent the state of the box
|
||||
|
||||
def process_message(box_name, topic_key, payload, context):
|
||||
try:
|
||||
logger.info(f"[{box_name}] Processing message for '{topic_key}': {payload}")
|
||||
|
||||
match topic_key:
|
||||
case 'window':
|
||||
pass
|
||||
case 'high_temp':
|
||||
pass
|
||||
case 'cmd':
|
||||
pass
|
||||
case 'general_off':
|
||||
pass
|
||||
case 'maintenance_mode':
|
||||
pass
|
||||
|
||||
# Example processing: Implement your specific logic here
|
||||
# For example, perform calculations or store data.
|
||||
result = f"Processed by {box_name} for '{topic_key}': {payload}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user