Inheritance: IYConfigEntry
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 4
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();
        }