Пример #1
0
        //------------------------------------------------------------------------------------------------------------------------
        private void InitYodiwoConnection()
        {
            //create node configuration
            NodeConfig conf = new NodeConfig()
            {
                Name           = "Azure Clone of " + ActiveCfg.AzureInfo.AzureDeviceName,
                YpServer       = ActiveCfg.YodiwoInfo.YodiwoApiServer,
                YpchannelPort  = Convert.ToInt32(ActiveCfg.YodiwoInfo.YPChannelPort),
                FrontendServer = ActiveCfg.YodiwoInfo.YodiwoRestUrl,
                CanSolveGraphs = false,
                SecureYpc      = ActiveCfg.YodiwoInfo.SecureYPC,
            };
            //prepare node graphmanager module
            var nodeGraphManager = new Yodiwo.NodeLibrary.Graphs.NodeGraphManager(
                new Type[]
            {
                typeof(Yodiwo.Logic.BlockLibrary.Basic.Librarian)
            });

            //create the proxy node
            proxyNode = new Yodiwo.NodeLibrary.Node(conf, Things, null, null, null, NodeGraphManager: nodeGraphManager);
            //set transport
            proxyNode.Transport = Transport.YPCHANNEL;

            //register cbs
            proxyNode.OnChangedState          += OnChangedStateCb;
            proxyNode.OnTransportConnected    += OnTransportConnectedCb;
            proxyNode.OnTransportDisconnected += OnTransportDisconnectedCb;
            proxyNode.OnTransportError        += OnTransportErrorCb;
            proxyNode.OnUnexpectedMessage      = OnUnexpectedMessageCb;
            proxyNode.OnThingActivated        += OnThingActivatedCb;

            //use nodekey to setup things
            proxyNode.SetupNodeKeys(ActiveCfg.YodiwoInfo.YodiwoNodeKey, ActiveCfg.YodiwoInfo.YodiwoSecretKey);

            //connect
            proxyNode.Connect();
            RegisterThings();
        }
Пример #2
0
        //------------------------------------------------------------------------------------------------------------------------
        private void InitYodiwoConnection()
        {
            //create node configuration
            NodeConfig conf = new NodeConfig()
            {
                Name = "Clone of " + ActiveCfg.IBMInfo.IOTFDeviceName,
                YpServer = ActiveCfg.YodiwoInfo.YodiwoApiServer,
                YpchannelPort = Convert.ToInt32(ActiveCfg.YodiwoInfo.YPChannelPort),
                FrontendServer = ActiveCfg.YodiwoInfo.YodiwoRestUrl,
                CanSolveGraphs = false,
                SecureYpc = ActiveCfg.YodiwoInfo.SecureYPC
            };
            //prepare node graphmanager module
            var nodeGraphManager = new Yodiwo.NodeLibrary.Graphs.NodeGraphManager(
                                                new Type[]
                                                    {
                                                        typeof(Yodiwo.Logic.BlockLibrary.Basic.Librarian)
                                                    });
            //create the proxy node
            proxyNode = new Yodiwo.NodeLibrary.Node(conf, Things, null, null, null, NodeGraphManager: nodeGraphManager);
            //set transport
            proxyNode.Transport = Transport.YPCHANNEL;

            //register cbs
            proxyNode.OnChangedState += OnChangedStateCb;
            proxyNode.OnTransportConnected += OnTransportConnectedCb;
            proxyNode.OnTransportDisconnected += OnTransportDisconnectedCb;
            proxyNode.OnTransportError += OnTransportErrorCb;
            proxyNode.OnUnexpectedMessage = OnUnexpectedMessageCb;
            proxyNode.OnThingActivated += OnThingActivatedCb;

            //use nodekey to setup things
            proxyNode.SetupNodeKeys(ActiveCfg.YodiwoInfo.YodiwoNodeKey, ActiveCfg.YodiwoInfo.YodiwoSecretKey);

            //connect
            proxyNode.Connect();
            RegisterThingStateCbs();
        }
