2024-10-29 16:07:02 +04:00
|
|
|
import time
|
|
|
|
import random as rnd
|
|
|
|
|
2024-11-12 17:04:24 +04:00
|
|
|
from flask import Flask
|
2024-11-12 16:18:14 +04:00
|
|
|
import requests
|
|
|
|
import threading
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2024-10-29 16:07:02 +04:00
|
|
|
class Detector:
|
|
|
|
def __init__(self, id, moistureThresholdUpper, moistureThresholdLower, tempThresholdUpper, tempThresholdLower):
|
|
|
|
self.id = id
|
|
|
|
self.moistureThresholdUpper = moistureThresholdUpper
|
|
|
|
self.moistureThresholdLower = moistureThresholdLower
|
|
|
|
self.tempThresholdUpper = tempThresholdUpper
|
|
|
|
self.tempThresholdLower = tempThresholdLower
|
|
|
|
self.moisture = 0
|
|
|
|
self.temp = 0
|
|
|
|
|
|
|
|
def cycle(self):
|
|
|
|
self.moisture += rnd.random() / 100
|
|
|
|
self.temp += (rnd.random() - 0.5) / 100
|
|
|
|
|
2024-11-12 17:04:24 +04:00
|
|
|
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)
|
|
|
|
|
2024-10-29 17:31:47 +04:00
|
|
|
detector1 = Detector(1, 0.6, 0.2, 40, 20)
|
|
|
|
|
2024-11-12 16:18:14 +04:00
|
|
|
detectors = [detector1]
|
|
|
|
|
|
|
|
if __name__ =="__main__":
|
2024-11-12 17:04:24 +04:00
|
|
|
while True:
|
|
|
|
for detector in detectors:
|
|
|
|
detector.cycle()
|
|
|
|
detector.sendData()
|
|
|
|
time.sleep(1)
|
2024-10-29 16:07:02 +04:00
|
|
|
|