示例#1
0
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyRFXtrx is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pyRFXtrx.  See the file COPYING.txt in the distribution.
# If not, see <http://www.gnu.org/licenses/>.


NOT TESTED


from RFXtrx.pyserial import PySerialTransport
from RFXtrx import LightingDevice
from time import sleep

transport = PySerialTransport('/dev/cu.usbserial-05VN8GHS', debug=True)
transport.reset()

while True:
    event = transport.receive_blocking()
    if isinstance(event.device, LightingDevice):
        sleep(5)
        event.device.send_off(transport)
        ack = transport.receive_blocking()
示例#2
0
# This file is part of pyRFXtrx, a Python library to communicate with
# the RFXtrx family of devices from http://www.rfxcom.com/
# See https://github.com/woudt/pyRFXtrx for the latest version.
#
# Copyright (C) 2012  Edwin Woudt <*****@*****.**>
#
# pyRFXtrx is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyRFXtrx is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pyRFXtrx.  See the file COPYING.txt in the distribution.
# If not, see <http://www.gnu.org/licenses/>.

from RFXtrx.pyserial import PySerialTransport

transport = PySerialTransport('/dev/cu.usbserial-05VN8GHS', debug=True)
transport.reset()

while True:
    print(transport.receive_blocking())
		    device.send_on(transport)
		else:
		    device.send_dim(transport,value)
    except:
        print "Error when parsing incomming message."
    
    return 
    
def ControlLoop():
    # schedule the client loop to handle messages, etc.
    print "Starting MQTT listener"
    client.loop_forever()
    print "Closing connection to MQTT"
    time.sleep(1)

transport = PySerialTransport(PORT, debug=True)
#transport.reset()
client = mosquitto.Mosquitto("RFXcom-client")
client.username_pw_set("driver","1234")
client.will_set(topic = "system/RFXcom", payload="Offline", qos=1, retain=True)

#Connect and notify others of our presence. 
client.connect(MQTT_HOST, keepalive=10)
client.publish("system/" + PREFIX, "Online",1,True)
client.on_connect = on_connect
client.on_message = on_message

#Start tread...
#thread.start_new_thread(ControlLoop,())
client.loop_start()