Пример #3
0
        public void Start()
        {
            YConfig = Config.Init();
            ActiveCfg = YConfig.GetActiveConf();

            NodeConfig conf = new NodeConfig()
            {
                uuid = ActiveCfg.Uuid,
                Name = "GrovePi Node",
                MqttBrokerHostname = ActiveCfg.MqttBrokerHostname,
                MqttUseSsl = ActiveCfg.MqttUseSsl,
                YpServer = ActiveCfg.ApiServer,
                YpchannelPort = ActiveCfg.YpchannelPort,
                SecureYpc = ActiveCfg.YpchannelSecure,
                FrontendServer = ActiveCfg.FrontendServer,
                CanSolveGraphs = ActiveCfg.CanSolveGraphs
            };

            //prepare pairing module
            var pairmodule = new Yodiwo.NodeLibrary.Pairing.NancyPairing.NancyPairing();

            //prepare node graph manager module
            var nodeGraphManager = new Yodiwo.NodeLibrary.Graphs.NodeGraphManager(
                                                new Type[]
                                                    {
                                                        typeof(Yodiwo.Logic.BlockLibrary.Basic.Librarian),
                                                        typeof(Yodiwo.Logic.BlockLibrary.Extended.Librarian),
                                                    });

            //create node
            node = new Yodiwo.NodeLibrary.Node(conf,
                                               pairmodule,
                                               null, null,
                                               NodeGraphManager: nodeGraphManager
                                               );
            Helper.node = node;
            //set TransPort
            node.Transport = transport;

            //register callbacks for grovepi node
            node.OnChangedState += OnChangedStateCb;
            node.OnNodePaired += OnPaired;
            node.OnTransportConnected += OnTransportConnectedCb;
            node.OnTransportDisconnected += OnTransportDisconnectedCb;
            node.OnTransportError += OnTransportErrorCb;
            node.OnUnexpectedMessage += OnUnexpectedMessageCb;
            node.OnPortActivated += OnPortActivatedCb;
            node.OnPortDeactivated += OnPortDeactivatedCb;
            node.OnThingUpdated += OnThingUpdated;

            //start Pairing
            if (String.IsNullOrWhiteSpace(ActiveCfg.NodeKey))
            {
                DebugEx.TraceLog("Starting pairing procedure.");
                var pair = node.StartPairing(ActiveCfg.FrontendServer, null, ActiveCfg.LocalWebServer).GetResults();
            }
            else
            {
                node.SetupNodeKeys(ActiveCfg.NodeKey, ActiveCfg.NodeSecret.ToSecureString());
                DebugEx.TraceLog("Node already paired: NodeKey = "
                    + ActiveCfg.NodeKey + ", NodeSecret = " + ActiveCfg.NodeSecret);
            }

            //add things
            Helper.CreateThings(this.pysharp, node);

            //register port event handlers
            RegisterThingsHandlers();

            //connect
            node.Connect();
        }
