Пример #1
0
        public static YConfig <FlicPluginConfig> Init(string plugindir)
        {
            var cfgFile = Path.Combine(plugindir, "conf_file.json");
            var yconfig = new YConfig <FlicPluginConfig>(cfgFile);

            try
            {
                if (yconfig.Retrieve(PreProccessContent: cnt => cnt.Replace("$Role$", "Local")))
                {
                    DebugEx.TraceLog("Config file found: " + cfgFile);
                    return(yconfig);
                }
                DebugEx.TraceLog("Config retrieval failed; falling back to defaults");
            }
            catch (Exception ex) { DebugEx.TraceLog("Loading default configuration: " + ex.Message); }


            //create default conf
            FlicPluginConfig cfg = new FlicPluginConfig();

            cfg.PythonServer        = "http://localhost:8080/";
            cfg.restrouteremoveflic = "removeflic";
            //add new active conf and save to disk
            yconfig.AddActiveConf("Default", cfg);
            yconfig.Save();

            return(yconfig);
        }
Пример #2
0
        //------------------------------------------------------------------------------------------------------------------------
        public static YConfig <ZwavePluginConfig> Init(string plugindir)
        {
            var cfgFile = Path.Combine(plugindir, "conf_file.json");
            var yconfig = new YConfig <ZwavePluginConfig>(cfgFile);

            try
            {
                if (yconfig.Retrieve(PreProccessContent: cnt => cnt.Replace("$Role$", "Local")))
                {
                    DebugEx.TraceLog("Config file found: " + cfgFile);
                    return(yconfig);
                }
                DebugEx.TraceLog("Config retrieval failed; falling back to defaults");
            }
            catch (Exception ex) { DebugEx.TraceLog("Loading default configuration: " + ex.Message); }

            //create default conf
            ZwavePluginConfig cfg = new ZwavePluginConfig();

            cfg.SerialPort         = "/dev/ttyAMA0";
            cfg.OpenZWaveDirectory = "/home/pi/open-zwave1/";
            //add new active conf and save to disk
            yconfig.AddActiveConf("Default", cfg);
            yconfig.Save();

            return(yconfig);
        }
Пример #3
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //------------------------------------------------------------------------------------------------------------------------
        public override bool Initialize(mNodeConfig mNodeConfig, string PluginConfig, string UserConfig)
        {
            YConfig   = Config.Init(PluginWorkingDirectory);
            ActiveCfg = YConfig.GetActiveConf();

            //init base
            if (base.Initialize(mNodeConfig, PluginConfig, UserConfig) == false)
            {
                return(false);
            }

            //init
            try
            {
                DebugEx.TraceLog("FLIC: InitFlicClient from flic plugin initialize");
                //init plugin
                _InitFlicClient();
            }
            catch (Exception ex) { DebugEx.Assert(ex, "Could not init"); }
            //done
            return(true);
        }
Пример #4
0
        public static YConfig <GrovePiNodeConfig> Init()
        {
            var cfgFile = "conf_file.json";

            var yconfig = new YConfig <GrovePiNodeConfig>(cfgFile);

            try
            {
                if (yconfig.Retrieve())
                {
                    Console.WriteLine("Config file found: " + cfgFile);
                    return(yconfig);
                }
                Console.WriteLine("Config retrieval failed; falling back to defaults");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Loading default configuration");
            }

            //create default conf
            GrovePiNodeConfig cfg = new GrovePiNodeConfig();

            cfg.FrontendServer     = "https://localhost:3334";
            cfg.ApiServer          = "localhost";
            cfg.LocalWebServer     = "http://localhost:4040";
            cfg.Uuid               = "1337GrovePi";
            cfg.MqttBrokerHostname = "localhost";
            cfg.YpchannelPort      = Yodiwo.API.Plegma.Constants.YPChannelPort;
            cfg.MqttUseSsl         = false;
            cfg.YpchannelSecure    = false;

            //add new active conf and save to disk
            yconfig.AddActiveConf("LocalGrovePi", cfg);
            yconfig.Save();

            return(yconfig);
        }
