From 7f5262575e81e24965fc48f3b9b89cec0d4640d1 Mon Sep 17 00:00:00 2001 From: the Date: Tue, 12 Nov 2024 16:18:14 +0400 Subject: [PATCH 01/12] webhook test --- GreenhouseDetector/detector.py | 46 ++++++++++++++-------------------- GreenhouseManager/manager.py | 34 ++++++++++--------------- 2 files changed, 32 insertions(+), 48 deletions(-) diff --git a/GreenhouseDetector/detector.py b/GreenhouseDetector/detector.py index 728ec1d..57545e9 100644 --- a/GreenhouseDetector/detector.py +++ b/GreenhouseDetector/detector.py @@ -1,13 +1,19 @@ -from random import random -from turtledemo.penrose import start - -from kafka import KafkaProducer, KafkaConsumer -import kafka -import socket -from json import dumps, loads import time import random as rnd +from flask import Flask, jsonify +import requests +import threading + +app = Flask(__name__) + +def start_detector(): + while True: + for detector in detectors: + detector.cycle() + detector.sendData() + time.sleep(1) + class Detector: def __init__(self, id, moistureThresholdUpper, moistureThresholdLower, tempThresholdUpper, tempThresholdLower): self.id = id @@ -18,31 +24,17 @@ class Detector: self.moisture = 0 self.temp = 0 - self.producer = KafkaProducer( - bootstrap_servers=['localhost:9092'], - client_id=f'detector{self.id}', - value_serializer=lambda v: dumps(v).encode('utf-8') - ) - - def sendData(self): - message = {'id' : self.id, - 'moisture': self.moisture, - 'temperature' : self.temp } - self.producer.send('dataDetectors', message) - def cycle(self): self.moisture += rnd.random() / 100 self.temp += (rnd.random() - 0.5) / 100 detector1 = Detector(1, 0.6, 0.2, 40, 20) -detector2 = Detector(2, 0.7, 0.3, 40, 20) -detector3 = Detector(3, 0.9, 0.6, 40, 20) -detectors = [detector1, detector2, detector3] +detectors = [detector1] -while True: - for detector in detectors: - detector.cycle() - detector.sendData() - time.sleep(1) +t1 = threading.Thread(target=start_detector) + +if __name__ =="__main__": + t1.start() + app.run(host='0.0.0.0', port=20001, debug=True) diff --git a/GreenhouseManager/manager.py b/GreenhouseManager/manager.py index c082d04..b3d21bf 100644 --- a/GreenhouseManager/manager.py +++ b/GreenhouseManager/manager.py @@ -2,15 +2,15 @@ from kafka import KafkaProducer, KafkaConsumer import kafka import socket from json import dumps, loads +from flask import Flask, request import time from enum import Enum -from GreenhouseDetector.detector import Detector +import threading -class Status(Enum): - UNKNOWN = -1 - OFF = 0 - ON = 1 +app = Flask(__name__) +def start_manager(): + return class Manager: def __init__(self, id: int, moisture: float = 0, temp: float = 20, isAutoOn: bool = False, valve_state: str = "closed", @@ -28,15 +28,6 @@ class Manager: value_serializer=lambda v: dumps(v).encode('utf-8') ) - # self.detectorConsumer = KafkaConsumer( - # 'dataDetectors', - # bootstrap_servers=['localhost:9092'], - # auto_offset_reset='earliest', - # enable_auto_commit=True, - # consumer_timeout_ms=1000, - #group_id=f'manager{id}', - # value_deserializer=lambda x: loads(x.decode('utf-8')) - #) self.controllerConsumer = KafkaConsumer( 'commands', bootstrap_servers=['localhost:9092'], @@ -129,16 +120,17 @@ class Manager: self.command = message.value['command'] self.toggle_device(self.command, self.request_id, self.greenhouse_id) - +@app.route('/webhook', methods=['POST']) +def webhook(): + if request.method == 'POST': + print("Data received from Webhook is") + return "Webhook received" manager1 = Manager(id=1) managers = [manager1] +t1 = threading.Thread(target=start_manager) -while True: - time.sleep(5) - manager1.sendData() - for manager in managers: - - manager.getCommand() +if __name__ == "__main__": + app.run(host="0.0.0.0", port=20002) \ No newline at end of file -- 2.25.1 From b7f4aa3f9f145a1e5c14fa63a97cf9af1a50b975 Mon Sep 17 00:00:00 2001 From: the Date: Tue, 12 Nov 2024 16:19:37 +0400 Subject: [PATCH 02/12] webhook fix --- GreenhouseManager/manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GreenhouseManager/manager.py b/GreenhouseManager/manager.py index b3d21bf..1152700 100644 --- a/GreenhouseManager/manager.py +++ b/GreenhouseManager/manager.py @@ -123,7 +123,7 @@ class Manager: @app.route('/webhook', methods=['POST']) def webhook(): if request.method == 'POST': - print("Data received from Webhook is") + print("Data received from Webhook is", request.json) return "Webhook received" manager1 = Manager(id=1) -- 2.25.1 From f82c8daa92541b2fdc60878a64ba978c8535e92a Mon Sep 17 00:00:00 2001 From: the Date: Tue, 12 Nov 2024 17:04:24 +0400 Subject: [PATCH 03/12] detector webhooks --- GreenhouseDetector/detector.py | 23 +++++++++---------- GreenhouseManager/manager.py | 41 +++++++++++++++------------------- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/GreenhouseDetector/detector.py b/GreenhouseDetector/detector.py index 57545e9..d092373 100644 --- a/GreenhouseDetector/detector.py +++ b/GreenhouseDetector/detector.py @@ -1,19 +1,12 @@ import time import random as rnd -from flask import Flask, jsonify +from flask import Flask import requests import threading app = Flask(__name__) -def start_detector(): - while True: - for detector in detectors: - detector.cycle() - detector.sendData() - time.sleep(1) - class Detector: def __init__(self, id, moistureThresholdUpper, moistureThresholdLower, tempThresholdUpper, tempThresholdLower): self.id = id @@ -28,13 +21,19 @@ class Detector: self.moisture += rnd.random() / 100 self.temp += (rnd.random() - 0.5) / 100 + def sendData(self): + data = {"moisture": self.moisture, + "temp": self.temp} + requests.post(f"http://127.0.0.1:20002/webhook?id={self.id}", json=data) + detector1 = Detector(1, 0.6, 0.2, 40, 20) detectors = [detector1] -t1 = threading.Thread(target=start_detector) - if __name__ =="__main__": - t1.start() - app.run(host='0.0.0.0', port=20001, debug=True) + while True: + for detector in detectors: + detector.cycle() + detector.sendData() + time.sleep(1) diff --git a/GreenhouseManager/manager.py b/GreenhouseManager/manager.py index 1152700..457c483 100644 --- a/GreenhouseManager/manager.py +++ b/GreenhouseManager/manager.py @@ -13,9 +13,9 @@ def start_manager(): return class Manager: - def __init__(self, id: int, moisture: float = 0, temp: float = 20, isAutoOn: bool = False, valve_state: str = "closed", + def __init__(self, _id: int, moisture: float = 0, temp: float = 20, isAutoOn: bool = False, valve_state: str = "closed", heater_state: str = "off"): - self.id = id + self._id = _id self.moisture = moisture self.temp = temp self.isAutoOn = isAutoOn @@ -24,7 +24,7 @@ class Manager: self.dataPublisher = KafkaProducer( bootstrap_servers=['localhost:9092'], - client_id=f'manager{id}_producer', + client_id=f'manager{self._id}_producer', value_serializer=lambda v: dumps(v).encode('utf-8') ) @@ -34,30 +34,19 @@ class Manager: auto_offset_reset='earliest', enable_auto_commit=True, consumer_timeout_ms=2000, - group_id=f'manager{id}', + group_id=f'manager{self._id}', value_deserializer=lambda x: loads(x.decode('utf-8')) ) self.controllerConsumerResponse = KafkaProducer( bootstrap_servers=['localhost:9092'], - client_id=f'manager{id}_producer', + client_id=f'manager{self._id}_producer', value_serializer=lambda v: dumps(v).encode('utf-8') ) - def update(self): - for message in self.detectorConsumer: - - print(f"Manager {self.id} received message: ") - print(message.value) - self.moisture = message.value['moisture'] - self.temp = message.value['temperature'] - print("Updating info...\n") - - self.sendData() - def sendData(self): print("sending data...") message = { - 'id': self.id, + 'id': self._id, 'moisture': self.moisture, 'temp': self.temp, 'valveStatus': str(self.valve_state), @@ -113,21 +102,27 @@ class Manager: for tp, msgs in messages.items(): for message in msgs: - print(f"Manager {self.id} received message: ") + print(f"Manager {self._id} received message: ") print(message.value) self.request_id = message.value['request_id'] self.greenhouse_id = message.value['greenhouse_id'] self.command = message.value['command'] self.toggle_device(self.command, self.request_id, self.greenhouse_id) -@app.route('/webhook', methods=['POST']) +@app.route(f'/webhook', methods=['POST']) def webhook(): - if request.method == 'POST': - print("Data received from Webhook is", request.json) - return "Webhook received" + for manager in managers: + if request.args.get('id') == manager._id and request.method == 'POST': + print("Data received from Webhook is", request.json) -manager1 = Manager(id=1) + body = request.json + for key, value in body.items(): + setattr(manager, key, value) + return f"Webhook received for manager {manager._id}" + return "Webhook ignored" + +manager1 = Manager(_id=1) managers = [manager1] t1 = threading.Thread(target=start_manager) -- 2.25.1 From 4747f975c53d19befc73d28da032cac98f0ae69f Mon Sep 17 00:00:00 2001 From: the Date: Tue, 12 Nov 2024 18:03:45 +0400 Subject: [PATCH 04/12] kafka network --- docker-compose.yml | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 995a9e2..e05fdef 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,7 @@ services: zookeeper: + networks: + - vpn image: confluentinc/cp-zookeeper:7.4.0 environment: ZOOKEEPER_CLIENT_PORT: 2181 @@ -8,17 +10,18 @@ services: - 2181:2181 kafka: + networks: + - vpn image: confluentinc/cp-kafka:7.4.0 ports: - - 9092:9092 - - 9997:9997 - expose: - 29092:29092 environment: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT - KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 + KAFKA_LISTENERS: EXTERNAL_SAME_HOST://:29092,EXTERNAL_DIFFERENT_HOST://:29093,INTERNAL://:9092 + KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092,EXTERNAL_SAME_HOST://localhost:29092,EXTERNAL_DIFFERENT_HOST://157.245.80.232:29093 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL_SAME_HOST:PLAINTEXT,EXTERNAL_DIFFERENT_HOST:PLAINTEXT + KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 KAFKA_LOG_FLUSH_INTERVAL_MESSAGES: 10000 @@ -27,6 +30,8 @@ services: - zookeeper init-kafka: + networks: + - vpn image: confluentinc/cp-kafka:7.4.0 depends_on: - kafka @@ -34,19 +39,20 @@ services: command: | " # blocks until kafka is reachable - kafka-topics --bootstrap-server kafka:29092 --list + kafka-topics --bootstrap-server kafka:9092 --list echo -e 'Creating kafka topics' - kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic commands --replication-factor 1 --partitions 1 - kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic data --replication-factor 1 --partitions 1 - kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic dataDetectors --replication-factor 1 --partitions 1 - kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic response --replication-factor 1 --partitions 1 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic commands --replication-factor 1 --partitions 1 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic data --replication-factor 1 --partitions 1 + kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic response --replication-factor 1 --partitions 1 echo -e 'Successfully created the following topics:' - kafka-topics --bootstrap-server kafka:29092 --list + kafka-topics --bootstrap-server kafka:9092 --list " kafka-ui: + networks: + - vpn container_name: kafka-ui image: provectuslabs/kafka-ui:latest ports: @@ -56,4 +62,8 @@ services: environment: KAFKA_CLUSTERS_0_NAME: local KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092 - KAFKA_CLUSTERS_0_METRICS_PORT: 9997 \ No newline at end of file + KAFKA_CLUSTERS_0_METRICS_PORT: 9997 + +networks: + vpn: + name: kafkaVPN \ No newline at end of file -- 2.25.1 From ce3f3a4dc64ed5a987f4194f6707f0e6bbea85a5 Mon Sep 17 00:00:00 2001 From: the Date: Tue, 12 Nov 2024 22:31:57 +0400 Subject: [PATCH 05/12] kafka network fix --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e05fdef..f17fc16 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,8 +18,8 @@ services: environment: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 - KAFKA_LISTENERS: EXTERNAL_SAME_HOST://:29092,EXTERNAL_DIFFERENT_HOST://:29093,INTERNAL://:9092 - KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092,EXTERNAL_SAME_HOST://localhost:29092,EXTERNAL_DIFFERENT_HOST://157.245.80.232:29093 + KAFKA_LISTENERS: EXTERNAL_SAME_HOST://:29092,EXTERNAL_DIFFERENT_HOST://:29092,INTERNAL://:9092 + KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092,EXTERNAL_SAME_HOST://localhost:29092,EXTERNAL_DIFFERENT_HOST://157.245.80.232:29092 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL_SAME_HOST:PLAINTEXT,EXTERNAL_DIFFERENT_HOST:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 -- 2.25.1 From 57e05aba909768bf6518fd37849150b6c52b6f86 Mon Sep 17 00:00:00 2001 From: the Date: Tue, 12 Nov 2024 22:34:06 +0400 Subject: [PATCH 06/12] kafka network unfix --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f17fc16..e05fdef 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,8 +18,8 @@ services: environment: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 - KAFKA_LISTENERS: EXTERNAL_SAME_HOST://:29092,EXTERNAL_DIFFERENT_HOST://:29092,INTERNAL://:9092 - KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092,EXTERNAL_SAME_HOST://localhost:29092,EXTERNAL_DIFFERENT_HOST://157.245.80.232:29092 + KAFKA_LISTENERS: EXTERNAL_SAME_HOST://:29092,EXTERNAL_DIFFERENT_HOST://:29093,INTERNAL://:9092 + KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092,EXTERNAL_SAME_HOST://localhost:29092,EXTERNAL_DIFFERENT_HOST://157.245.80.232:29093 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL_SAME_HOST:PLAINTEXT,EXTERNAL_DIFFERENT_HOST:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 -- 2.25.1 From ffef39d409773dde7850fdd759f5ac5aaf2ba007 Mon Sep 17 00:00:00 2001 From: the Date: Wed, 13 Nov 2024 00:30:33 +0400 Subject: [PATCH 07/12] =?UTF-8?q?=D0=A1=D0=A2=D0=9E=D0=9B=D0=AC=D0=9A?= =?UTF-8?q?=D0=9E=20=D0=9C=D0=A3=D0=A7=D0=95=D0=9D=D0=98=D0=99=20=D0=A0?= =?UTF-8?q?=D0=90=D0=94=D0=98=20=D0=9E=D0=94=D0=9D=D0=9E=D0=99=20=D0=A1?= =?UTF-8?q?=D0=A2=D0=A0=D0=9E=D0=A7=D0=9A=D0=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GreenhouseManager/manager.py | 3 +++ docker-compose.yml | 47 ++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/GreenhouseManager/manager.py b/GreenhouseManager/manager.py index 457c483..794fbff 100644 --- a/GreenhouseManager/manager.py +++ b/GreenhouseManager/manager.py @@ -56,6 +56,7 @@ class Manager: print(message) self.dataPublisher.send('data', message) + self.dataPublisher.flush() def toggle_device(self, device, request_id, greenhouse_id): @@ -119,6 +120,8 @@ def webhook(): for key, value in body.items(): setattr(manager, key, value) + manager.sendData() + return f"Webhook received for manager {manager._id}" return "Webhook ignored" diff --git a/docker-compose.yml b/docker-compose.yml index e05fdef..a0a4521 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ services: zookeeper: - networks: - - vpn +# networks: +# - vpn image: confluentinc/cp-zookeeper:7.4.0 environment: ZOOKEEPER_CLIENT_PORT: 2181 @@ -10,18 +10,23 @@ services: - 2181:2181 kafka: - networks: - - vpn +# networks: +# - vpn image: confluentinc/cp-kafka:7.4.0 ports: - - 29092:29092 + - 9092:9092 + - 9997:9997 + + expose: + - 29092:29092 + environment: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 - KAFKA_LISTENERS: EXTERNAL_SAME_HOST://:29092,EXTERNAL_DIFFERENT_HOST://:29093,INTERNAL://:9092 - KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092,EXTERNAL_SAME_HOST://localhost:29092,EXTERNAL_DIFFERENT_HOST://157.245.80.232:29093 - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL_SAME_HOST:PLAINTEXT,EXTERNAL_DIFFERENT_HOST:PLAINTEXT - KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL + KAFKA_LISTENERS: HOST://0.0.0.0:9092,DOCKER://0.0.0.0:29092 + KAFKA_ADVERTISED_LISTENERS: HOST://localhost:9092,DOCKER://kafka:29092 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: DOCKER:PLAINTEXT,HOST:PLAINTEXT + KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 KAFKA_LOG_FLUSH_INTERVAL_MESSAGES: 10000 @@ -30,8 +35,8 @@ services: - zookeeper init-kafka: - networks: - - vpn +# networks: +# - vpn image: confluentinc/cp-kafka:7.4.0 depends_on: - kafka @@ -39,20 +44,20 @@ services: command: | " # blocks until kafka is reachable - kafka-topics --bootstrap-server kafka:9092 --list + kafka-topics --bootstrap-server kafka:29092 --list echo -e 'Creating kafka topics' - kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic commands --replication-factor 1 --partitions 1 - kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic data --replication-factor 1 --partitions 1 - kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic response --replication-factor 1 --partitions 1 + kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic commands --replication-factor 1 --partitions 1 + kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic data --replication-factor 1 --partitions 1 + kafka-topics --bootstrap-server kafka:29092 --create --if-not-exists --topic response --replication-factor 1 --partitions 1 echo -e 'Successfully created the following topics:' - kafka-topics --bootstrap-server kafka:9092 --list + kafka-topics --bootstrap-server kafka:29092 --list " kafka-ui: - networks: - - vpn +# networks: +# - vpn container_name: kafka-ui image: provectuslabs/kafka-ui:latest ports: @@ -64,6 +69,6 @@ services: KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092 KAFKA_CLUSTERS_0_METRICS_PORT: 9997 -networks: - vpn: - name: kafkaVPN \ No newline at end of file +#networks: +# vpn: +# name: kafkaVPN \ No newline at end of file -- 2.25.1 From 73961934f0081de042370a133fd2fee49f94b2aa Mon Sep 17 00:00:00 2001 From: the Date: Wed, 13 Nov 2024 00:31:21 +0400 Subject: [PATCH 08/12] =?UTF-8?q?=D0=A1=D0=A2=D0=9E=D0=9B=D0=AC=D0=9A?= =?UTF-8?q?=D0=9E=20=D0=9C=D0=A3=D0=A7=D0=95=D0=9D=D0=98=D0=99=20=D0=A0?= =?UTF-8?q?=D0=90=D0=94=D0=98=20=D0=9E=D0=94=D0=9D=D0=9E=D0=99=20=D0=A1?= =?UTF-8?q?=D0=A2=D0=A0=D0=9E=D0=A7=D0=9A=D0=98,=20=D0=95=D0=A9=D0=81=20?= =?UTF-8?q?=D0=98=20=D0=9D=D0=95=D0=A2=D0=92=D0=9E=D0=A0=D0=9A=20=D0=9D?= =?UTF-8?q?=D0=90=20=D0=A1=D0=90=D0=9C=D0=9E=D0=9C=20=D0=94=D0=95=D0=9B?= =?UTF-8?q?=D0=95=20=D0=9D=D0=95=20=D0=A0=D0=90=D0=91=D0=9E=D0=A2=D0=90?= =?UTF-8?q?=D0=95=D0=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GreenhouseManager/manager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/GreenhouseManager/manager.py b/GreenhouseManager/manager.py index 794fbff..efee642 100644 --- a/GreenhouseManager/manager.py +++ b/GreenhouseManager/manager.py @@ -58,6 +58,7 @@ class Manager: self.dataPublisher.send('data', message) self.dataPublisher.flush() + def toggle_device(self, device, request_id, greenhouse_id): if device == 'valve': -- 2.25.1 From b009ebdd0ced34f1628dc368c28b8aaa88318797 Mon Sep 17 00:00:00 2001 From: the Date: Wed, 13 Nov 2024 00:36:31 +0400 Subject: [PATCH 09/12] =?UTF-8?q?=D0=90=D0=90=D0=90=D0=90=D0=90=D0=90?= =?UTF-8?q?=D0=90=D0=90=D0=90=D0=90=D0=90=D0=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a0a4521..56659ba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 KAFKA_LISTENERS: HOST://0.0.0.0:9092,DOCKER://0.0.0.0:29092 - KAFKA_ADVERTISED_LISTENERS: HOST://localhost:9092,DOCKER://kafka:29092 + KAFKA_ADVERTISED_LISTENERS: HOST://192.168.1.5:9092,DOCKER://kafka:29092 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: DOCKER:PLAINTEXT,HOST:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 -- 2.25.1 From 83aec339c9875de463d6d3fadd72519d0ae528d9 Mon Sep 17 00:00:00 2001 From: the Date: Wed, 13 Nov 2024 00:53:31 +0400 Subject: [PATCH 10/12] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GreenhouseManager/manager.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/GreenhouseManager/manager.py b/GreenhouseManager/manager.py index efee642..d9772d1 100644 --- a/GreenhouseManager/manager.py +++ b/GreenhouseManager/manager.py @@ -113,8 +113,10 @@ class Manager: @app.route(f'/webhook', methods=['POST']) def webhook(): + print("received webhook", request.args.get('id')) for manager in managers: - if request.args.get('id') == manager._id and request.method == 'POST': + print() + if int(request.args.get('id')) == manager._id and request.method == 'POST': print("Data received from Webhook is", request.json) body = request.json @@ -126,10 +128,9 @@ def webhook(): return f"Webhook received for manager {manager._id}" return "Webhook ignored" +t1 = threading.Thread(target=start_manager) manager1 = Manager(_id=1) managers = [manager1] -t1 = threading.Thread(target=start_manager) - if __name__ == "__main__": - app.run(host="0.0.0.0", port=20002) \ No newline at end of file + threading.Thread(target=lambda: app.run(host="0.0.0.0", port=20002, debug=True, use_reloader=False)).start() \ No newline at end of file -- 2.25.1 From c0322536999c239e455efbadcb1724d174c8c6c7 Mon Sep 17 00:00:00 2001 From: the Date: Wed, 13 Nov 2024 01:00:16 +0400 Subject: [PATCH 11/12] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=812?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 56659ba..32dc5a9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ services: zookeeper: -# networks: -# - vpn + networks: + - vpn image: confluentinc/cp-zookeeper:7.4.0 environment: ZOOKEEPER_CLIENT_PORT: 2181 @@ -10,8 +10,8 @@ services: - 2181:2181 kafka: -# networks: -# - vpn + networks: + - vpn image: confluentinc/cp-kafka:7.4.0 ports: - 9092:9092 @@ -35,8 +35,8 @@ services: - zookeeper init-kafka: -# networks: -# - vpn + networks: + - vpn image: confluentinc/cp-kafka:7.4.0 depends_on: - kafka @@ -56,8 +56,8 @@ services: " kafka-ui: -# networks: -# - vpn + networks: + - vpn container_name: kafka-ui image: provectuslabs/kafka-ui:latest ports: @@ -69,6 +69,6 @@ services: KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092 KAFKA_CLUSTERS_0_METRICS_PORT: 9997 -#networks: -# vpn: -# name: kafkaVPN \ No newline at end of file +networks: + vpn: + name: kafkaVPN \ No newline at end of file -- 2.25.1 From 5fa9c76b996d3b79ed60ee3d4c6623271400b6fa Mon Sep 17 00:00:00 2001 From: the Date: Wed, 13 Nov 2024 01:14:32 +0400 Subject: [PATCH 12/12] test changes --- docker-compose.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 32dc5a9..a1e5c42 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,12 @@ +networks: + vpn: + name: kafkaVPN + driver: bridge + ipam: + config: + - subnet: "192.168.2.0/24" + gateway: "192.168.2.1" + services: zookeeper: networks: @@ -11,7 +20,8 @@ services: kafka: networks: - - vpn + vpn: + ipv4_address: 192.168.2.10 image: confluentinc/cp-kafka:7.4.0 ports: - 9092:9092 @@ -68,7 +78,3 @@ services: KAFKA_CLUSTERS_0_NAME: local KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092 KAFKA_CLUSTERS_0_METRICS_PORT: 9997 - -networks: - vpn: - name: kafkaVPN \ No newline at end of file -- 2.25.1