def mqtt_init(): config = { 'HOST': 'localhost', 'DEVICE_ID': 'beeper', 'DEVICE_NAME': 'Beeper', 'TOPIC': 'homie' } device = homie.Device(config) node_beeper = device.addNode('beeper', 'Beeper', 'beeper') property_sequence = node_beeper.addProperty('sequence', 'Sequence', datatype='string') property_sequence.settable(sequence_handler) device.setFirmware('python', '1.0') device.setup()
def handle_device_discovery(self, ble_device, connection_manager): device = homie.Device({ # 'HOST': 'home', 'HOST': '192.168.1.1', 'DEVICE_ID': 'ble-' + ble_device['address'].replace(':', '').lower(), 'DEVICE_NAME': ble_device['name'] if ble_device['name'] is not None else 'BLE ' + ble_device['address'], 'TOPIC': 'homie_ble', 'QOS': 0 }) for serviceUUID in ble_device['services']: service = ble_device['services'][serviceUUID] uuid = service['service'].uuid common_name = 'Service ' + serviceUUID if uuid.commonName is not None: common_name = uuid.commonName node = device.addNode(serviceUUID, common_name, 'service') for characteristic_uuid in service['characteristics']: characteristic = service['characteristics'][ characteristic_uuid] uuid = characteristic.uuid common_name = 'Characteristic ' + characteristic_uuid if uuid.commonName is not None: common_name = uuid.commonName property = node.addProperty(characteristic_uuid, common_name, None, None, None) def handle_publish(char): def handle(p, value): value_bytes = bytearray.fromhex(value) connection_manager.write_value(ble_device, char, value_bytes) return handle property.settable(handle_publish(characteristic)) device.setup()
logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) config = { "HOST": "OpenHABianPI", "PORT": 1883, "KEEPALIVE": 10, "USERNAME": "", "PASSWORD": "", "CA_CERTS": "", "DEVICE_ID": "boatlift", "DEVICE_NAME": "Boat Lift", "TOPIC": "homie" } device = homie.Device(config) switchNode = device.addNode("switch", "switch", "switch") switchProperty = switchNode.addProperty("on") def switchOnHandler(property, value): if value == 'true': logger.info("Switch: ON") property.update("true") else: logger.info("Switch: OFF") property.update("false") def main(): device.setFirmware("relay-switch", "1.0.0")
from dy01 import DY01 from dy05 import DY05 from dy08 import DY08 logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) with open("solight_config.json") as config_file: config = json.load(config_file) pi = pigpio.pi() dy01 = DY01(pi, config["transmitter_pin"]) dy05 = DY05(pi, config["transmitter_pin"], 0.5) dy08 = DY08(pi, config["transmitter_pin"]) communicator = homie.Device(config["homie"]) communicator.setFirmware("SolightSockets", "1.0.0") id_counter = 0 def newNodeId(): global id_counter nodeId = "socket%d" % id_counter id_counter += 1 return nodeId def create_dy01_handler(name, sock): def handle_command(property, payload): logger.debug("Received message: '%s' for %s" % (payload, name)) if payload == "true":
def __init__(self, wallet, region, benchmarks, devices, name, oc_strat, oc_file, switching_threshold, run_excavator, ipc_port, autostart, db, mqtt_host, mqtt_name): self.wallet = wallet self.region = region self.benchmarks = benchmarks self.devices = devices self.name = name self.oc_file = oc_file self.switching_threshold = switching_threshold self.run_excavator = run_excavator self.ipc_port = ipc_port self.db = db self.state = Driver.State.INIT self.device_monitor = nvidia_smi.Monitor(data=["xidEvent", "temp"]) self.excavator_proc = None self.ipc = None # Mqtt self.mqtt_host = mqtt_host self.mqtt_name = mqtt_name # Mqtt homie self.homie = None if self.mqtt_host: homie_config = { "HOST": mqtt_host, "PORT": 1883, "KEEPALIVE": 60, "USERNAME": "", "PASSWORD": "", "CA_CERTS": "", "DEVICE_NAME": mqtt_name, "DEVICE_ID": mqtt_name, "TOPIC": "homie" } self.homie = homie.Device(homie_config) self.homie_cooling = self.homie.addNode("cooing", "Cooling system", "temperature") self.homie_mining = self.homie.addNode("mining", "Mining system", "stats") self.homie_devices = {} # dict of device id -> overclocking device object self.devices_oc = {} # dict of device id -> settings self.device_settings = {} self.paying_current = None for d in self.devices: dev = Driver.DeviceSettings() dev.id = d dev.enabled = autostart dev.oc_strategy = oc_strat self.device_settings[d] = dev self.excavator = excavator_api.ExcavatorApi() self.oc_config = None for d in devices: self.devices_oc[d] = overclock.Device(d) self.devices_oc[d].refresh()