Пример #4
0
        public void Start()
        {
            #region Configurations

            this.YConfig = this.InitConfig();
            this.ActiveCfg = this.YConfig.GetActiveConf();
            NodeConfig conf = new NodeConfig()
            {
                uuid = ActiveCfg.Uuid,
                Name = "RaspberryNode",
                MqttBrokerHostname = ActiveCfg.MqttBrokerHostname,
                MqttUseSsl = ActiveCfg.MqttUseSsl,
                YpServer = ActiveCfg.ApiServer,
                YpchannelPort = ActiveCfg.YpchannelPort,
                SecureYpc = ActiveCfg.YpchannelSecure,
                FrontendServer = ActiveCfg.FrontendServer
            };

            #endregion

            #region Things setup

            #region Setup Led1 thing
            {
                var thing = Led1Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name = "Raspberry Led 1",
                    Config = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List<Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name = "LedState",
                        State = "0",
                        Type = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led1);
            }
            #endregion

            #region Setup Led2 thing
            {
                var thing = Led2Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name = "Raspberry Led 2",
                    Config = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List<Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name = "LedState",
                        State = "0",
                        Type = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led2);
            }
            #endregion

            #region Setup Led3 thing
            {
                var thing = Led3Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name = "Raspberry Led 3",
                    Config = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List<Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name = "LedState",
                        State = "0",
                        Type = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led3);
            }
            #endregion

            #region Setup Led4 thing
            {
                var thing = Led4Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name = "Raspberry Led 4",
                    Config = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List<Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name = "LedState",
                        State = "0",
                        Type = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led4);
            }
            #endregion

            #region Setup Led5 thing
            {
                var thing = Led5Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name = "Raspberry Led 5",
                    Config = null,
                    UIHints = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List<Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name = "LedState",
                        State = "0",
                        Type = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led5);
            }
            #endregion

            #endregion

            #region Node construction
            //prepare pairing module
            var pairmodule = new Yodiwo.Node.Pairing.NancyPairing.NancyPairing();
            //prepare node graph manager module
            var nodeGraphManager = new Yodiwo.NodeLibrary.Graphs.NodeGraphManager(
                                                new Type[]
                                                    {
                                                        typeof(Yodiwo.Logic.BlockLibrary.Basic.Librarian),
                                                        typeof(Yodiwo.Logic.BlockLibrary.Extended.Librarian),
                                                    });
            //create node
            Node = new Yodiwo.NodeLibrary.Node(conf,
                                                Things.Values.ToList(),
                                                pairmodule,
                                                null, null,
                                                NodeGraphManager: nodeGraphManager
                                                //MqttTransport: typeof(Yodiwo.NodeLibrary.Transports.MQTT)
                                                );

            #endregion

            #region Register port event handlers

            Node.PortEventHandlers[Led1Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led = PkeyToLed.TryGetOrDefault(Led1Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led2Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led = PkeyToLed.TryGetOrDefault(Led2Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led3Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led = PkeyToLed.TryGetOrDefault(Led3Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led4Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led = PkeyToLed.TryGetOrDefault(Led4Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led5Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led = PkeyToLed.TryGetOrDefault(Led5Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            #endregion

            #region Register callbacks

            Node.OnChangedState += OnChangedStateCb;
            Node.OnNodePaired += OnPairedCb;
            Node.OnTransportConnected += OnTransportConnectedCb;
            Node.OnTransportDisconnected += OnTransportDisconnectedCb;
            Node.OnTransportError += OnTransportErrorCb;
            Node.OnUnexpectedMessage = OnUnexpectedMessageCb;

            #endregion

            #region Pairing/Connect

            if (String.IsNullOrWhiteSpace(ActiveCfg.NodeKey))
            {
                DebugEx.TraceLog("Starting pairing procedure.");
                var task = Node.StartPairing(ActiveCfg.FrontendServer, null, ActiveCfg.LocalWebServer);
            }
            else
            {
                Node.SetupNodeKeys(ActiveCfg.NodeKey, ActiveCfg.NodeSecret);
                DebugEx.TraceLog("Node already paired: NodeKey = "
                    + ActiveCfg.NodeKey + ", NodeSecret = ", ActiveCfg.NodeSecret);

                Node.Connect();
            }

            #endregion
        }
Пример #5
0
        public void Start()
        {
            YConfig   = Config.Init();
            ActiveCfg = YConfig.GetActiveConf();

            NodeConfig conf = new NodeConfig()
            {
                uuid = ActiveCfg.Uuid,
                Name = "GrovePi Node",
                MqttBrokerHostname = ActiveCfg.MqttBrokerHostname,
                MqttUseSsl         = ActiveCfg.MqttUseSsl,
                YpServer           = ActiveCfg.ApiServer,
                YpchannelPort      = ActiveCfg.YpchannelPort,
                SecureYpc          = ActiveCfg.YpchannelSecure,
                FrontendServer     = ActiveCfg.FrontendServer,
                CanSolveGraphs     = ActiveCfg.CanSolveGraphs
            };

            //prepare pairing module
            var pairmodule = new Yodiwo.NodeLibrary.Pairing.NancyPairing.NancyPairing();

            //prepare node graph manager module
            var nodeGraphManager = new Yodiwo.NodeLibrary.Graphs.NodeGraphManager(
                new Type[]
            {
                typeof(Yodiwo.Logic.BlockLibrary.Basic.Librarian),
                typeof(Yodiwo.Logic.BlockLibrary.Extended.Librarian),
            });

            //create node
            node = new Yodiwo.NodeLibrary.Node(conf,
                                               pairmodule,
                                               null, null,
                                               NodeGraphManager: nodeGraphManager
                                               );
            Helper.node = node;
            //set TransPort
            node.Transport = transport;

            //register callbacks for grovepi node
            node.OnChangedState          += OnChangedStateCb;
            node.OnNodePaired            += OnPaired;
            node.OnTransportConnected    += OnTransportConnectedCb;
            node.OnTransportDisconnected += OnTransportDisconnectedCb;
            node.OnTransportError        += OnTransportErrorCb;
            node.OnUnexpectedMessage     += OnUnexpectedMessageCb;
            node.OnPortActivated         += OnPortActivatedCb;
            node.OnPortDeactivated       += OnPortDeactivatedCb;
            node.OnThingUpdated          += OnThingUpdated;

            //start Pairing
            if (String.IsNullOrWhiteSpace(ActiveCfg.NodeKey))
            {
                DebugEx.TraceLog("Starting pairing procedure.");
                var pair = node.StartPairing(ActiveCfg.FrontendServer, null, ActiveCfg.LocalWebServer).GetResults();
            }
            else
            {
                node.SetupNodeKeys(ActiveCfg.NodeKey, ActiveCfg.NodeSecret.ToSecureString());
                DebugEx.TraceLog("Node already paired: NodeKey = "
                                 + ActiveCfg.NodeKey + ", NodeSecret = " + ActiveCfg.NodeSecret);
            }

            //add things
            Helper.CreateThings(this.pysharp, node);

            //register port event handlers
            RegisterThingsHandlers();

            //connect
            node.Connect();
        }
Пример #6
0
        public void Start()
        {
            #region Configurations

            this.YConfig   = this.InitConfig();
            this.ActiveCfg = this.YConfig.GetActiveConf();
            NodeConfig conf = new NodeConfig()
            {
                uuid = ActiveCfg.Uuid,
                Name = "RaspberryNode",
                MqttBrokerHostname = ActiveCfg.MqttBrokerHostname,
                MqttUseSsl         = ActiveCfg.MqttUseSsl,
                YpServer           = ActiveCfg.ApiServer,
                YpchannelPort      = ActiveCfg.YpchannelPort,
                SecureYpc          = ActiveCfg.YpchannelSecure,
                FrontendServer     = ActiveCfg.FrontendServer
            };

            #endregion

            #region Things setup

            #region Setup Led1 thing
            {
                var thing = Led1Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type     = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name     = "Raspberry Led 1",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LedState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led1);
            }
            #endregion

            #region Setup Led2 thing
            {
                var thing = Led2Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type     = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name     = "Raspberry Led 2",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LedState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led2);
            }
            #endregion

            #region Setup Led3 thing
            {
                var thing = Led3Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type     = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name     = "Raspberry Led 3",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LedState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led3);
            }
            #endregion

            #region Setup Led4 thing
            {
                var thing = Led4Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type     = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name     = "Raspberry Led 4",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LedState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led4);
            }
            #endregion

            #region Setup Led5 thing
            {
                var thing = Led5Thing = new Yodiwo.API.Plegma.Thing()
                {
                    Type     = "yodiwo.input.leds.simple",
                    ThingKey = new ThingKey(NodeKey, GenerateThingID()),
                    Name     = "Raspberry Led 5",
                    Config   = null,
                    UIHints  = new ThingUIHints()
                    {
                        IconURI = "/Content/RaspberryNode/img/icon-thing-led.png",
                    },
                };
                thing.Ports = new List <Yodiwo.API.Plegma.Port>()
                {
                    new Yodiwo.API.Plegma.Port()
                    {
                        ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
                        Name        = "LedState",
                        State       = "0",
                        Type        = Yodiwo.API.Plegma.ePortType.Boolean,
                        PortKey     = PortKey.BuildFromArbitraryString("$ThingKey$", "0")
                    }
                };
                Things.Add(thing.ThingKey, thing);
                PkeyToLed.Add(thing.Ports[0].PortKey, LedPin.Led5);
            }
            #endregion

            #endregion

            #region Node construction
            //prepare pairing module
            var pairmodule = new Yodiwo.Node.Pairing.NancyPairing.NancyPairing();
            //prepare node graph manager module
            var nodeGraphManager = new Yodiwo.NodeLibrary.Graphs.NodeGraphManager(
                new Type[]
            {
                typeof(Yodiwo.Logic.BlockLibrary.Basic.Librarian),
                typeof(Yodiwo.Logic.BlockLibrary.Extended.Librarian),
            });
            //create node
            Node = new Yodiwo.NodeLibrary.Node(conf,
                                               Things.Values.ToList(),
                                               pairmodule,
                                               null, null,
                                               NodeGraphManager: nodeGraphManager
                                               //MqttTransport: typeof(Yodiwo.NodeLibrary.Transports.MQTT)
                                               );

            #endregion

            #region Register port event handlers

            Node.PortEventHandlers[Led1Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led      = PkeyToLed.TryGetOrDefault(Led1Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led2Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led      = PkeyToLed.TryGetOrDefault(Led2Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led3Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led      = PkeyToLed.TryGetOrDefault(Led3Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led4Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led      = PkeyToLed.TryGetOrDefault(Led4Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            Node.PortEventHandlers[Led5Thing.Ports[0]] = data =>
            {
                var ledState = data.ParseToBool();
                var led      = PkeyToLed.TryGetOrDefault(Led5Thing.Ports[0].PortKey, LedPin.Unknown);
                Console.WriteLine("==> Rx port event msg for led {0}", led);
                if (led != LedPin.Unknown)
                {
                    SetLedState(led, ledState);
                }
            };

            #endregion

            #region Register callbacks

            Node.OnChangedState          += OnChangedStateCb;
            Node.OnNodePaired            += OnPairedCb;
            Node.OnTransportConnected    += OnTransportConnectedCb;
            Node.OnTransportDisconnected += OnTransportDisconnectedCb;
            Node.OnTransportError        += OnTransportErrorCb;
            Node.OnUnexpectedMessage      = OnUnexpectedMessageCb;

            #endregion

            #region Pairing/Connect

            if (String.IsNullOrWhiteSpace(ActiveCfg.NodeKey))
            {
                DebugEx.TraceLog("Starting pairing procedure.");
                var task = Node.StartPairing(ActiveCfg.FrontendServer, null, ActiveCfg.LocalWebServer);
            }
            else
            {
                Node.SetupNodeKeys(ActiveCfg.NodeKey, ActiveCfg.NodeSecret);
                DebugEx.TraceLog("Node already paired: NodeKey = "
                                 + ActiveCfg.NodeKey + ", NodeSecret = ", ActiveCfg.NodeSecret);

                Node.Connect();
            }

            #endregion
        }