Пример #5
0
        public YConfig <RaspNodeConfig> InitConfig()
        {
            var absoluteCfgFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/" + this.cfgFile;

            var yconfig = new YConfig <RaspNodeConfig>(absoluteCfgFile);

            try
            {
                if (yconfig.Retrieve())
                {
                    Console.WriteLine("Config file found: {0}", absoluteCfgFile);
                    return(yconfig);
                }
                Console.WriteLine("Config retrieval failed; falling back to defaults");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Loading default configuration");
            }

            //create default conf
            RaspNodeConfig cfg = new RaspNodeConfig();

            cfg.FrontendServer     = "https://cyan.yodiwo.com";
            cfg.ApiServer          = "api.yodiwo.com";
            cfg.LocalWebServer     = "http://localhost:3339";
            cfg.Uuid               = "1337Raspberry";
            cfg.MqttBrokerHostname = "api.yodiwo.com";
            cfg.YpchannelPort      = Yodiwo.API.Plegma.Constants.YPChannelPort;
            cfg.MqttUseSsl         = false;
            cfg.YpchannelSecure    = false;

            //add new active conf and save to disk
            yconfig.AddActiveConf("default", cfg);
            yconfig.Save();

            return(yconfig);
        }
Пример #6
0
        public static YConfig<SkyWriterNodeConfig> Init()
        {
            var cfgFile = "conf_file.json";

            var yconfig = new YConfig<SkyWriterNodeConfig>(cfgFile);

            try
            {
                if (yconfig.Retrieve())
                {
                    Console.WriteLine("Config file found: " + cfgFile);
                    return yconfig;
                }
                Console.WriteLine("Config retrieval failed; falling back to defaults");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Loading default configuration");
            }

            //create default conf
            SkyWriterNodeConfig cfg = new SkyWriterNodeConfig();
            cfg.FrontendServer = "https://localhost:3334";
            cfg.ApiServer = "localhost";
            cfg.LocalWebServer = "http://localhost:4050";
            cfg.Uuid = "1337SkyWriter";
            cfg.MqttBrokerHostname = "localhost";
            cfg.YpchannelPort = Yodiwo.API.Plegma.Constants.YPChannelPort;
            cfg.MqttUseSsl = false;
            cfg.YpchannelSecure = false;

            //add new active conf and save to disk
            yconfig.AddActiveConf("LocalSkyWriter", cfg);
            yconfig.Save();

            return yconfig;
        }
Пример #7
0
        public YConfig <RaspPiGpioNodeConfig> InitConfig()
        {
            var absoluteCfgFile = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/" + this.cfgFile;

            var yconfig = new YConfig <RaspPiGpioNodeConfig>(absoluteCfgFile);

            try
            {
                if (yconfig.Retrieve())
                {
                    Console.WriteLine("Config file found: {0}", absoluteCfgFile);
                    return(yconfig);
                }
                Console.WriteLine("Config retrieval failed; falling back to defaults");
            }
            catch
            {
                Console.WriteLine("Loading default configuration");
            }

            //create default conf
            RaspPiGpioNodeConfig cfg = new RaspPiGpioNodeConfig();

            cfg.FrontendServer  = "https://tcyan.yodiwo.com";
            cfg.ApiServer       = "api.yodiwo.com";
            cfg.LocalWebServer  = "http://localhost:3339";
            cfg.Uuid            = "RaspPiGpioNode";
            cfg.YpchannelPort   = Constants.YPChannelPort;
            cfg.YpchannelSecure = true;

            //add new active conf and save to disk
            yconfig.AddActiveConf("default", cfg);
            yconfig.Save();

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

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

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

            //create node
            node = new Yodiwo.NodeLibrary.Node(conf,
                                               pairmodule,
                                               null, null,
                                               NodeGraphManager: null
                                               );
            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.OnThingActivated        += OnThingActivatedCb;
            node.OnThingDeactivated      += OnThingDeactivatedCb;

            //register port event handlers

            //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);

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

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

            //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,
                                                Helper.GatherThings(this.pysharp),
                                                pairmodule,
                                                null, null

                                                );
            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.OnUnexpectedRequest = HandleUnknownRequest;
            node.OnThingActivated += OnThingActivatedCb;

            //register port event handlers
            RegisterHandlers();


            //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);
                DebugEx.TraceLog("Node already paired: NodeKey = "
                    + ActiveCfg.NodeKey + ", NodeSecret = ", ActiveCfg.NodeSecret);
            }

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

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

            //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,
                                               Helper.GatherThings(this.pysharp),
                                               pairmodule,
                                               null, null

                                               );
            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.OnUnexpectedRequest      = HandleUnknownRequest;
            node.OnThingActivated        += OnThingActivatedCb;

            //register port event handlers
            RegisterHandlers();


            //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);
                DebugEx.TraceLog("Node already paired: NodeKey = "
                                 + ActiveCfg.NodeKey + ", NodeSecret = ", ActiveCfg.NodeSecret);
            }

            //connect
            node.Connect();
        }
