LED-Color: blue
mosquitto_pub -d -h localhost -p 1883 -t "yang/config" -m '{ "device":{ "description": "MQTT-Device identified by UUID", "uuid":{ "type": "string", "value": "F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD" }, "device-category":{ "description": "Identifies the device category", "type": "string", "value":"L-LAMP" } }, "rpc": { "set_color_blue": { "description": "RPC call that sets the LED Color to blue", "mqtt-command": "BLUE", "input": { "uuid": { "description": "Sends request to device specified by uuid", "type": "string" } } }, "switch_off": { "description": "Switches the LIFX-Led off", "mqtt-command": "OFF" } } }'
{
"device":{
"description":"MQTT-Device identified by UUID",
"uuid":{
"type":"string",
"value":"F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD"
},
"device-category":{
"description":"Identifies the device category",
"type":"string",
"value":"L-LAMP"
}
},
"rpc":{
"set_color_blue":{
"description":"RPC call that sets the LED Color to blue",
"mqtt-command":"BLUE",
"input":{
"uuid":{
"description":"Sends request to device specified by uuid",
"type":"string"
}
}
},
"switch_off":{
"description":"Switches the LIFX-Led off",
"mqtt-command":"OFF"
}
}
}
LED-Color: green
mosquitto_pub -d -h localhost -p 1883 -t "yang/config" -m '{ "device":{ "description": "MQTT-Device identified by UUID", "uuid":{ "type": "string", "value": "F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD" }, "device-category":{ "description": "Identifies the device category", "type": "string", "value":"L-LAMP" } }, "rpc": { "set_color_green": { "description": "RPC call that sets the LED Color to green", "mqtt-command": "GREEN", "input": { "uuid": { "description": "Sends request to device specified by uuid", "type": "string" } } }, "switch_off": { "description": "Switches the LIFX-Led off", "mqtt-command": "OFF" } } }'
{
"device":{
"description":"MQTT-Device identified by UUID",
"uuid":{
"type":"string",
"value":"F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD"
},
"device-category":{
"description":"Identifies the device category",
"type":"string",
"value":"L-LAMP"
}
},
"rpc":{
"set_color_green":{
"description":"RPC call that sets the LED Color to green",
"mqtt-command":"GREEN",
"input":{
"uuid":{
"description":"Sends request to device specified by uuid",
"type":"string"
}
}
},
"switch_off":{
"description":"Switches the LIFX-Led off",
"mqtt-command":"OFF"
}
}
}
LED-Color: green + blue
mosquitto_pub -d -h localhost -p 1883 -t "yang/config" -m '{ "device":{ "description": "MQTT-Device identified by UUID", "uuid":{ "type": "string", "value": "F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD" }, "device-category":{ "description": "Identifies the device category", "type": "string", "value":"L-LAMP" } }, "rpc": { "set_color_blue": { "description": "RPC call that sets the LED Color to blue", "mqtt-command": "BLUE", "input": { "uuid": { "description": "Sends request to device specified by uuid", "type": "string" } } }, "set_color_green": { "description": "RPC call that sets the LED Color to green", "mqtt-command": "GREEN", "input": { "uuid": { "description": "Sends request to device specified by uuid", "type": "string" } } }, "switch_off": { "description": "Switches the LIFX-Led off", "mqtt-command": "OFF" } } }'
{
"device":{
"description":"MQTT-Device identified by UUID",
"uuid":{
"type":"string",
"value":"F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD"
},
"device-category":{
"description":"Identifies the device category",
"type":"string",
"value":"L-LAMP"
}
},
"rpc":{
"set_color_blue":{
"description":"RPC call that sets the LED Color to blue",
"mqtt-command":"BLUE",
"input":{
"uuid":{
"description":"Sends request to device specified by uuid",
"type":"string"
}
}
},
"set_color_green":{
"description":"RPC call that sets the LED Color to green",
"mqtt-command":"GREEN",
"input":{
"uuid":{
"description":"Sends request to device specified by uuid",
"type":"string"
}
}
},
"switch_off":{
"description":"Switches the LIFX-Led off",
"mqtt-command":"OFF"
}
}
}
m = manager.connect_ssh("localhost", port=44555, username="Thomas", password="admin",allow_agent=False,hostkey_verify=False,look_for_keys=False) n = xml_.to_ele('<get-schema/>') m.dispatch(n)
n = xml_.to_ele('<get/>') n = xml_.to_ele('<set_color_blue><uuid>12345</uuid></set_color_blue>') n = xml_.to_ele('<set_color_green><uuid>12345</uuid></set_color_green>') n = xml_.to_ele('<switch_off><uuid>1fff</uuid></switch_off>')
ACHTUNG: Server stürzt ab, wenn kein UUID tag angegeben wird.
Setup in iTerm: (cd /Users/Thomas/LIFX/demo):
mqtt/LIFX bridge (./mqtt)mqtt_publisher (send json)mqtt_subscriber (mosquitto_sub -d -h localhost -p 1883 -t „#“)/usr/local/sbin/mosquitto -c ./mqtt.confVirtenv starten:
source python-virtenv/bin/activate
NETCONF/MQTT bridge:
python -i netconf_Server.py # Achtung: MQTT Broker muss vorher gestartet sein!
ncclient:
from ncclient import manager from ncclient import xml_
for capability in m.server_capabilities: ... print(capability)
m = manager.connect_ssh('ios-xe-mgmt.cisco.com', port=10000, username="root", password='C!sc0123',allow_agent=False,hostkey_verify=False,look_for_keys=False)