2024-10-23 14:11:04 +04:00
|
|
|
import pika
|
|
|
|
import time
|
|
|
|
|
|
|
|
def publish_events():
|
2024-10-23 15:56:48 +04:00
|
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost', port=5672, credentials=pika.PlainCredentials("user", "password")))
|
2024-10-23 14:11:04 +04:00
|
|
|
channel = connection.channel()
|
|
|
|
|
|
|
|
channel.exchange_declare(exchange='greenhouse_events', exchange_type='fanout')
|
|
|
|
|
|
|
|
events = [
|
|
|
|
"Влажность превысила верхнюю границу",
|
|
|
|
"Влажность упала за нижнюю границу",
|
|
|
|
"Полив начат",
|
|
|
|
"Полив остановлен"
|
|
|
|
]
|
|
|
|
|
|
|
|
while True:
|
|
|
|
event = events[int(time.time()) % len(events)]
|
|
|
|
channel.basic_publish(exchange='greenhouse_events', routing_key='', body=event)
|
|
|
|
print(f'Отправлено: {event}')
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
publish_events()
|