Commit bfc12e7e authored by Ľuboš Jenčík's avatar Ľuboš Jenčík
Browse files

update

parent 42dc69dd
This diff is collapsed.
from umqtt.robust import MQTTClient
from machine import Pin
from machine import Pin, reset
from time import sleep
import separate
#well1 global
def setWell1(msg):
separate.well1 = msg
print(well1)
def setWell2(msg):
separate.well2 = msg
print(well2)
def getWell1():
return separate.well1
#well2 global
def setWell2(msg):
separate.well2 = msg
def getWell2():
return separate.well2
#humidity
def getHumidity():
return separate.humidity1
def setHumidity(msg):
separate.humidity1 = msg
#connect to WiFi
def do_connect(ssid, password):
import network
wlan = network.WLAN(network.STA_IF)
......@@ -28,10 +36,8 @@ def do_connect(ssid, password):
pass
print('network config:', wlan.ifconfig())
do_connect('JencikWifi1', 'Matus2621996')
def callback(topic, message):
if(topic == b"irrigation/humidity1"):
if(topic == b"irrigation/humidity1.1"):
humidity(topic, message)
elif(topic == b"irrigation/well/sensor/1"):
print("well1")
......@@ -40,16 +46,16 @@ def callback(topic, message):
print("well2")
well2(topic, message)
elif(topic == b"irrigation/esp32/switch"):
print("pumpa vypnuta")
print("pumpa")
def humidity(topic, message):
value = int(message)
print(value)
global variable
if(value < 40):
variable = True
setHumidity(True)
else:
variable = False
setHumidity(False)
def well1(topic, message):
global topic1
......@@ -67,69 +73,43 @@ def switch(topic, message):
switch = True
do_connect('JencikWifi1', 'Matus2621996')
led2 = Pin(4, Pin.OUT)
led1 = Pin(23, Pin.OUT)
client = MQTTClient('esp32-lukas', 'broker.hivemq.com', 1883)
client.set_callback(callback)
client.connect()
client.subscribe('irrigation/humidity1.1')
variable = False
while True:
client = MQTTClient('esp32-lukas', 'broker.hivemq.com', 1883)
client.set_callback(callback)
client.connect()
client.subscribe('irrigation/humidity1')
print('Humidity .')
client.wait_msg()
client.wait_msg()
client.disconnect()
if(variable == True):
client = MQTTClient('esp32-lukas', 'broker.hivemq.com', 1883)
client.set_callback(callback)
client.connect()
client.check_msg()
if(getHumidity() == True):
num1 = "1"
client.publish('irrigation/esp/run', num1, qos=0, retain=False)
client.subscribe('irrigation/well/sensor/1')
topic1 = False
while True:
print('Studne .')
client.wait_msg()
if(topic1 == True):
break;
print('Cakam studna 1')
client.wait_msg()
print('studna 1, hodnota: {}'.format(getWell1()))
client.disconnect()
client = MQTTClient('esp32-lukas', 'broker.hivemq.com', 1883)
client.set_callback(callback)
client.connect()
client.subscribe('irrigation/well/sensor/2')
topic2 = False
while True:
print('Studne .')
client.wait_msg()
if(topic2 == True):
break;
client.disconnect()
print(getWell1())
print('Cakam studna 2')
client.wait_msg()
print('studna 2, hodnota: {}'.format(getWell2()))
if(getWell1() >= getWell2()):
client = MQTTClient('esp32-lukas', 'broker.hivemq.com', 1883)
client.set_callback(callback)
client.connect()
num1 = "1"
client.publish('irrigation/esp32/pump', num1)
led1.on()
client.subscribe('irrigation/esp32/switch')
client.wait_msg()
client.wait_msg()
led1.off()
client.disconnect()
else:
client = MQTTClient('esp32-lukas', 'broker.hivemq.com', 1883)
client.set_callback(callback)
client.connect()
num1 = "2"
client.publish('irrigation/esp32/pump', num1)
led2.on()
......@@ -139,8 +119,8 @@ while True:
client.wait_msg()
led2.off()
client.disconnect()
setHumidity(False)
sleep(1)
\ No newline at end of file
global well1
global well2
\ No newline at end of file
global well2
humidity1 = False
\ No newline at end of file
from umqtt.robust import MQTTClient
from machine import ADC, Pin
from time import sleep
import separate
def getValue():
return separate.value
def setValue(msg):
separate.value = msg
def do_connect(ssid, password):
import network
......@@ -12,11 +19,21 @@ def do_connect(ssid, password):
while not wlan.isconnected():
pass
print('network config:', wlan.ifconfig())
def callback(topic, message):
value = int(message)
if value == 0:
setValue(False)
elif value == 1:
setValue(True)
do_connect('JencikWifi1', 'Matus2621996')
client = MQTTClient('esp32-lubos', 'broker.hivemq.com', 1883)
client.set_callback(callback)
client.connect()
client.subscribe('irrigation/esp/run')
adc1 = ADC(Pin(34))
adc1.atten(ADC.ATTN_6DB)
......@@ -25,10 +42,14 @@ adc2.atten(ADC.ATTN_6DB)
while True:
print('.')
num1 = str(adc1.read())
num2 = str(adc2.read())
client.publish('irrigation/well/sensor/1', num1)
sleep(2)
client.publish('irrigation/well/sensor/2', num2)
sleep(2)
\ No newline at end of file
client.check_msg()
if getValue() == True:
num1 = str(adc1.read())
num2 = str(adc2.read())
client.publish('irrigation/well/sensor/1', num1)
sleep(2)
client.publish('irrigation/well/sensor/2', num2)
sleep(2)
setValue(False)
sleep(1)
value = False
\ No newline at end of file
......@@ -12,49 +12,15 @@
"user_id": "e1c1de7135b9419386f3b38ae8cdeb07",
"friendly_name": "Hackathon-2021"
},
"last_changed": "2021-04-29T23:10:36.232343+00:00",
"last_updated": "2021-04-29T23:10:53.783458+00:00",
"last_changed": "2021-05-18T13:48:01.871818+00:00",
"last_updated": "2021-05-18T13:48:17.557335+00:00",
"context": {
"id": "e14ef186b16f9e73ec8c9654d0bbe59b",
"id": "96acedf4aee7f5f38f2c45b97e5dae11",
"parent_id": null,
"user_id": null
}
},
"last_seen": "2021-04-29T23:12:03.991991+00:00"
},
{
"state": {
"entity_id": "switch.pump_of_well_1",
"state": "off",
"attributes": {
"friendly_name": "Pump of well 1"
},
"last_changed": "2021-04-28T21:15:35.662712+00:00",
"last_updated": "2021-04-28T21:15:35.662712+00:00",
"context": {
"id": "b79742e1567221892d562edba05c3f56",
"parent_id": null,
"user_id": null
}
},
"last_seen": "2021-04-28T23:33:22.195288+00:00"
},
{
"state": {
"entity_id": "switch.pump_of_well_2",
"state": "off",
"attributes": {
"friendly_name": "Pump of well 2"
},
"last_changed": "2021-04-28T21:15:41.750446+00:00",
"last_updated": "2021-04-28T21:15:41.750446+00:00",
"context": {
"id": "0a4e1e327fadeb34ceeace769a558ec8",
"parent_id": null,
"user_id": null
}
},
"last_seen": "2021-04-28T23:33:22.195288+00:00"
"last_seen": "2021-05-18T16:28:19.491556+00:00"
}
]
}
\ No newline at end of file
......@@ -2,12 +2,12 @@
"version": 1,
"key": "http",
"data": {
"ip_ban_enabled": true,
"server_port": 8123,
"login_attempts_threshold": -1,
"ssl_profile": "modern",
"ip_ban_enabled": true,
"cors_allowed_origins": [
"https://cast.home-assistant.io"
]
],
"ssl_profile": "modern",
"server_port": 8123
}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment