-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from emoncms/master
Merge master to stable
- Loading branch information
Showing
8 changed files
with
816 additions
and
30 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"name" : "DemandShaper", | ||
"version" : "1.2.5" | ||
"version" : "1.2.6" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import time | ||
import paho.mqtt.client as mqtt | ||
|
||
device = "smartplug1272" | ||
mqtt_user = "emonpi" | ||
mqtt_passwd = "emonpimqtt2016" | ||
mqtt_host = "localhost" | ||
mqtt_port = 1883 | ||
|
||
basetopic = "emon" | ||
# basetopic = "user/"+str(userid) # multiuser | ||
|
||
ctrlmode = "off" | ||
timer = "0000 0000 0000 0000" | ||
|
||
def on_connect(client, userdata, flags, rc): | ||
# Initialisation string | ||
mqttc.subscribe(basetopic+"/"+device+"/in/#") | ||
pass | ||
|
||
def on_message(client, userdata, msg): | ||
global ctrlmode, timer | ||
|
||
print msg.topic+": "+msg.payload | ||
|
||
# Set control mode: On, Off, Timer | ||
if msg.topic==basetopic+"/"+device+"/in/ctrlmode": | ||
ctrlmode = msg.payload | ||
|
||
# Set timer: start1 stop1 start2 stop2 | ||
if msg.topic==basetopic+"/"+device+"/in/timer": | ||
ctrlmode = "Timer" | ||
timer = msg.payload | ||
|
||
# Fetch and return smartplug state | ||
if msg.topic==basetopic+"/"+device+"/in/state": | ||
value = '{"ip":"192.168.1.71","time":0,"ctrlmode":"'+ctrlmode+'","timer":"'+timer+'","vout":0}' | ||
print basetopic+"/"+device+"/out/state"+" "+value+"\n" | ||
mqttc.publish(basetopic+"/"+device+"/out/state",value,2) | ||
|
||
mqttc = mqtt.Client("smartplug-remote") | ||
mqttc.on_connect = on_connect | ||
mqttc.on_message = on_message | ||
|
||
# Connect | ||
try: | ||
mqttc.username_pw_set(mqtt_user, mqtt_passwd) | ||
mqttc.connect(mqtt_host, mqtt_port, 60) | ||
mqttc.loop_start() | ||
except Exception: | ||
print "Could not connect to MQTT" | ||
else: | ||
print "Connected to MQTT" | ||
|
||
time.sleep(1) | ||
|
||
# Loop | ||
while 1: | ||
# Sent a device parameter | ||
topic = basetopic+"/"+device+"/temperature" | ||
value = 18.5 | ||
mqttc.publish(topic,value,2) | ||
time.sleep(10) | ||
|
||
# Close | ||
mqttc.loop_stop() | ||
mqttc.disconnect() | ||
|