Ejemplo n.º 1
0
def virtual(run_func):
    """Simulate coap resources in VirtualCopernicus"""
    new_configuration = configuration
    new_configuration['name'] = 'Bathroom'
    circuit = TkCircuit(new_configuration)

    @circuit.run
    def main():
        run_func()
Ejemplo n.º 2
0
def virtual():
    """Simulate coap resources in VirtualCopernicus"""
    circuit = TkCircuit(configuration)

    root = resource.Site()
    root.add_resource(['.well-known', 'core'],
                      resource.WKCResource(root.get_resources_as_linkheader))
    root.add_resource(['servo'], ServoResource(17))
    root.add_resource(['led1'], LEDResource(21))
    root.add_resource(['led2'], LEDResource(22))
    root.add_resource(['button1'],
                      ButtonResource(11, lambda: print("Button1 pressed")))
    root.add_resource(['button2'], ButtonResource(12))
    root.add_resource(['buzzer'], BuzzerResource(16))
    root.add_resource(['gpio_buzzer'], GPIOResource(15))

    @circuit.run
    def main():
        asyncio.set_event_loop(event_loop)
        asyncio.Task(
            Context.create_server_context(root, bind=(SERVER_IP, 5683)))
        event_loop.run_forever()
Ejemplo n.º 3
0
        {
            "x": 242,
            "y": 146,
            "name": "Button 1",
            "pin": 11
        },
        {
            "x": 200,
            "y": 217,
            "name": "Button 2",
            "pin": 12
        },
    ]
}

circuit = TkCircuit(configuration)


@circuit.run
def main():
    # now just write the code you would use on a real Raspberry Pi

    from gpiozero import LED, Button
    import paho.mqtt.client as mqtt

    def button1_pressed():
        print("button1 pressed!")
        mqttc.publish("smart_house/light/bathroom/1", "TOGGLE", 0, False)

    def button2_pressed():
        print("button2 pressed!")