Пример #11
0
        public YConfig<RaspNodeConfig> InitConfig()
        {
            var absoluteCfgFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/" + this.cfgFile;

            var yconfig = new YConfig<RaspNodeConfig>(absoluteCfgFile);

            try
            {
                if (yconfig.Retrieve())
                {
                    Console.WriteLine("Config file found: {0}", absoluteCfgFile);
                    return yconfig;
                }
                Console.WriteLine("Config retrieval failed; falling back to defaults");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Loading default configuration");
            }

            //create default conf
            RaspNodeConfig cfg = new RaspNodeConfig();
            cfg.FrontendServer = "https://cyan.yodiwo.com";
            cfg.ApiServer = "api.yodiwo.com";
            cfg.LocalWebServer = "http://localhost:3339";
            cfg.Uuid = "1337Raspberry";
            cfg.MqttBrokerHostname = "api.yodiwo.com";
            cfg.YpchannelPort = Yodiwo.API.Plegma.Constants.YPChannelPort;
            cfg.MqttUseSsl = false;
            cfg.YpchannelSecure = false;

            //add new active conf and save to disk
            yconfig.AddActiveConf("default", cfg);
            yconfig.Save();

            return yconfig;
        }
Пример #12
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
        }
Пример #13
0
        public void Start()
        {
            #region Configurations

            this.YConfig   = this.InitConfig();
            this.ActiveCfg = this.YConfig.GetActiveConf();
            NodeConfig conf = new NodeConfig()
            {
                uuid           = ActiveCfg.Uuid,
                Name           = "RaspPiGpioNode",
                YpServer       = ActiveCfg.ApiServer,
                YpchannelPort  = ActiveCfg.YpchannelPort,
                SecureYpc      = ActiveCfg.YpchannelSecure,
                FrontendServer = ActiveCfg.FrontendServer,
                CanSolveGraphs = false,
                Pairing_NoUUIDAuthentication = true
            };

            if (String.IsNullOrWhiteSpace(ActiveCfg.NodeKey))
            {
                _IsFirstConnectionAfterPairing = true;
            }

            #endregion

            #region Node construction
            //create node
            Node = new Yodiwo.NodeLibrary.Node(conf,
                                               new Yodiwo.NodeLibrary.Pairing.NancyPairing.NancyPairing(),
                                               DataLoad: null,
                                               DataSave: null,
                                               nodeType: eNodeType.EndpointSingle
                                               );
            #endregion

            #region Register callbacks
            Node.OnNodePaired            += Node_OnPairedCb;
            Node.OnNodeUnpaired          += Node_OnNodeUnpairedCb;
            Node.OnTransportConnected    += Node_OnTransportConnectedCb;
            Node.OnTransportDisconnected += Node_OnTransportDisconnectedCb;
            Node.OnTransportError        += Node_OnTransportErrorCb;
            #endregion

            #region Do Pairing/Connection
            if (String.IsNullOrWhiteSpace(ActiveCfg.NodeKey))
            {
                //if nodekey null, start pairing
                DebugEx.TraceLog("Starting pairing procedure.");
                var task = Node.StartPairing(ActiveCfg.FrontendServer, null, ActiveCfg.LocalWebServer);
                task.Wait();
            }
            #endregion

            //already paired, connect
            Node.SetupNodeKeys(ActiveCfg.NodeKey, ActiveCfg.NodeSecret.ToSecureString());
            DebugEx.TraceLog($"Node already paired: NodeKey={ActiveCfg.NodeKey}, NodeSecret={ActiveCfg.NodeSecret.Substring(0, 8)}...");

            _SetupThings();

            foreach (var thing in ThingIdToThing.Values)
            {
                Node.PortEventHandlers[thing.Ports[0]] = (data, isEvent) =>
                {
                    Console.WriteLine("PorteventMsg Rx (isEvent={2}) for thingUID {0} with data {1}", thing.ThingKey.Split('-').Last(), data, isEvent);
                    if (isEvent)
                    {
                        var gpiopin = ThingIdToPin.TryGetOrDefault(thing.ThingKey.Split('-').Last(), GpioPin.Unknown);
                        if (gpiopin != GpioPin.Unknown)
                        {
                            Console.WriteLine("Setting pin {0} to {1}", gpiopin, data);
                            gpioPinsConnection[GpioToPin.TryGetOrDefault(gpiopin)] = data.ParseToBool();
                        }
                    }
                };
            }

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

            this.YConfig = this.InitConfig();
            this.ActiveCfg = this.YConfig.GetActiveConf();
            NodeConfig conf = new NodeConfig()
            {
                uuid = ActiveCfg.Uuid,
                Name = "RaspPiGpioNode",
                YpServer = ActiveCfg.ApiServer,
                YpchannelPort = ActiveCfg.YpchannelPort,
                SecureYpc = ActiveCfg.YpchannelSecure,
                FrontendServer = ActiveCfg.FrontendServer,
                CanSolveGraphs = false,
                Pairing_NoUUIDAuthentication = true
            };

            if (String.IsNullOrWhiteSpace(ActiveCfg.NodeKey))
            {
                _IsFirstConnectionAfterPairing = true;
            }

            #endregion

            #region Node construction
            //create node
            Node = new Yodiwo.NodeLibrary.Node(conf,
                                               new Yodiwo.NodeLibrary.Pairing.NancyPairing.NancyPairing(),
                                               DataLoad: null,
                                               DataSave: null,
                                               nodeType: eNodeType.EndpointSingle
                                               );
            #endregion

            #region Register callbacks
            Node.OnNodePaired += Node_OnPairedCb;
            Node.OnNodeUnpaired += Node_OnNodeUnpairedCb;
            Node.OnTransportConnected += Node_OnTransportConnectedCb;
            Node.OnTransportDisconnected += Node_OnTransportDisconnectedCb;
            Node.OnTransportError += Node_OnTransportErrorCb;
            #endregion

            #region Do Pairing/Connection
            if (String.IsNullOrWhiteSpace(ActiveCfg.NodeKey))
            {
                //if nodekey null, start pairing
                DebugEx.TraceLog("Starting pairing procedure.");
                var task = Node.StartPairing(ActiveCfg.FrontendServer, null, ActiveCfg.LocalWebServer);
                task.Wait();
            }
            #endregion

            //already paired, connect
            Node.SetupNodeKeys(ActiveCfg.NodeKey, ActiveCfg.NodeSecret.ToSecureString());
            DebugEx.TraceLog($"Node already paired: NodeKey={ActiveCfg.NodeKey}, NodeSecret={ActiveCfg.NodeSecret.Substring(0, 8)}...");

            _SetupThings();

            foreach (var thing in ThingIdToThing.Values)
            {
                Node.PortEventHandlers[thing.Ports[0]] = (data, isEvent) =>
                {
                    Console.WriteLine("PorteventMsg Rx (isEvent={2}) for thingUID {0} with data {1}", thing.ThingKey.Split('-').Last(), data, isEvent);
                    if (isEvent)
                    {
                        var gpiopin = ThingIdToPin.TryGetOrDefault(thing.ThingKey.Split('-').Last(), GpioPin.Unknown);
                        if (gpiopin != GpioPin.Unknown)
                        {
                            Console.WriteLine("Setting pin {0} to {1}", gpiopin, data);
                            gpioPinsConnection[GpioToPin.TryGetOrDefault(gpiopin)] = data.ParseToBool();
                        }
                    }
                };
            }

            //connect
            Node.Connect();
        }
