def alarmsniffer(): alarm_codes_ein = ['1361', '4433', '5201', '5393'] alarm_codes_aus = ['1364', '4436', '5204', '5396'] receiver = RCSwitchReceiver() receiver.enableReceive(2) while True: if receiver.available(): received_value = receiver.getReceivedValue() if (received_value): if any(str(received_value) in s for s in alarm_codes_ein): alarm('EIN') subprocess.call("sh monitor_on.sh &> /dev/null", shell=True) if any(str(received_value) in s for s in alarm_codes_aus): alarm('AUS') receiver.resetAvailable() time.sleep(.5)
class RCSwitch(Switch): def __init__(self, triggervalue, shutdownvalue, exitvalue): self.receiver = RCSwitchReceiver() self.receiver.enableReceive(2) self.triggervalue = triggervalue self.shutdownvalue = shutdownvalue self.exitvalue = exitvalue def get_switch_state(self): if self.receiver.available(): value = self.receiver.getReceivedValue() self.receiver.resetAvailable() return { self.triggervalue: SwitchState.TRIGGER, self.shutdownvalue: SwitchState.SHUTDOWN, self.exitvalue: SwitchState.EXIT }.get(value, SwitchState.NONE) return SwitchState.NONE
class Transmitter: def __init__(self): self.sender = pi_switch.RCSwitchSender() self.sender.enableTransmit(0) self.receiver = RCSwitchReceiver() self.receiver.enableReceive(2) def sendRelayStatus(self, sid, relay_status): code = str(sid) + "000" + "00" + str(relay_status) code_encoded = int(code) self.sender.sendDecimal(code_encoded, 24) def updateRelayStatusWC(self, sid, relay_status): if relay_status != 1 and relay_status != 2: print("Error: wrong relay status on sending") sys.exit() self.sendRelayStatus(sid, relay_status)
def run_receiver(): """ Setup the Raspberry Pi as receiver, listen for transmitted values, display every received number as binary < 256 if the display is attached. Prints the received value, bit length and protocol to the terminal. """ receiver = RCSwitchReceiver() receiver.enableReceive(2) while True: print 'Listening...' sleep(0.5) if receiver.available(): received_value = receiver.getReceivedValue() if received_value: display_number(received_value % 256, True) print("Value: %s | Bit: %s | Protocol: %s" % (received_value, receiver.getReceivedBitlength(), receiver.getReceivedProtocol())) receiver.resetAvailable()
class Receiver433Manager(threading.Thread): def __init__(self, shared_queue): super(Receiver433Manager, self).__init__() # shared queue to send data (received UID)to the main thread self.shared_queue = shared_queue # init the lib self.receiver = RCSwitchReceiver() # WiringPi 2 = RPI pin 13 = GPIO 27 self.receiver.enableReceive(2) # this is used to stop the arming thread self.stop_event = threading.Event() def run(self): print "Starting receiver 433" while not self.stop_event.is_set(): if self.receiver.available(): received_value = self.receiver.getReceivedValue() if received_value: print "Receiver 433; Received id: %s" % received_value # send the value to the main thread if self.shared_queue is not None: self.shared_queue.put(received_value) # wait before listen again time.sleep(1) self.receiver.resetAvailable() # take a breath time.sleep(0.1) def stop(self): """ Stop the thread :return: """ self.stop_event.set() self.receiver.resetAvailable()
from pi_switch import RCSwitchReceiver from Config import Config #---------------------------------------------------------------------------# # Configure receiver #---------------------------------------------------------------------------# receiver = RCSwitchReceiver() receiver.enableReceive(Config.RPi_Pin_Receiver) num = 0 #---------------------------------------------------------------------------# # Loop and wait for commands #---------------------------------------------------------------------------# while True: if receiver.available(): received_value = receiver.getReceivedValue() if received_value: num += 1 print("Received[%s]:" % num) print(received_value) print("%s / %s bit" % (received_value, receiver.getReceivedBitlength())) print("Protocol: %s" % receiver.getReceivedProtocol()) print("") receiver.resetAvailable()
# Uses pi_switch from https://github.com/lexruee/pi-switch-python # See pi_switch readme for details on setup from pi_switch import RCSwitchReceiver import time receiver = RCSwitchReceiver() receiver.enableReceive(2) acceptedTypes = {1: "Light", 2: "Temp [C]", 3: "Humidity [%]"} prev_value = 0L while True: if receiver.available(): value = receiver.getReceivedValue() if value == prev_value: # we have already seen this measurement, so ignore it continue # decode byte3 byte3 = (0xFF000000 & value) >> 24 typeID = int((0xF0 & byte3) >> 4) seqNum = int((0x0F & byte3)) # decode byte2 and byte1 data = int((0x00FFFF00 & value) >> 8) # decode byte0 checkSum = int((0x000000FF & value)) calculatedCheckSum = 0xFF & (typeID + seqNum + data)
from pi_switch import RCSwitchReceiver import paho.mqtt.client as mqtt import json import time receiver = RCSwitchReceiver() receiver.enableReceive(2) num = 0 prevTemp=0 prevHum=0 def onConnect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) mqttClient = mqtt.Client("c3") mqttClient.on_connect = onConnect #mqttClient.connect("54.187.15.61",1883) mqttClient.connect("54.67.96.20",1883) message={} while True: if receiver.available(): received_value = receiver.getReceivedValue()
lista_valores[9].sensor_desc = ' hum09' lista_valores[10].sensor_desc = 'temp10' lista_valores[11].sensor_desc = ' hum11' lista_valores[12].sensor_desc = ' bat12' lista_valores[13].sensor_desc = 'temp13' lista_valores[14].sensor_desc = ' hum14' lista_valores[15].sensor_desc = 'pres15' lista_valores[16].sensor_desc = 'P_Te16' lista_valores[17].sensor_desc = 'void' lista_valores[18].sensor_desc = 'void' print lista_valores[1].sensor_desc # inicializamos RCSwitch receiver = RCSwitchReceiver() receiver.enableReceive(0) procesa_valor(14003540) imprime_lista() while True: print dt.now() # procesa_valor(14003540) if receiver.available(): received_value = receiver.getReceivedValue() if received_value: print("Value: %s | Bit: %s | Protocol: %s" % (received_value, receiver.getReceivedBitlength(), receiver.getReceivedProtocol())) procesa_valor(received_value) receiver.resetAvailable() sleep(10)
level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S', format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', ) parser = argparse.ArgumentParser( description='Listens for rf codes via a 433/315MHz GPIO device') parser.add_argument('-g', dest='gpio', type=int, default=2, help="GPIO pin according to WiringPi pinout (Default: 17)") args = parser.parse_args() receiver = RCSwitchReceiver() receiver.enableReceive(args.gpio) num = 0 while True: if receiver.available(): received_value = receiver.getReceivedValue() if received_value: num += 1 print("Received[%s]:" % num) print(received_value) print("%s / %s bit" % (received_value, receiver.getReceivedBitlength())) print("Protocol: %s" % receiver.getReceivedProtocol()) print("")