Cucumber/GreenhouseDetector/detector.py

41 lines
1.0 KiB
Python
Raw Normal View History

2024-10-29 16:07:02 +04:00
import time
import random as rnd
2024-11-12 16:18:14 +04:00
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)
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-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]
t1 = threading.Thread(target=start_detector)
2024-10-29 16:07:02 +04:00
2024-11-12 16:18:14 +04:00
if __name__ =="__main__":
t1.start()
app.run(host='0.0.0.0', port=20001, debug=True)
2024-10-29 16:07:02 +04:00