//------------------------------------------------------------------------------------------------------------------------ private List <Thing> SetupSerialPortThings() { List <Thing> things = new List <Thing>(); // Serial Port Data { var tkey1 = new ThingKey(NodeKey, CreateThingId("1")); SendToCloudPort = new Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "FromSerialPort", State = "", ConfFlags = ePortConf.None, Type = Yodiwo.API.Plegma.ePortType.String, PortKey = PortKey.BuildFromArbitraryString(tkey1, "0") }; var t = new Yodiwo.API.Plegma.Thing() { ThingKey = tkey1, Type = "com.yodiwo.serialport", Name = "SerialOut", UIHints = new ThingUIHints() { IconURI = "http://www.aimtouch.com/images/RS232-icon.png", }, Ports = new List <Port>() { SendToCloudPort } }; t = AddThing(t); things.Add(t); } // Serial Port success write { var tkey2 = new ThingKey(NodeKey, CreateThingId("2")); ReceiveFromCloudPort = new Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "ToSerialPort", State = "", ConfFlags = ePortConf.None, Type = Yodiwo.API.Plegma.ePortType.String, PortKey = PortKey.BuildFromArbitraryString(tkey2, "0") }; var t = new Yodiwo.API.Plegma.Thing() { ThingKey = tkey2, Type = "com.yodiwo.serialport", Name = "SerialIn", UIHints = new ThingUIHints() { IconURI = "http://www.aimtouch.com/images/RS232-icon.png", }, Ports = new List <Port>() { ReceiveFromCloudPort } }; t = AddThing(t); things.Add(t); } return(things); }
public static void CreateThings(Transport trans, Node node) { #region READ CONFIGURATION var SavedThingsConfig = ReadConfig(); if (SavedThingsConfig == null) { DebugEx.Assert("Could not retrieve or create config; startup failed"); return; } //use pin configuration from saved conf file var buzzerPin = SavedThingsConfig[typeof(Buzzer)].Pin; var rgbLedPin = SavedThingsConfig[typeof(RgbLed)].Pin; var soundSensorPin = SavedThingsConfig[typeof(SoundSensor)].Pin; var lightSensorPin = SavedThingsConfig[typeof(LightSensor)].Pin; var buttonPin = SavedThingsConfig[typeof(Button)].Pin; var rotaryAnglePin = SavedThingsConfig[typeof(RotaryAngleSensor)].Pin; var relayPin = SavedThingsConfig[typeof(Relay)].Pin; var htSensorPin = SavedThingsConfig[typeof(TempAndHumidity)].Pin; var ultrasonicPin = SavedThingsConfig[typeof(UltraSonicRanger)].Pin; var lcdPin = SavedThingsConfig[typeof(LCD)].Pin; //use sampling period configuration from saved conf file var gpio_Sampling = SavedThingsConfig[typeof(GPIO)].Period; var soundSensorSampling = SavedThingsConfig[typeof(SoundSensor)].Period; var lightSensorSampling = SavedThingsConfig[typeof(LightSensor)].Period; var buttonSampling = SavedThingsConfig[typeof(Button)].Period; var rotaryAngleSampling = SavedThingsConfig[typeof(RotaryAngleSensor)].Period; var relaySampling = SavedThingsConfig[typeof(Relay)].Period; var htSensorSampling = SavedThingsConfig[typeof(TempAndHumidity)].Period; var ultrasonicSampling = SavedThingsConfig[typeof(UltraSonicRanger)].Period; #endregion #region CREATE SENSORS /* A2MCU */ GPIO GPIO_2 = new GPIO(Pin.DigitalPin2, trans, gpio_Sampling); GPIO GPIO_3 = new GPIO(Pin.DigitalPin3, trans, gpio_Sampling); GPIO GPIO_4 = new GPIO(Pin.DigitalPin4, trans, gpio_Sampling); GPIO GPIO_5 = new GPIO(Pin.DigitalPin5, trans, gpio_Sampling); GPIO GPIO_6 = new GPIO(Pin.DigitalPin6, trans, gpio_Sampling); /* /A2MCU */ Buzzer buzzer = new Buzzer(GrovePiSensor.PinNameToPin[buzzerPin], trans); RgbLed rgbled = new RgbLed(GrovePiSensor.PinNameToPin[rgbLedPin], trans); SoundSensor soundSensor = new SoundSensor(GrovePiSensor.PinNameToPin[soundSensorPin], trans, soundSensorSampling); LightSensor lightSensor = new LightSensor(GrovePiSensor.PinNameToPin[lightSensorPin], trans, lightSensorSampling); Button button = new Button(GrovePiSensor.PinNameToPin[buttonPin], trans, buttonSampling); RotaryAngleSensor rotaryAngleSensor = new RotaryAngleSensor(GrovePiSensor.PinNameToPin[rotaryAnglePin], trans, rotaryAngleSampling); Relay relaySensor = new Relay(GrovePiSensor.PinNameToPin[relayPin], trans, relaySampling); TempAndHumidity htSensor = new TempAndHumidity(GrovePiSensor.PinNameToPin[htSensorPin], trans, htSensorSampling); UltraSonicRanger ultrasonicSensor = new UltraSonicRanger(GrovePiSensor.PinNameToPin[ultrasonicPin], trans, ultrasonicSampling); LCD lcd = new LCD(GrovePiSensor.PinNameToPin[lcdPin], trans); #endregion #region SETUP THINGS #region Setup A2MCU GPIO things List <Thing> gpio_things = new List <Thing>(); for (int i = 2; i <= 6; i++) { //var pinConfig = new ConfigParameter() { Name = "Pin", Value = buzzerPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = gpio_Sampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "gpio_thing" + i), Type = ThingTypeLibrary.Gpio.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "GPIO_" + i, Config = new List <ConfigParameter>() { samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/gpio.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "GPO", PortModelId = ModelTypeLibrary.GpioModel_Id, State = "false", Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "GPO") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "GPI", State = "false", PortModelId = ModelTypeLibrary.GpioModel_Id, Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "GPI") } }; thing = node.AddThing(thing); gpio_things.Add(thing); Things.Add(thing); } //gpio thing --> gpio sensor class GPIOs.Add(gpio_things.ElementAt(0), GPIO_2); GPIOs.Add(gpio_things.ElementAt(1), GPIO_3); GPIOs.Add(gpio_things.ElementAt(2), GPIO_4); GPIOs.Add(gpio_things.ElementAt(3), GPIO_5); GPIOs.Add(gpio_things.ElementAt(4), GPIO_6); //gpio thing --> generic sensor class Lookup.Add(gpio_things.ElementAt(0), GPIO_2); Lookup.Add(gpio_things.ElementAt(1), GPIO_3); Lookup.Add(gpio_things.ElementAt(2), GPIO_4); Lookup.Add(gpio_things.ElementAt(3), GPIO_5); Lookup.Add(gpio_things.ElementAt(4), GPIO_6); gpio_things.Clear(); #endregion //setup Buzzer thing #region Setup Buzzer thing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = buzzerPin }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "buzzerthing"), Type = ThingTypeLibrary.Buzzer.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "Buzzer", Config = new List <ConfigParameter>() { pinConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/buzzer.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "BuzzerState", State = "false", PortModelId = ModelTypeLibrary.BuzzerModel_Id, Type = Yodiwo.API.Plegma.ePortType.Decimal, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; BuzzerThing = thing = node.AddThing(thing); } #endregion //setup RgbLed thing #region SetUp RgbLedThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = rgbLedPin }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "RgbLedThing"), Type = ThingTypeLibrary.Lights.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.Lights_BooleanModelType, Name = "RgbLed", Config = new List <ConfigParameter>() { pinConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/thing-genericlight.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "RgbLedState", State = "false", PortModelId = ModelTypeLibrary.OnOffLightModel_Id, Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; RgbLedThing = thing = node.AddThing(thing); } #endregion //setup SoundSensorThing #region SetUp SoundSensorThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = soundSensorPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = soundSensorSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "SoundSensorThing"), Type = ThingTypeLibrary.SoundSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "SoundSensor", Config = new List <ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/sound.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Value", State = "0", PortModelId = ModelTypeLibrary.SoundSensorModel_Id, Type = Yodiwo.API.Plegma.ePortType.Integer, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; SoundSensorThing = thing = node.AddThing(thing); } #endregion //setup Light Sensor thing #region SetUp LightSensorThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = lightSensorPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = lightSensorSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "LightSensorThing"), Type = ThingTypeLibrary.LightSensor.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.LightSensor_NonNormalizedModelType, Name = "LightSensor", Config = new List <ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/light.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Lumens", State = "0", PortModelId = ModelTypeLibrary.Brightness_Id, Type = Yodiwo.API.Plegma.ePortType.Integer, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; LightSensorThing = thing = node.AddThing(thing); } #endregion //setup Button thing #region SetUp ButtonThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = buttonPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = buttonSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "ButtonSensorThing"), Type = ThingTypeLibrary.Button.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "Button", Config = new List <ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/thing-genericbutton.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "ButtonState", State = "0", PortModelId = ModelTypeLibrary.ButtonModel_OnOffActuatorId, Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; ButtonSensorThing = thing = node.AddThing(thing); } #endregion //setup RotaryAngle Sensor thing #region SetUp RotaryAngleSensorThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = rotaryAnglePin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = rotaryAngleSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "RotaryAngleSensorThing"), Type = ThingTypeLibrary.Slider.Type + PlegmaAPI.ThingModelTypeSeparatorStr, Name = "Rotary Angle Sensor", Config = new List <ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/thing-slider.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "RotaryAngle", State = "0", PortModelId = ModelTypeLibrary.SliderModel_Id, Type = Yodiwo.API.Plegma.ePortType.Decimal, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; RotaryAngleSensorThing = thing = node.AddThing(thing); } #endregion #if false //setup Relay thing #region SetUp RelayThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = relayPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = relaySampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "RelaySensorThing"), Type = ThingTypeLibrary.SwitchActuator.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.SwitchActuator_RelayModelType, Name = "Relay", Config = new List <ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/relay.jpg", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "RelayState", PortModelId = ModelTypeLibrary.RelayModel_RelayId, State = "0", Type = Yodiwo.API.Plegma.ePortType.Integer, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; RelaySensorThing = thing = node.AddThing(thing); } #endregion #endif //setup Temperature and Humidity Sensor thing #region SetUp HTSensorThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = htSensorPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = htSensorSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "HTSensorThing"), Type = ThingTypeLibrary.HTSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "Temperature and Humidity Sensor", Config = new List <ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/ht.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, PortModelId = ModelTypeLibrary.HTSensorModel_TemperatureSensorId, Name = "HT", State = "0", Type = Yodiwo.API.Plegma.ePortType.Integer, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; HTSensorThing = thing = node.AddThing(thing); } #endregion //setup UltraSonic Sensor thing #region SetUp UltrasonicThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = ultrasonicPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = ultrasonicSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "UltrasonicSensorThing"), Type = ThingTypeLibrary.ProximitySensor.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.ProximitySensor_UltrasonicModelType, Name = "Ultrasonic Sensor", Config = new List <ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/proximity.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "cm", State = "0", PortModelId = ModelTypeLibrary.UltrasonicSensorModel_Id, Type = Yodiwo.API.Plegma.ePortType.Integer, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; UltrasonicSensorThing = thing = node.AddThing(thing); } #endregion //setup LCD Sensor thing #region SetUp LCDThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = lcdPin }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "LCDThing"), Type = ThingTypeLibrary.Lcd.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "LCD", Config = new List <ConfigParameter>() { pinConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/lcd.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "Message", State = "0", PortModelId = ModelTypeLibrary.LcdModel_Id, Type = Yodiwo.API.Plegma.ePortType.String, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; LCDThing = thing = node.AddThing(thing); } #endregion #endregion #region LUT CRETION Things.Add(BuzzerThing); Things.Add(RgbLedThing); Things.Add(SoundSensorThing); Things.Add(LightSensorThing); Things.Add(ButtonSensorThing); Things.Add(RotaryAngleSensorThing); //Things.Add(RelaySensorThing); Things.Add(HTSensorThing); Things.Add(UltrasonicSensorThing); Things.Add(LCDThing); Lookup.Add(BuzzerThing, buzzer); Lookup.Add(RgbLedThing, rgbled); Lookup.Add(SoundSensorThing, soundSensor); Lookup.Add(LightSensorThing, lightSensor); Lookup.Add(ButtonSensorThing, button); Lookup.Add(RotaryAngleSensorThing, rotaryAngleSensor); //Lookup.Add(RelaySensorThing, relaySensor); Lookup.Add(HTSensorThing, htSensor); Lookup.Add(UltrasonicSensorThing, ultrasonicSensor); Lookup.Add(LCDThing, lcd); /* * GroveSensors.Add(BuzzerThing.Name, buzzer); * GroveSensors.Add(RgbLedThing.Name, rgbled); * GroveSensors.Add(SoundSensorThing.Name, soundSensor); * GroveSensors.Add(LightSensorThing.Name, lightSensor); * GroveSensors.Add(ButtonSensorThing.Name, button); * GroveSensors.Add(RotaryAngleSensorThing.Name, rotaryAngleSensor); * GroveSensors.Add(RelaySensorThing.Name, relaySensor); * GroveSensors.Add(HTSensorThing.Name, htSensor); * GroveSensors.Add(UltrasonicSensorThing.Name, ultrasonicSensor); * GroveSensors.Add(LCDThing.Name, lcd); */ #endregion #region REGISTER EVENTS foreach (var gpio in GPIOs.Values) { gpio.OnGetContinuousDatacb += data => OnGetContinuousDatacb(gpio, data); } soundSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(soundSensor, data); lightSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(lightSensor, data); button.OnGetContinuousDatacb += data => OnGetContinuousDatacb(button, data); rotaryAngleSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(rotaryAngleSensor, data); relaySensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(relaySensor, data); htSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(htSensor, data); ultrasonicSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(ultrasonicSensor, data); #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 }
public static void CreateThings(Transport trans, Node node) { //setup Position thing //3 ports (x,y,z) #region Setup Position thing { var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "PositionThing"), Type = ThingTypeLibrary.PositionSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "Position", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/position.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Position x State", State = "0", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.PositionSensorModel_XId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Position y State", State = "0", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.PositionSensorModel_YId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "1") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Position z State", State = "0", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.PositionSensorModel_ZId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "2") }, }; PositionThing = thing = node.AddThing(thing); } #endregion //setup Gesture thing // 5 ports(i.e tap:'center','flick':north2south,'touch':west...) #region Setup Gesture thing { var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "GestureThing"), Type = ThingTypeLibrary.GestureSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "Gesture", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/motion.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Tap", State = "false", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.GestureSensorModel_TapId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Touch", State = "false", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.GestureSensorModel_TouchId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "1") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "DoubleTap", State = "false", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.GestureSensorModel_DoubleTapId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "2") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Airwheel", State = "false", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.GestureSensorModel_AirwheelId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "3") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Flick", State = "false", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.GestureSensorModel_FlickId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "4") }, }; GestureThing = thing = node.AddThing(thing); } #endregion //add things Things.Add(PositionThing); Things.Add(GestureThing); //create skywriter sensors PositionSensor positionsensor = new PositionSensor(trans); GestureSensor gesturesensor = new GestureSensor(trans); //update dictinaries Lookup.Add(PositionThing, positionsensor); Lookup.Add(GestureThing, gesturesensor); SkyWriterSensors.Add(PositionThing.Name, positionsensor); SkyWriterSensors.Add(GestureThing.Name, gesturesensor); //register events positionsensor.OnGetContinuousDatacb += p => OnGetPositionDatacb(positionsensor, p); gesturesensor.OnGetContinuousDatacb += p => OnGetGestureDatacb(gesturesensor, p); }
//------------------------------------------------------------------------------------------------------------------------ private IEnumerable <Thing> SetupSerialPortThing() { // Clean old things things.Clear(); // mNode transport conncted event { var isTransportConnected = new Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Connected", State = "", ConfFlags = ePortConf.IsTrigger, Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") }; Ports.Add("isTransportConnected", isTransportConnected); var connectionTimestamp = new Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Timestamp", State = "", ConfFlags = ePortConf.None, Type = Yodiwo.API.Plegma.ePortType.Timestamp, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "1") }; Ports.Add("connectionTimestamp", connectionTimestamp); var t = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", CreateThingKey("0")), Type = "", Name = "Transport", Config = new List <ConfigParameter>(), UIHints = new ThingUIHints() { IconURI = "http://simpleicon.com/wp-content/uploads/cloud-connection-1.png", }, Ports = new List <Port>() { isTransportConnected, connectionTimestamp } }; t = AddThing(t); things.Add("Transport", t); } // mNode periodic send { var periodicTimestamp = new Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Timestamp", State = "", ConfFlags = ePortConf.None, Type = Yodiwo.API.Plegma.ePortType.Timestamp, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") }; Ports.Add("periodicTimestamp", periodicTimestamp); var t = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", CreateThingKey("1")), Type = "", Name = "Periodic", Config = new List <ConfigParameter>() { // TODO: Use the actual value of the thing new ConfigParameter() { Description = "Period Seconds", Name = "Period", Value = "10" } }, UIHints = new ThingUIHints() { IconURI = "https://openreferral.org/wp-content/uploads/2015/02/icon_4034-300x300.png", }, Ports = new List <Port>() { periodicTimestamp } }; t = AddThing(t); things.Add("Periodic", t); } // mNode Ping { var echoPortOut = new Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Echo", State = "", ConfFlags = ePortConf.None, Type = Yodiwo.API.Plegma.ePortType.String, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") }; Ports.Add("echoPortOut", echoPortOut); var echoPortIn = new Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "Echo", State = "", ConfFlags = ePortConf.None, Type = Yodiwo.API.Plegma.ePortType.String, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "1") }; Ports.Add("echoPortIn", echoPortIn); var t = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", CreateThingKey("2")), Type = "", Name = "Ping", Config = new List <ConfigParameter>(), UIHints = new ThingUIHints() { IconURI = "https://apk-dl.com/detail/image/com.lipinic.ping-w250.png", }, Ports = new List <Port>() { echoPortIn, echoPortOut } }; t = AddThing(t); things.Add("Ping", t); } return(things.Values); }
public static void CreateThings(Transport trans, Node node) { #region READ CONFIGURATION var SavedThingsConfig = ReadConfig(); if (SavedThingsConfig == null) { DebugEx.Assert("Could not retrieve or create config; startup failed"); return; } //use pin configuration from saved conf file var buzzerPin = SavedThingsConfig[typeof(Buzzer)].Pin; var rgbLedPin = SavedThingsConfig[typeof(RgbLed)].Pin; var soundSensorPin = SavedThingsConfig[typeof(SoundSensor)].Pin; var lightSensorPin = SavedThingsConfig[typeof(LightSensor)].Pin; var buttonPin = SavedThingsConfig[typeof(Button)].Pin; var rotaryAnglePin = SavedThingsConfig[typeof(RotaryAngleSensor)].Pin; var relayPin = SavedThingsConfig[typeof(Relay)].Pin; var htSensorPin = SavedThingsConfig[typeof(TempAndHumidity)].Pin; var ultrasonicPin = SavedThingsConfig[typeof(UltraSonicRanger)].Pin; var lcdPin = SavedThingsConfig[typeof(LCD)].Pin; //use sampling period configuration from saved conf file var gpio_Sampling = SavedThingsConfig[typeof(GPIO)].Period; var soundSensorSampling = SavedThingsConfig[typeof(SoundSensor)].Period; var lightSensorSampling = SavedThingsConfig[typeof(LightSensor)].Period; var buttonSampling = SavedThingsConfig[typeof(Button)].Period; var rotaryAngleSampling = SavedThingsConfig[typeof(RotaryAngleSensor)].Period; var relaySampling = SavedThingsConfig[typeof(Relay)].Period; var htSensorSampling = SavedThingsConfig[typeof(TempAndHumidity)].Period; var ultrasonicSampling = SavedThingsConfig[typeof(UltraSonicRanger)].Period; #endregion #region CREATE SENSORS /* A2MCU */ GPIO GPIO_2 = new GPIO(Pin.DigitalPin2, trans, gpio_Sampling); GPIO GPIO_3 = new GPIO(Pin.DigitalPin3, trans, gpio_Sampling); GPIO GPIO_4 = new GPIO(Pin.DigitalPin4, trans, gpio_Sampling); GPIO GPIO_5 = new GPIO(Pin.DigitalPin5, trans, gpio_Sampling); GPIO GPIO_6 = new GPIO(Pin.DigitalPin6, trans, gpio_Sampling); /* /A2MCU */ Buzzer buzzer = new Buzzer(GrovePiSensor.PinNameToPin[buzzerPin], trans); RgbLed rgbled = new RgbLed(GrovePiSensor.PinNameToPin[rgbLedPin], trans); SoundSensor soundSensor = new SoundSensor(GrovePiSensor.PinNameToPin[soundSensorPin], trans, soundSensorSampling); LightSensor lightSensor = new LightSensor(GrovePiSensor.PinNameToPin[lightSensorPin], trans, lightSensorSampling); Button button = new Button(GrovePiSensor.PinNameToPin[buttonPin], trans, buttonSampling); RotaryAngleSensor rotaryAngleSensor = new RotaryAngleSensor(GrovePiSensor.PinNameToPin[rotaryAnglePin], trans, rotaryAngleSampling); Relay relaySensor = new Relay(GrovePiSensor.PinNameToPin[relayPin], trans, relaySampling); TempAndHumidity htSensor = new TempAndHumidity(GrovePiSensor.PinNameToPin[htSensorPin], trans, htSensorSampling); UltraSonicRanger ultrasonicSensor = new UltraSonicRanger(GrovePiSensor.PinNameToPin[ultrasonicPin], trans, ultrasonicSampling); LCD lcd = new LCD(GrovePiSensor.PinNameToPin[lcdPin], trans); #endregion #region SETUP THINGS #region Setup A2MCU GPIO things List<Thing> gpio_things = new List<Thing>(); for (int i = 2; i <= 6; i++) { //var pinConfig = new ConfigParameter() { Name = "Pin", Value = buzzerPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = gpio_Sampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "gpio_thing" + i), Type = ThingTypeLibrary.Gpio.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "GPIO_" + i, Config = new List<ConfigParameter>() { samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/gpio.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "GPO", PortModelId = ModelTypeLibrary.GpioModel_Id, State = "false", Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "GPO") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "GPI", State = "false", PortModelId = ModelTypeLibrary.GpioModel_Id, Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "GPI") } }; thing = node.AddThing(thing); gpio_things.Add(thing); Things.Add(thing); } //gpio thing --> gpio sensor class GPIOs.Add(gpio_things.ElementAt(0), GPIO_2); GPIOs.Add(gpio_things.ElementAt(1), GPIO_3); GPIOs.Add(gpio_things.ElementAt(2), GPIO_4); GPIOs.Add(gpio_things.ElementAt(3), GPIO_5); GPIOs.Add(gpio_things.ElementAt(4), GPIO_6); //gpio thing --> generic sensor class Lookup.Add(gpio_things.ElementAt(0), GPIO_2); Lookup.Add(gpio_things.ElementAt(1), GPIO_3); Lookup.Add(gpio_things.ElementAt(2), GPIO_4); Lookup.Add(gpio_things.ElementAt(3), GPIO_5); Lookup.Add(gpio_things.ElementAt(4), GPIO_6); gpio_things.Clear(); #endregion //setup Buzzer thing #region Setup Buzzer thing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = buzzerPin }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "buzzerthing"), Type = ThingTypeLibrary.Buzzer.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "Buzzer", Config = new List<ConfigParameter>() { pinConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/buzzer.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "BuzzerState", State = "false", PortModelId = ModelTypeLibrary.BuzzerModel_Id, Type = Yodiwo.API.Plegma.ePortType.Decimal, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; BuzzerThing = thing = node.AddThing(thing); } #endregion //setup RgbLed thing #region SetUp RgbLedThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = rgbLedPin }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "RgbLedThing"), Type = ThingTypeLibrary.Lights.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.Lights_BooleanModelType, Name = "RgbLed", Config = new List<ConfigParameter>() { pinConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/thing-genericlight.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "RgbLedState", State = "false", PortModelId = ModelTypeLibrary.OnOffLightModel_Id, Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; RgbLedThing = thing = node.AddThing(thing); } #endregion //setup SoundSensorThing #region SetUp SoundSensorThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = soundSensorPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = soundSensorSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "SoundSensorThing"), Type = ThingTypeLibrary.SoundSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "SoundSensor", Config = new List<ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/sound.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Value", State = "0", PortModelId=ModelTypeLibrary.SoundSensorModel_Id, Type = Yodiwo.API.Plegma.ePortType.Integer, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; SoundSensorThing = thing = node.AddThing(thing); } #endregion //setup Light Sensor thing #region SetUp LightSensorThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = lightSensorPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = lightSensorSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "LightSensorThing"), Type = ThingTypeLibrary.LightSensor.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.LightSensor_NonNormalizedModelType, Name = "LightSensor", Config = new List<ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/light.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Lumens", State = "0", PortModelId = ModelTypeLibrary.Brightness_Id, Type = Yodiwo.API.Plegma.ePortType.Integer, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; LightSensorThing = thing = node.AddThing(thing); } #endregion //setup Button thing #region SetUp ButtonThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = buttonPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = buttonSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "ButtonSensorThing"), Type = ThingTypeLibrary.Button.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "Button", Config = new List<ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/thing-genericbutton.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "ButtonState", State = "0", PortModelId= ModelTypeLibrary.ButtonModel_OnOffActuatorId, Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; ButtonSensorThing = thing = node.AddThing(thing); } #endregion //setup RotaryAngle Sensor thing #region SetUp RotaryAngleSensorThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = rotaryAnglePin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = rotaryAngleSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "RotaryAngleSensorThing"), Type = ThingTypeLibrary.Slider.Type + PlegmaAPI.ThingModelTypeSeparatorStr, Name = "Rotary Angle Sensor", Config = new List<ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/thing-slider.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "RotaryAngle", State = "0", PortModelId =ModelTypeLibrary.SliderModel_Id, Type = Yodiwo.API.Plegma.ePortType.Decimal, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; RotaryAngleSensorThing = thing = node.AddThing(thing); } #endregion #if false //setup Relay thing #region SetUp RelayThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = relayPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = relaySampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "RelaySensorThing"), Type = ThingTypeLibrary.SwitchActuator.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.SwitchActuator_RelayModelType, Name = "Relay", Config = new List<ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/relay.jpg", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "RelayState", PortModelId = ModelTypeLibrary.RelayModel_RelayId, State = "0", Type = Yodiwo.API.Plegma.ePortType.Integer, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; RelaySensorThing = thing = node.AddThing(thing); } #endregion #endif //setup Temperature and Humidity Sensor thing #region SetUp HTSensorThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = htSensorPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = htSensorSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "HTSensorThing"), Type = ThingTypeLibrary.HTSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "Temperature and Humidity Sensor", Config = new List<ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/ht.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, PortModelId = ModelTypeLibrary.HTSensorModel_TemperatureSensorId, Name = "HT", State = "0", Type = Yodiwo.API.Plegma.ePortType.Integer, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; HTSensorThing = thing = node.AddThing(thing); } #endregion //setup UltraSonic Sensor thing #region SetUp UltrasonicThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = ultrasonicPin }; var samplePeriodConfig = new ConfigParameter() { Name = "SamplePeriod", Value = ultrasonicSampling.ToStringInvariant() }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "UltrasonicSensorThing"), Type = ThingTypeLibrary.ProximitySensor.Type + PlegmaAPI.ThingModelTypeSeparator + ThingTypeLibrary.ProximitySensor_UltrasonicModelType, Name = "Ultrasonic Sensor", Config = new List<ConfigParameter>() { pinConfig, samplePeriodConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/proximity.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "cm", State = "0", PortModelId = ModelTypeLibrary.UltrasonicSensorModel_Id, Type = Yodiwo.API.Plegma.ePortType.Integer, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; UltrasonicSensorThing = thing = node.AddThing(thing); } #endregion //setup LCD Sensor thing #region SetUp LCDThing { var pinConfig = new ConfigParameter() { Name = "Pin", Value = lcdPin }; var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "LCDThing"), Type = ThingTypeLibrary.Lcd.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "LCD", Config = new List<ConfigParameter>() { pinConfig }, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/lcd.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "Message", State = "0", PortModelId= ModelTypeLibrary.LcdModel_Id, Type = Yodiwo.API.Plegma.ePortType.String, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; LCDThing = thing = node.AddThing(thing); } #endregion #endregion #region LUT CRETION Things.Add(BuzzerThing); Things.Add(RgbLedThing); Things.Add(SoundSensorThing); Things.Add(LightSensorThing); Things.Add(ButtonSensorThing); Things.Add(RotaryAngleSensorThing); //Things.Add(RelaySensorThing); Things.Add(HTSensorThing); Things.Add(UltrasonicSensorThing); Things.Add(LCDThing); Lookup.Add(BuzzerThing, buzzer); Lookup.Add(RgbLedThing, rgbled); Lookup.Add(SoundSensorThing, soundSensor); Lookup.Add(LightSensorThing, lightSensor); Lookup.Add(ButtonSensorThing, button); Lookup.Add(RotaryAngleSensorThing, rotaryAngleSensor); //Lookup.Add(RelaySensorThing, relaySensor); Lookup.Add(HTSensorThing, htSensor); Lookup.Add(UltrasonicSensorThing, ultrasonicSensor); Lookup.Add(LCDThing, lcd); /* GroveSensors.Add(BuzzerThing.Name, buzzer); GroveSensors.Add(RgbLedThing.Name, rgbled); GroveSensors.Add(SoundSensorThing.Name, soundSensor); GroveSensors.Add(LightSensorThing.Name, lightSensor); GroveSensors.Add(ButtonSensorThing.Name, button); GroveSensors.Add(RotaryAngleSensorThing.Name, rotaryAngleSensor); GroveSensors.Add(RelaySensorThing.Name, relaySensor); GroveSensors.Add(HTSensorThing.Name, htSensor); GroveSensors.Add(UltrasonicSensorThing.Name, ultrasonicSensor); GroveSensors.Add(LCDThing.Name, lcd); */ #endregion #region REGISTER EVENTS foreach (var gpio in GPIOs.Values) gpio.OnGetContinuousDatacb += data => OnGetContinuousDatacb(gpio, data); soundSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(soundSensor, data); lightSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(lightSensor, data); button.OnGetContinuousDatacb += data => OnGetContinuousDatacb(button, data); rotaryAngleSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(rotaryAngleSensor, data); relaySensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(relaySensor, data); htSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(htSensor, data); ultrasonicSensor.OnGetContinuousDatacb += data => OnGetContinuousDatacb(ultrasonicSensor, data); #endregion }
//------------------------------------------------------------------------------------------------------------------------ #region Functions //------------------------------------------------------------------------------------------------------------------------ //initialize node's things public static List <Thing> GatherThings() { //setup CheckBox 1 thing #region Setup CheckBox 1 thing { var thing = CheckBox1Thing = new Yodiwo.API.Plegma.Thing() { Type = "yodiwo.output.checkboxes", Name = "Virtual CheckBox 1", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/VirtualGateway/img/icon-thing-checkbox.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "CheckState", State = "false", Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; Things.Add(thing); } #endregion //setup Text 1 thing #region Setup CheckBox 1 thing { var thing = TextThing = new Yodiwo.API.Plegma.Thing() { Type = "yodiwo.output.labels", Name = "Text 1", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/VirtualGateway/img/icon-thing-text.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "Text", State = "", Type = Yodiwo.API.Plegma.ePortType.String, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; Things.Add(thing); } #endregion //setup slider 1 thing #region Setup slider 1 thing { var thing = Slider1Thing = new Yodiwo.API.Plegma.Thing() { Type = "yodiwo.output.slider", Name = "Slider 1", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/VirtualGateway/img/icon-thing-slider.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Value", State = "0", Type = Yodiwo.API.Plegma.ePortType.Decimal, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; Things.Add(thing); } #endregion //setup Light 1 thing #region Setup Light 1 thing { var thing = Light1Thing = new Yodiwo.API.Plegma.Thing() { Type = "yodiwo.input.lights.dimmable", Name = "Virtual Light 1", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/VirtualGateway/img/icon-thing-genericlight.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "LightState", State = "0", Type = Yodiwo.API.Plegma.ePortType.Decimal, ConfFlags = ePortConf.PropagateAllEvents, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; Things.Add(thing); } #endregion //setup SpeechReg thing #region Setup SpeechReg thing { var thing = SpeechRegThing = new Yodiwo.API.Plegma.Thing() { Type = "yodiwo.output.speechrecognition", Name = "Virtual SpeechReg", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/VirtualGateway/img/icon-thing-voicerecognition.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Text", State = "", Type = Yodiwo.API.Plegma.ePortType.String, ConfFlags = ePortConf.PropagateAllEvents, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; Things.Add(thing); } #endregion //setup SpeechReg thing #region Setup Text2Speech thing { var thing = Text2SpeechThing = new Yodiwo.API.Plegma.Thing() { Type = "yodiwo.input.text2speech", Name = "Virtual Text2Speech", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/VirtualGateway/img/icon-thing-text2speech.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input, Name = "Text", State = "", Type = Yodiwo.API.Plegma.ePortType.String, ConfFlags = ePortConf.PropagateAllEvents, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; Things.Add(thing); } #endregion //setup thing #region accell 1 thing { var thing = AccelerometerThing = new Yodiwo.API.Plegma.Thing() { Type = "yodiwo.output.accelerometer", Name = "Accelerometer", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/VirtualGateway/img/icon-thing-slider.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "X", State = "0", Type = Yodiwo.API.Plegma.ePortType.Decimal, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Y", State = "0", Type = Yodiwo.API.Plegma.ePortType.Decimal, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "1") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Z", State = "0", Type = Yodiwo.API.Plegma.ePortType.Decimal, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "2") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Length", State = "0", Type = Yodiwo.API.Plegma.ePortType.Decimal, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "3") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Shaken", State = "0", ConfFlags = ePortConf.PropagateAllEvents, Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "4") } }; Things.Add(thing); } #endregion //setup thing #region Setup fall thing { var thing = FallThing = new Yodiwo.API.Plegma.Thing() { Type = "yodiwo.output.accelerometer", Name = "Fall Detector", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/VirtualGateway/img/icon-thing-checkbox.png", }, }; thing.Ports = new List <Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Fall Event", State = "false", ConfFlags = ePortConf.PropagateAllEvents, Type = Yodiwo.API.Plegma.ePortType.Boolean, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") } }; Things.Add(thing); } #endregion return(Things); }
public static void CreateThings(Transport trans, Node node) { //setup Position thing //3 ports (x,y,z) #region Setup Position thing { var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "PositionThing"), Type = ThingTypeLibrary.PositionSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "Position", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/position.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Position x State", State = "0", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.PositionSensorModel_XId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Position y State", State = "0", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.PositionSensorModel_YId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "1") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Position z State", State = "0", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.PositionSensorModel_ZId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "2") }, }; PositionThing = thing = node.AddThing(thing); } #endregion //setup Gesture thing // 5 ports(i.e tap:'center','flick':north2south,'touch':west...) #region Setup Gesture thing { var thing = new Yodiwo.API.Plegma.Thing() { ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", "GestureThing"), Type = ThingTypeLibrary.GestureSensor.Type + PlegmaAPI.ThingModelTypeSeparatorPlusDefault, Name = "Gesture", Config = null, UIHints = new ThingUIHints() { IconURI = "/Content/img/icons/Generic/motion.png", }, }; thing.Ports = new List<Yodiwo.API.Plegma.Port>() { new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Tap", State = "false", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.GestureSensorModel_TapId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "0") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Touch", State = "false", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.GestureSensorModel_TouchId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "1") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "DoubleTap", State = "false", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.GestureSensorModel_DoubleTapId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "2") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Airwheel", State = "false", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.GestureSensorModel_AirwheelId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "3") }, new Yodiwo.API.Plegma.Port() { ioDirection = Yodiwo.API.Plegma.ioPortDirection.Output, Name = "Flick", State = "false", Type = Yodiwo.API.Plegma.ePortType.String, PortModelId = ModelTypeLibrary.GestureSensorModel_FlickId, PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", "4") }, }; GestureThing = thing = node.AddThing(thing); } #endregion //add things Things.Add(PositionThing); Things.Add(GestureThing); //create skywriter sensors PositionSensor positionsensor = new PositionSensor(trans); GestureSensor gesturesensor = new GestureSensor(trans); //update dictinaries Lookup.Add(PositionThing, positionsensor); Lookup.Add(GestureThing, gesturesensor); SkyWriterSensors.Add(PositionThing.Name, positionsensor); SkyWriterSensors.Add(GestureThing.Name, gesturesensor); //register events positionsensor.OnGetContinuousDatacb += p => OnGetPositionDatacb(positionsensor, p); gesturesensor.OnGetContinuousDatacb += p => OnGetGestureDatacb(gesturesensor, p); }
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 }