Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import paho.mqtt.client as mqtt
import json
from datetime import datetime
import time
# Function to generate medication reminders based on current time
def generate_medication_reminder():
current_time = datetime.now().strftime("%H:%M")
medication_schedule = {
"03:11": "Take Medication A",
"00:24": "Take Medication B",
"02:55": "Take Medication C"
}
if current_time in medication_schedule:
return medication_schedule[current_time]
else:
return "No medication required right now"
# MQTT client setup
client = mqtt.Client()
client.subscribe("owntracks/HS/#")
client.connect("broker.hivemq.com", 1883)
# Loop to publish medication reminders
while True:
tid = "HS" # Example TID
current_time = datetime.now().strftime("%H:%M:%S")
medication_reminder = generate_medication_reminder()
data_to_publish = {
'tid': tid,
'current_time': current_time,
'medication_reminder': medication_reminder
}
data_encoded = json.dumps(data_to_publish)
client.publish("medication_reminder", data_encoded)
print(f"Just published: {data_to_publish}")
# Sleep for 60 seconds before publishing the next data
time.sleep(3)