//------------------------------------------------------------------------------------------------------------------------ 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, }; //create the proxy node proxyNode = new Yodiwo.NodeLibrary.Node(conf, Things, null, null, null); //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(); }
//------------------------------------------------------------------------------------------------------------------------ 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(); }
//------------------------------------------------------------------------------------------------------------------------ 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(); }
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(); }
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(); }
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(); }
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(); }
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 }
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(); }
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(); }
private async void Page_Loaded(object sender, RoutedEventArgs e) { //show status form SetStatus("Initializing Virtual Node"); //Check Pairing #region Check Pairing/connection if (NodeKey.IsInvalid) { SetStatus("Waiting for pairing completion"); //start pairing await node.StartPairing(ActiveCfg.FrontendServer, null, ActiveCfg.LocalWebServer); //get result while (NodeKey.IsInvalid) { await Task.Delay(500); } SetStatus("Pairing Completed"); } else { //Setup node info from stored configurations node.SetupNodeKeys(ActiveCfg.NodeKey, ActiveCfg.NodeSecret); } //Connect if (this.transport != Transport.None) { SetStatus("Connecting " + this.transport.ToString() + " to worker"); node.Transport = this.transport; node.Connect(); //close status form SetStatus("Virtual Gateway started"); //enable controls brdDisabler.Visibility = Visibility.Collapsed; } else { await MessageBox.Show("Set your transport"); } speechRecognizer = new SpeechRecognizer(SpeechRecognizer.SystemSpeechLanguage); speechRecognizer.StateChanged += SpeechRecognizer_StateChanged;; // Apply the dictation topic constraint to optimize for dictated freeform speech. var dictationConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "dictation"); speechRecognizer.Constraints.Add(dictationConstraint); SpeechRecognitionCompilationResult result = await speechRecognizer.CompileConstraintsAsync(); if (result.Status != SpeechRecognitionResultStatus.Success) { SetStatus("Speech recognition init failed"); } //start recogniser recognHeartBeat(); //Workaround Alert : Accelerometers stop giving out events after a time for some reason.. so keep "refreshing" them every XXX time #region Start Accelerometers //start accelerometer Task.Run(() => { while (true) { if (accelerometer != null) { accelerometer.ReadingChanged -= accelerometer_ReadingChanged; accelerometer.Shaken -= Accelerometer_Shaken; } accelerometer = Accelerometer.GetDefault(); accelerometer.ReportInterval = 300; accelerometer.ReadingChanged += accelerometer_ReadingChanged; accelerometer.Shaken += Accelerometer_Shaken; Task.Delay(2000).Wait(); } }); //start accelerometer 2 Task.Run(() => { while (true) { if (accelerometer2 != null) { accelerometer2.ReadingChanged -= accelerometer2_ReadingChanged; } accelerometer2 = Accelerometer.GetDefault(); accelerometer2.ReportInterval = 50; accelerometer2.ReadingChanged += accelerometer2_ReadingChanged; Task.Delay(2000).Wait(); } }); #endregion }
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 }