Cucumber/GreenhouseDetector/detector.py
2024-11-12 16:18:14 +04:00

41 lines
1.0 KiB
Python

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
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
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)