def __init__(self, uid, switch_id, ip, connection, logging_daemon, queue): self.bricklet = RemoteSwitch(uid, connection) self.uid = uid self.switch_id = switch_id self.ip = ip self._logging_daemon = logging_daemon self._queue = queue self._logging_daemon.debug( 'Tinkerforge ... Remote-Bricklet "%s" initialisiert' % uid)
def __init__(self, uid, switch_id, ip, connection, logging_daemon, queue): self.bricklet = RemoteSwitch(uid, connection) self.uid = uid self.switch_id = switch_id self.ip = ip self._logging_daemon = logging_daemon self._queue = queue self._logging_daemon.debug('Tinkerforge ... Remote-Bricklet "%s" initialisiert' % uid)
class BrickletRemote: def __init__(self, uid, switch_id, ip, connection, logging_daemon, queue): self.bricklet = RemoteSwitch(uid, connection) self.uid = uid self.switch_id = switch_id self.ip = ip self._logging_daemon = logging_daemon self._queue = queue self._logging_daemon.debug( 'Tinkerforge ... Remote-Bricklet "%s" initialisiert' % uid) @staticmethod def status(number): return -99 def set_switch(self, switch_to, arg_a, arg_b, arg_c, arg_d): self.bricklet.set_repeats(5) func = { "b switch": self.bricklet.switch_socket_b, "a switch": self.bricklet.switch_socket_a, }.get(arg_b) if func is not None: func(int(arg_c), int(arg_d), switch_to) self._logging_daemon.debug( 'Tinkerforge ... RemoteSwitch-Bricklet UID "%s" , geschaltet %s %s %s, SOLL = %s , ' % (self.uid, arg_b, arg_c, arg_d, switch_to)) tmp_json = json.dumps({ "usage": "switch_changed_status", "ip": self.ip, "id": self.switch_id, "value": switch_to }) for consumer in self._queue: consumer(tmp_json) self._logging_daemon.info( 'Tinkerforge ... RemoteSwitch-Bricklet UID "%s" Relais %s %s %s, send %s -> SocketServer' ' Warteschlange ' % (self.uid, arg_b, arg_c, arg_d, switch_to))
class BrickletRemote: def __init__(self, uid, switch_id, ip, connection, logging_daemon, queue): self.bricklet = RemoteSwitch(uid, connection) self.uid = uid self.switch_id = switch_id self.ip = ip self._logging_daemon = logging_daemon self._queue = queue self._logging_daemon.debug('Tinkerforge ... Remote-Bricklet "%s" initialisiert' % uid) @staticmethod def status(number): return -99 def set_switch(self, switch_to, arg_a, arg_b, arg_c, arg_d): self.bricklet.set_repeats(5) func = { "b switch" : self.bricklet.switch_socket_b, "a switch" : self.bricklet.switch_socket_a, }.get(arg_b) if func is not None: func(int(arg_c), int(arg_d), switch_to) self._logging_daemon.debug( 'Tinkerforge ... RemoteSwitch-Bricklet UID "%s" , geschaltet %s %s %s, SOLL = %s , ' % (self.uid, arg_b, arg_c, arg_d, switch_to)) tmp_json = json.dumps({ "usage": "switch_changed_status", "ip": self.ip, "id": self.switch_id, "value": switch_to }) for consumer in self._queue: consumer(tmp_json) self._logging_daemon.info( 'Tinkerforge ... RemoteSwitch-Bricklet UID "%s" Relais %s %s %s, send %s -> SocketServer' ' Warteschlange ' % (self.uid, arg_b, arg_c, arg_d, switch_to))
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change to your UID from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_remote_switch import RemoteSwitch if __name__ == "__main__": ipcon = IPConnection() # Create IP connection rs = RemoteSwitch(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Switch on a type A socket with house code 17 and receiver code 1. # House code 17 is 10001 in binary (least-significant bit first) # and means that the DIP switches 1 and 5 are on and 2-4 are off. # Receiver code 1 is 10000 in binary (least-significant bit first) # and means that the DIP switch A is on and B-E are off. rs.switch_socket_a(17, 1, RemoteSwitch.SWITCH_TO_ON) raw_input('Press key to exit\n') # Use input() in Python 3