Пример #15
0
        public YConfig<RaspPiGpioNodeConfig> InitConfig()
        {
            var absoluteCfgFile = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/" + this.cfgFile;

            var yconfig = new YConfig<RaspPiGpioNodeConfig>(absoluteCfgFile);

            try
            {
                if (yconfig.Retrieve())
                {
                    Console.WriteLine("Config file found: {0}", absoluteCfgFile);
                    return yconfig;
                }
                Console.WriteLine("Config retrieval failed; falling back to defaults");
            }
            catch
            {
                Console.WriteLine("Loading default configuration");
            }

            //create default conf
            RaspPiGpioNodeConfig cfg = new RaspPiGpioNodeConfig();
            cfg.FrontendServer = "https://tcyan.yodiwo.com";
            cfg.ApiServer = "api.yodiwo.com";
            cfg.LocalWebServer = "http://localhost:3339";
            cfg.Uuid = "RaspPiGpioNode";
            cfg.YpchannelPort = Constants.YPChannelPort;
            cfg.YpchannelSecure = true;

            //add new active conf and save to disk
            yconfig.AddActiveConf("default", cfg);
            yconfig.Save();

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

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

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

            //create node
            node = new Yodiwo.NodeLibrary.Node(conf,
                                                pairmodule,
                                                null, null,
                                                NodeGraphManager: null
                                                );
            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.OnThingActivated += OnThingActivatedCb;
            node.OnThingDeactivated += OnThingDeactivatedCb;

            //register port event handlers

            //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);

            //connect
            node.Connect();
        }
Пример #17
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
        }