Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ed46d80ad | ||
|
|
05a73720bb | ||
|
|
fc717f18a2 | ||
|
|
50117a5a96 | ||
|
|
309c209b1b | ||
|
|
9a81f0fbba |
@@ -1,4 +1,4 @@
|
|||||||
# 0.5.8 - xx/07/2018
|
# 0.5.8 - 19/07/2018
|
||||||
- Added "openweathermap" driver for impement check weather condition from openweatermap api
|
- Added "openweathermap" driver for impement check weather condition from openweatermap api
|
||||||
|
|
||||||
# 0.5.7 - 01/06/2018
|
# 0.5.7 - 01/06/2018
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
For more information see https://www.lejubila.net/2018/03/pigardent-0-5-5-driver-master-per-implementare-un-architettura-master-slave/
|
For more information see https://www.lejubila.net/2018/03/pigardent-0-5-5-driver-master-per-implementare-un-architettura-master-slave/
|
||||||
|
|
||||||
# Example of zone configuration in piGarden.conf
|
# Example of zone configuration in piGarden.conf
|
||||||
|
```bash
|
||||||
EV1_ALIAS="Giarino_Posteriore_DX" #
|
EV1_ALIAS="Giarino_Posteriore_DX" #
|
||||||
EV1_GPIO="drv:remote:PIREMOTE1:Giardino_Posteriore_DX"
|
EV1_GPIO="drv:remote:PIREMOTE1:Giardino_Posteriore_DX"
|
||||||
|
|
||||||
@@ -11,3 +11,4 @@ PIREMOTE1_IP="192.168.1.51"
|
|||||||
PIREMOTE1_PORT="8084"
|
PIREMOTE1_PORT="8084"
|
||||||
PIREMOTE1_USER=""
|
PIREMOTE1_USER=""
|
||||||
PIREMOTE1_PWD=""
|
PIREMOTE1_PWD=""
|
||||||
|
```
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ More information on Sonoff Tasmota firmware: https://github.com/arendst/Sonoff-T
|
|||||||
|
|
||||||
# Example of zone configuration in piGarden.conf
|
# Example of zone configuration in piGarden.conf
|
||||||
|
|
||||||
|
```bash
|
||||||
EV1_ALIAS="Giardino_Posteriore_DX"
|
EV1_ALIAS="Giardino_Posteriore_DX"
|
||||||
EV1_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power1"
|
EV1_GPIO="drv:sonoff_tasmota_http:SONOFF1:Power1"
|
||||||
EV1_MONOSTABLE=1
|
EV1_MONOSTABLE=1
|
||||||
@@ -16,6 +17,6 @@ EV2_MONOSTABLE=1
|
|||||||
SONOFF1_IP="192.168.1.1"
|
SONOFF1_IP="192.168.1.1"
|
||||||
SONOFF1_USER="user"
|
SONOFF1_USER="user"
|
||||||
SONOFF1_PWD="pwd"
|
SONOFF1_PWD="pwd"
|
||||||
|
```
|
||||||
More information for configuration: https://www.lejubila.net/2018/06/pigarden-0-5-7-gestisci-le-tue-elettrovalvole-con-i-moduli-sonoff-grazie-al-nuovo-driver-sonoff_tasmota_http
|
More information for configuration: https://www.lejubila.net/2018/06/pigarden-0-5-7-gestisci-le-tue-elettrovalvole-con-i-moduli-sonoff-grazie-al-nuovo-driver-sonoff_tasmota_http
|
||||||
|
|
||||||
|
|||||||
1
mqttconnector/.gitignore
vendored
Normal file
1
mqttconnector/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
piGardenMqttconnector.ini
|
||||||
2
mqttconnector/exec_command.sh
Executable file
2
mqttconnector/exec_command.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
echo -e "$1" | ../piGarden.sh socket_server_command
|
||||||
88
mqttconnector/mqttconnector.py
Normal file
88
mqttconnector/mqttconnector.py
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#
|
||||||
|
# Installare libreria paho-mqtt, configparser:
|
||||||
|
# sudo pip install paho-mqtt configparser
|
||||||
|
#
|
||||||
|
|
||||||
|
import paho.mqtt.client as mqttClient
|
||||||
|
import time
|
||||||
|
import subprocess
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
def on_connect(client, userdata, flags, rc):
|
||||||
|
|
||||||
|
if rc == 0:
|
||||||
|
|
||||||
|
print("Connected to broker")
|
||||||
|
|
||||||
|
global Connected # Use global variable
|
||||||
|
Connected = True # Signal connection
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
print("Connection failed")
|
||||||
|
|
||||||
|
def on_message(client, userdata, message):
|
||||||
|
print "Topic : " + message.topic
|
||||||
|
print "Message received: " + message.payload
|
||||||
|
if message.topic.startswith("pigarden/command/"):
|
||||||
|
print "pigarden command: " + message.payload
|
||||||
|
cmd = ""
|
||||||
|
cmd = message.payload
|
||||||
|
if pigarden_user != "" and pigarden_pwd != "":
|
||||||
|
cmd = pigarden_user + '\n' + pigarden_pwd + '\n' + cmd
|
||||||
|
|
||||||
|
p = subprocess.Popen([ pigarden_path + "mqttconnector/exec_command.sh", cmd ], stdout=subprocess.PIPE)
|
||||||
|
(output, err) = p.communicate()
|
||||||
|
|
||||||
|
## Wait for date to terminate. Get return returncode ##
|
||||||
|
p_status = p.wait()
|
||||||
|
print "Command : '" + cmd + "'"
|
||||||
|
print "Command output : ", output
|
||||||
|
print "Command exit status/return code : ", p_status
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read('/etc/piGardenMqttconnector.ini')
|
||||||
|
|
||||||
|
|
||||||
|
Connected = False # global variable for the state of the connection
|
||||||
|
|
||||||
|
broker_address = config['mqtt']['broker_address']
|
||||||
|
port = int(config['mqtt']['port'])
|
||||||
|
user = config['mqtt']['user']
|
||||||
|
password = config['mqtt']['password']
|
||||||
|
client_id = config['mqtt']['client_id']
|
||||||
|
|
||||||
|
pigarden_path = config['pigarden']['path']
|
||||||
|
pigarden_user = config['pigarden']['user']
|
||||||
|
pigarden_pwd = config['pigarden']['pwd']
|
||||||
|
|
||||||
|
client = mqttClient.Client(client_id) # create new instance
|
||||||
|
client.username_pw_set(user, password=password) # set username and password
|
||||||
|
client.on_connect = on_connect # attach function to callback
|
||||||
|
client.on_message = on_message # attach function to callback
|
||||||
|
|
||||||
|
print broker_address, port, user, password
|
||||||
|
|
||||||
|
client.connect(broker_address, port=port) # connect to broker
|
||||||
|
|
||||||
|
client.loop_start() #start the loop
|
||||||
|
|
||||||
|
while Connected != True: #Wait for connection
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
client.subscribe("pigarden/command/+")
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print "exiting"
|
||||||
|
client.disconnect()
|
||||||
|
client.loop_stop()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
12
mqttconnector/piGardenMqttconnector.ini.example
Normal file
12
mqttconnector/piGardenMqttconnector.ini.example
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[mqtt]
|
||||||
|
broker_address=m20.cloudmqtt.com
|
||||||
|
port=13554
|
||||||
|
user=ucorgnpg
|
||||||
|
password=K5iJrLxNnhbM
|
||||||
|
client_id=Python
|
||||||
|
|
||||||
|
[pigarden]
|
||||||
|
path=/home/pi/piGarden/
|
||||||
|
user=a
|
||||||
|
pwd=b
|
||||||
|
|
||||||
Reference in New Issue
Block a user