protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _pinDht = _gpio.OpenPin(DHT11_PIN, GpioSharingMode.Exclusive);
            _dht11  = new Dht11(_pinDht, GpioPinDriveMode.Input);

            _pinLed = _gpio.OpenPin(LED_PIN);
            _pinLed.SetDriveMode(GpioPinDriveMode.Output);
            _pinLed.Write(GpioPinValue.Low);

            _timer.Start();

            _startedAt = DateTimeOffset.Now;

            // Send IoT device info (once).
            if (_sendToCloud)
            {
                try {
                    await AzureIoTHub.SendDeviceToCloudMessageAsync(JsonConvert.SerializeObject(_deviceInfo));

                    _gridOffline.Visibility = Visibility.Collapsed;
                }
                catch (Exception ex) {
                    Debug.WriteLine("Problem sending to IoT Hub: " + ex.Message.ToString());
                    _gridOffline.Visibility = Visibility.Visible;
                }
            }
        }
        public MainPage()
        {
            this.InitializeComponent();

            // call the method to initialize variables and hardware components
            InitHardware();

            // set interval of timer to 1 second
            _dispatchTimer.Interval = TimeSpan.FromSeconds(1);

            // invoke a method at each tick (as per interval of your timer)
            _dispatchTimer.Tick += _dispatchTimer_Tick;

            // initialize pin (GPIO pin on which you have set your temperature sensor)
            _temperaturePin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);

            // create instance of a DHT11 
            _dhtInterface = new Dht11(_temperaturePin, GpioPinDriveMode.Input);

            // start the timer
            _dispatchTimer.Start();

            // set start date time
            _startedAt = DateTimeOffset.Now;
        }
Exemple #3
0
        public MainPage()
        {
            this.InitializeComponent();

            // call the method to initialize variables and hardware components
            InitHardware();

            // set interval of timer to 1 second
            _dispatchTimer.Interval = TimeSpan.FromSeconds(1);

            // invoke a method at each tick (as per interval of your timer)
            _dispatchTimer.Tick += _dispatchTimer_Tick;

            // initialize pin (GPIO pin on which you have set your temperature sensor)
            _temperaturePin = GpioController.GetDefault().OpenPin(2, GpioSharingMode.Exclusive);

            // create instance of a DHT11
            _dhtInterface = new Dht11(_temperaturePin, GpioPinDriveMode.Input);

            // start the timer
            _dispatchTimer.Start();

            // set start date time
            _startedAt = DateTimeOffset.Now;

            //Azure IoT Hub
            string iotHubUri = "neerajhome.azure-devices.net";
            string deviceId  = "RHTemp1";
            string deviceKey = "OW+MEyxprIUk/PW/Zw8hcNWAdrZis9PdzY0X69cbk5I=";

            deviceClient = DeviceClient.Create(iotHubUri,
                                               AuthenticationMethodFactory.
                                               CreateAuthenticationWithRegistrySymmetricKey(deviceId, deviceKey),
                                               TransportType.Http1);
        }
 public RpcDht(IDht dht, Node node) {
   LocalUseOnly = true;
   _bqs = new Cache(100);
   _node = node;
   _dht = dht;
   _node.Rpc.AddHandler("DhtClient", this);
 }
Exemple #5
0
        public MainPage()
        {
            this.InitializeComponent();
            var    iotDevice = new TpmDevice(0);
            string hubUri    = iotDevice.GetHostName();
            string deviceId  = iotDevice.GetDeviceId();
            string sasToken  = iotDevice.GetSASToken();

            deviceName = deviceId;

            deviceClient = DeviceClient.Create(hubUri,
                                               AuthenticationMethodFactory.CreateAuthenticationWithToken(deviceId, sasToken), TransportType.Mqtt);


            _timer.Interval = TimeSpan.FromSeconds(1);
            _timer.Tick    += _timer_Tick;

            GpioController controller = GpioController.GetDefault();

            if (controller != null)
            {
                _pin = GpioController.GetDefault().OpenPin(17, GpioSharingMode.Exclusive);
                _dht = new Dht11(_pin, GpioPinDriveMode.Input);
                _timer.Start();
                _startedAt = DateTimeOffset.Now;
            }
        }
        public MainPage()
        {
            this.InitializeComponent();

            // call the method to initialize variables and hardware components
            InitHardware();

            // set interval of timer to 1 second
            _dispatchTimer.Interval = TimeSpan.FromSeconds(1);

            // invoke a method at each tick (as per interval of your timer)
            _dispatchTimer.Tick += _dispatchTimer_Tick;

            // initialize pin (GPIO pin on which you have set your temperature sensor)
            _temperaturePin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);

            // create instance of a DHT11
            _dhtInterface = new Dht11(_temperaturePin, GpioPinDriveMode.Input);

            // start the timer
            _dispatchTimer.Start();

            // set start date time
            _startedAt = DateTimeOffset.Now;
        }
Exemple #7
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            _timer.Stop();

            // ***
            // *** Dispose the pin.
            // ***
            if (_pin != null)
            {
                _pin.Dispose();
                _pin = null;
            }

            // ***
            // *** Set the Dht object reference to null.
            // ***
            _dht = null;

            // ***
            // *** Stop the high CPU usage simulation.
            // ***
            CpuKiller.StopEmulation();

            base.OnNavigatedFrom(e);
        }
Exemple #8
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            var controller = GpioController.GetDefault();

            if (controller == null)
            {
                return;
            }

            sensorPin = controller.OpenPin(SENSOR_PIN_NUM, GpioSharingMode.Exclusive);
            dht       = new Dht22(sensorPin, GpioPinDriveMode.Input);

            ledPin = controller.OpenPin(LED_PIN_NUM, GpioSharingMode.Exclusive);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

            isRelayPin = controller.OpenPin(RELAY_PIN_NUM, GpioSharingMode.Exclusive);
            isRelayPin.SetDriveMode(GpioPinDriveMode.Output);

            registryManager = RegistryManager.CreateFromConnectionString(Config.ConnectionString);

            ReceiveDataFromAzure();

            timer.Start();
        }
Exemple #9
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // ***
            // *** Get a reference to the GPIO Controller.
            // ***
            var controller = await GpioController.GetDefaultAsync();

            // ***
            // *** Make sure the reference is valid (that e are connected to a device with
            // *** a GPIO Controller.
            // ***
            if (controller == null)
            {
                return;
            }

            // ***
            // *** Set up the data pin.
            // ***
            var dataPin = controller.OpenPin(DataPinNumber, GpioSharingMode.Exclusive);

            // ***
            // *** Create the sensor.
            // ***
            _sensor = new Dht11(dataPin);

            // ***
            // *** Start the timer.
            // ***
            _timer.Start();
        }
Exemple #10
0
        private async void ClickMe_Click(object sender, RoutedEventArgs e)
        {
            //HelloMessage.Text = "Hello, Windows 10 IoT Core!";
            GpioController controller = GpioController.GetDefault();

            if (controller != null)
            {
                _pin1 = GpioController.GetDefault().OpenPin(piN, GpioSharingMode.Exclusive);
                _pin1.SetDriveMode(GpioPinDriveMode.Input);

                _dht1 = new Dht11(_pin1, GpioPinDriveMode.Input);
            }

            DhtReading reading = new DhtReading();

            reading = await _dht1.GetReadingAsync().AsTask();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            while (stopwatch.Elapsed < TimeSpan.FromSeconds(60))
            {
                if (reading.IsValid)
                {
                    var Temperature   = reading.Temperature;
                    var Humidity      = reading.Humidity;
                    var messageDialog = new MessageDialog(string.Format("Temperature : {0} - Humidity : {1}", Temperature, Humidity));
                    Task.Delay(5000).Wait();
                    await messageDialog.ShowAsync();
                }

                stopwatch.Stop();
            }
        }
Exemple #11
0
        public override int Run(string[] remainingArguments)
        {
            CreateNode();
            switch(remainingArguments[0]){
            case "join":{
                var port = remainingArguments[1].Convert<int>();
                node.Connect(Environment.MachineName, port);
                dht = node.New<IDht>("System.Dht");
                dht.Join(new ActorId(remainingArguments[2] + ".localhost/System.Dht"));
            }break;

            case "put":{
                dht.Put(remainingArguments[1], remainingArguments[2]);
            }break;
            case "get":{
                Console.WriteLine(dht.Get(remainingArguments[1]));
            }break;
            }

            //			var dht = node.Proxy.New<IDht>();
            //			// join node
            //			dht.Put(new Resource("abc"), "def");
            //			Console.WriteLine("found " + dht.Get(new Resource("abc")));
            return 0;
        }
Exemple #12
0
        private void InittempSensor()
        {
            // call the method to initialize variables and hardware components
            InitHardware();

            // set interval of timer to 1 second
            _dispatchTimer.Interval = TimeSpan.FromSeconds(1);

            // invoke a method at each tick (as per interval of your timer)
            _dispatchTimer.Tick += _dispatchTimer_Tick;

            // initialize pin (GPIO pin on which you have set your temperature sensor)
            _temperaturePin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);

            // create instance of a DHT11
            _dhtInterface = new Dht11(_temperaturePin, GpioPinDriveMode.Input);

            // start the timer
            _dispatchTimer.Start();

            // set start date time
            _startedAt = DateTimeOffset.Now;

            //Azure IoT Hub
            string iotHubUri = "mondayiothub1.azure-devices.net";
            string deviceId  = "iot1";
            string deviceKey = "Dfdr5BaIf+0uJUMLa8YBcIe74fNpBvsQ7FayoQpRXXs=";

            deviceClient = DeviceClient.Create(iotHubUri,
                                               AuthenticationMethodFactory.
                                               CreateAuthenticationWithRegistrySymmetricKey(deviceId, deviceKey),
                                               TransportType.Http1);
        }
Exemple #13
0
        protected async Task <(double Temperature, double Humidity)> ReadTemperature(IDht device)
        {
            (double Temperature, double Humidity)returnValue = (0, 0);

            DhtReading reading = new DhtReading();

            reading = await device.GetReadingAsync().AsTask();

            if (reading.IsValid)
            {
                // ***
                // *** Get the values from the reading.
                // ***
                returnValue.Temperature = reading.Temperature;
                returnValue.Humidity    = reading.Humidity;
            }
            else
            {
                // ***
                // *** Show -1 so that it is evident there
                // *** is an error reading the device.
                // ***
                returnValue.Temperature = -1;
                returnValue.Humidity    = -1;
            }

            return(returnValue);
        }
Exemple #14
0
 public RpcDht(IDht dht, Node node) {
   LocalUseOnly = true;
   _channels = new Brunet.Collections.Cache(100);
   _node = node;
   _dht = dht;
   _node.Rpc.AddHandler("DhtClient", this);
 }
Exemple #15
0
 /// <summary>Initiates a RpcProxyHandler instance. It uses reflection for rpc call.
 /// Thus, it does not have to inherit IRpcHanler.This instance keeps Entry
 /// to keep track of key, value, and ttl</summary>
 /// <param name="node">node which is currently connected.</param>
 /// <param name="dht">IDht instance</param>
 public RpcDhtProxy(IDht dht, Node node)
 {
     _entries = new Dictionary <MemBlock, Dictionary <MemBlock, Entry> >();
     _rpc     = node.Rpc;
     _dht     = dht;
     _sync    = new Object();
     _rpc.AddHandler("RpcDhtProxy", this);
 }
Exemple #16
0
 private void InitHardware()
 {
     _dispatchTimer  = new DispatcherTimer();
     _temperaturePin = null;
     _dhtInterface   = null;
     _retryCount     = new List <int>();
     _startedAt      = DateTimeOffset.Parse("1/1/1");
 }
Exemple #17
0
 /// <summary>Initiates a RpcProxyHandler instance. It uses reflection for rpc call.
 /// Thus, it does not have to inherit IRpcHanler.This instance keeps Entry
 /// to keep track of key, value, and ttl</summary>
 /// <param name="node">node which is currently connected.</param>
 /// <param name="dht">IDht instance</param>
 public RpcDhtProxy(IDht dht, Node node)
 {
   _entries = new Dictionary<MemBlock, Dictionary<MemBlock, Entry>>();
   _rpc = node.Rpc;
   _dht = dht;
   _sync = new Object();
   _rpc.AddHandler("RpcDhtProxy", this);
 }
Exemple #18
0
 /**
 <summary>Create a DhtDns using the specified Dht object</summary>
 <param name="dht">A Dht object used to acquire name translations</param>
 */
 public DhtDns(MemBlock ip, MemBlock netmask, string name_server,
     bool forward_queries, IDht dht, String ipop_namespace) :
   base(ip, netmask, name_server, forward_queries)
 {
   _ipop_namespace = ipop_namespace;
   _dht = dht;
   _sync = new object();
 }
Exemple #19
0
 public RpcDht(IDht dht, Node node)
 {
     LocalUseOnly = true;
     _channels    = new Brunet.Collections.Cache(100);
     _node        = node;
     _dht         = dht;
     _node.Rpc.AddHandler("DhtClient", this);
 }
Exemple #20
0
 /**
  * <summary>Create a DhtDns using the specified Dht object</summary>
  * <param name="dht">A Dht object used to acquire name translations</param>
  */
 public DhtDns(MemBlock ip, MemBlock netmask, string name_server,
               bool forward_queries, IDht dht, String ipop_namespace) :
     base(ip, netmask, name_server, forward_queries)
 {
     _ipop_namespace = ipop_namespace;
     _dht            = dht;
     _sync           = new object();
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            pin    = GpioController.GetDefault().OpenPin(17, GpioSharingMode.Exclusive);
            sensor = new Dht11(pin, GpioPinDriveMode.Input);

            timer.Start();
        }
 /// <summary>Creates a DhtAddressResolver Object.</summary>
 /// <param name="dht">The dht object to use for dht interactions.</param>
 /// <param name="ipop_namespace">The ipop namespace where the dhcp server
 /// is storing names.</param>
 public DhtAddressResolver(IDht dht, string ipop_namespace)
 {
     _dht            = dht;
     _ipop_namespace = ipop_namespace;
     _cache          = new TimeBasedCache <MemBlock, Address>(CLEANUP_TIME_MS);
     _attempts       = new Dictionary <MemBlock, int>();
     _queued         = new Dictionary <MemBlock, bool>();
     _mapping        = new Dictionary <Channel, MemBlock>();
 }
Exemple #23
0
 /// <summary>Creates a DhtAddressResolver Object.</summary>
 /// <param name="dht">The dht object to use for dht interactions.</param>
 /// <param name="ipop_namespace">The ipop namespace where the dhcp server
 /// is storing names.</param>
 public DhtAddressResolver(IDht dht, string ipop_namespace)
 {
   _dht = dht;
   _ipop_namespace = ipop_namespace;
   _cache = new TimeBasedCache<MemBlock, Address>(CLEANUP_TIME_MS);
   _attempts = new Dictionary<MemBlock, int>();
   _queued = new Dictionary<MemBlock, bool>();
   _mapping = new Dictionary<Channel, MemBlock>();
 }
Exemple #24
0
        public static void Setup()
        {
            _pin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);
            _dht = new Dht11(_pin, GpioPinDriveMode.Input);

            _timer.Start();

            _startedAt = DateTimeOffset.Now;
        }
Exemple #25
0
        public static void Setup()
        {
            _pin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);
            _dht = new Dht11(_pin, GpioPinDriveMode.Input);

            _timer.Start();

            _startedAt = DateTimeOffset.Now;
        }
Exemple #26
0
 public ApplicationNode(StructuredNode node, IDht dht, RpcDhtProxy dht_proxy,
                        NCService ncservice, ProtocolSecurityOverlord security_overlord)
 {
     Node             = node;
     Dht              = dht;
     DhtProxy         = dht_proxy;
     NCService        = ncservice;
     SecurityOverlord = security_overlord;
 }
Exemple #27
0
 public ApplicationNode(StructuredNode node, IDht dht, RpcDhtProxy dht_proxy,
     NCService ncservice ,ProtocolSecurityOverlord security_overlord)
 {
   Node = node;
   Dht = dht;
   DhtProxy = dht_proxy;
   NCService = ncservice;
   SecurityOverlord = security_overlord;
 }
Exemple #28
0
 public ApplicationNode(StructuredNode node, IDht dht, RpcDhtProxy dht_proxy,
                        NCService ncservice, SecurityOverlord security_overlord, NodeConfig nc)
 {
     Config                   = nc;
     Node                     = node;
     Dht                      = dht;
     DhtProxy                 = dht_proxy;
     NCService                = ncservice;
     SecurityOverlord         = security_overlord;
     SymphonySecurityOverlord = security_overlord as SymphonySecurityOverlord;
 }
 /// <summary>Creates a DhtAddressResolver Object.</summary>
 /// <param name="dht">The dht object to use for dht interactions.</param>
 /// <param name="ipop_namespace">The ipop namespace where the dhcp server
 /// is storing names.</param>
 public DhtAddressResolver(IDht dht, string ipop_namespace)
 {
   _dht = dht;
   _ipop_namespace = ipop_namespace;
   _verified_cache = new TimeBasedCache<MemBlock, Address>(CLEANUP_TIME_MS);
   _incoming_cache = new TimeBasedCache<MemBlock, Address>(CLEANUP_TIME_MS);
   _attempts = new Dictionary<MemBlock, int>();
   _queued = new Dictionary<MemBlock, bool>();
   _mapping = new Dictionary<Channel, MemBlock>();
   _udp_client = new UdpClient("127.0.0.1", 55123);
 }
Exemple #30
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            _timer.Stop();

            _pin.Dispose();
            _pin = null;

            _dht11 = null;

            base.OnNavigatedFrom(e);
        }
Exemple #31
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            _timer.Stop();

            _pin.Dispose();
            _pin = null;

            _dht = null;

            base.OnNavigatedFrom(e);
        }
Exemple #32
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _pin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);
            _dht = new Dht11(_pin, GpioPinDriveMode.Input);

            _timer.Start();

            _startedAt = DateTimeOffset.Now;
        }
Exemple #33
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _pin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);
            _dht11 = new Dht11(_pin, GpioPinDriveMode.Input);

            _timer.Start();

            _startedAt = DateTimeOffset.Now;
        }
Exemple #34
0
 public ApplicationNode(StructuredNode node, IDht dht, RpcDhtProxy dht_proxy,
     NCService ncservice, SecurityOverlord security_overlord, NodeConfig nc)
 {
   Config = nc;
   Node = node;
   Dht = dht;
   DhtProxy = dht_proxy;
   NCService = ncservice;
   SecurityOverlord = security_overlord;
   SymphonySecurityOverlord = security_overlord as SymphonySecurityOverlord;
 }
Exemple #35
0
        public MainPage()
        {
            this.InitializeComponent();

            dhtPin = GpioController.GetDefault().OpenPin(DHTPIN, GpioSharingMode.Exclusive);
            dht    = new Dht11(dhtPin, GpioPinDriveMode.Input);
            sensorTimer.Interval = TimeSpan.FromSeconds(10);
            sensorTimer.Tick    += sensorTimer_Tick;

            sensorTimer.Start();
        }
        // method to initialize variables and hardware components
        private void InitHardware()
        {
            _dispatchTimer = new DispatcherTimer();

            _temperaturePin = null;

            _dhtInterface = null;

            _retryCount = new List<int>();

            _startedAt = DateTimeOffset.Parse("1/1/1");
        }
Exemple #37
0
        public void InitDHT22()
        {
            dhtlock = new ReaderWriterLockSlim();
            GpioController controller = GpioController.GetDefault();

            if (controller != null)
            {
                OneWirePin = GpioController.GetDefault().OpenPin(DHTPIN, GpioSharingMode.Exclusive);
                _dht       = new Dht22(OneWirePin, GpioPinDriveMode.Input);
                _startedAt = DateTimeOffset.Now;
            }
        }
Exemple #38
0
    /// <summary>Creates a DhtAddressResolver Object.</summary>
    /// <param name="dht">The dht object to use for dht interactions.</param>
    /// <param name="ipop_namespace">The ipop namespace where the dhcp server
    /// is storing names.</param>
    public DhtAddressResolver(IDht dht, string ipop_namespace)
    {
      _dht = dht;
      _ipop_namespace = ipop_namespace;

      _last_results = new Dictionary<MemBlock, Address>();
      _results = new Dictionary<MemBlock, Address>();
      _attempts = new Dictionary<MemBlock, int>();
      _queued = new Dictionary<MemBlock, bool>();
      _mapping = new Dictionary<Channel, MemBlock>();
      _fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(CleanUp, CLEANUP_TIME_MS, CLEANUP_TIME_MS / 10);
      _stopped = 0;
    }
Exemple #39
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            _timer.Stop();

            _pin.Dispose();
            _pin = null;

            _dht = null;

			CpuKiller.StopEmulation();

			base.OnNavigatedFrom(e);
        }
Exemple #40
0
        /// <summary>
        /// Constructs a new <see cref="BootstrapperNode" />.
        /// </summary>
        public BootstrapperNode()
        {
            Application.Start();

            if (_node != null)
            {
                return;
            }

            try
            {
                InitializeLock.Wait();

                if (_node != null)
                {
                    return;
                }

                Node node = new Node();
                node.Initialize();
                _node         = node;
                _bootstrapper = this;

                if (_node != null && _node.IsInitialized)
                {
                    Log.Info("Initialized successfully.");
                }
                else
                {
                    Log.Error("Initialization failed.");
                }
            }
            catch (Exception ex)
            {
                Log.Error("Initialization failed.");

                if (ex is AddressAlreadyInUseException)
                {
                    Log.Warn("A Kademlia.Bootstrapper is already running on this machine.");
                }
                else
                {
                    Log.Error(ex);
                    throw;
                }
            }
            finally
            {
                InitializeLock.Release();
            }
        }
Exemple #41
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

            timer.Stop();

            sensorPin?.Dispose();
            sensorPin = null;

            ledPin?.Dispose();
            ledPin = null;

            dht = null;
        }
Exemple #42
0
        // method to initialize variables and hardware components
        private void InitHardware()
        {
            _dispatchTimer = new DispatcherTimer();

            _temperaturePin = null;

            _dhtInterface = null;

            _retryCount = new List <int>();

            _startedAt = DateTimeOffset.Parse("1/1/1");

            lcd = new displayI2C(DEVICE_I2C_ADDRESS, I2C_CONTROLLER_NAME, RS, RW, EN, D4, D5, D6, D7, BL);
            //lcd.createSymbol(new byte[] { 0x00, 0x00, 0x0A, 0x00, 0x11, 0x0E, 0x00, 0x00 }, 0x00);
            lcd.init();
        }
Exemple #43
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

			_pin = GpioController.GetDefault().OpenPin(17, GpioSharingMode.Exclusive);
            _dht = new Dht22(_pin, GpioPinDriveMode.Input);

            _timer.Start();

            _startedAt = DateTimeOffset.Now;

			// ***
			// *** Uncomment to simulate heavy CPU usage
			// ***
			//CpuKiller.StartEmulation();
        }
Exemple #44
0
        public void StopDHT22()
        {
            // ***
            // *** Dispose the pin.
            // ***
            if (OneWirePin != null)
            {
                OneWirePin.Dispose();
                OneWirePin = null;
            }

            // ***
            // *** Set the Dht object reference to null.
            // ***
            _dht = null;
        }
        DhtReading reading;// = new DhtReading();


        public HomeScreen()
        {
            this.InitializeComponent();
            _main = this;

            var _pin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);
            _dht = new Dht11(_pin, GpioPinDriveMode.Input);
            

            _timer.Interval = TimeSpan.FromSeconds(1);
            _timer.Tick += _timer_Tick;


            GetNistTime();
            getinitreadingtemp();
        }
Exemple #46
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _pin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);
            _dht = new Dht11(_pin, GpioPinDriveMode.Input);

            _timer.Start();

            _startedAt = DateTimeOffset.Now;

            // ***
            // *** Uncomment to simulate heavy CPU usage
            // ***
            //CpuKiller.StartEmulation();
        }
Exemple #47
0
        DhtReading reading;// = new DhtReading();


        public HomeScreen()
        {
            this.InitializeComponent();
            _main = this;

            var _pin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);

            _dht = new Dht11(_pin, GpioPinDriveMode.Input);


            _timer.Interval = TimeSpan.FromSeconds(1);
            _timer.Tick    += _timer_Tick;


            GetNistTime();
            getinitreadingtemp();
        }
Exemple #48
0
    /// <summary>Uses the Dht for the bootstrap problem.</summary>
    /// <param name="node">The node needing remote tas.</param>
    /// <param name="dht">The dht for the shared overlay.</param>
    /// <param name="dht_proxy">A dht proxy for the shared overlay.</param>
    public DhtDiscovery(StructuredNode node, IDht dht, string shared_namespace,
        RpcDhtProxy dht_proxy) :
      base(node)
    {
      _dht = dht;
      _dht_proxy = dht_proxy;
      _node = node;
      _shared_namespace = shared_namespace;
      string skey = "PrivateOverlay:" + node.Realm;
      byte[] bkey = Encoding.UTF8.GetBytes(skey);
      _p2p_address = node.Address.ToMemBlock();
      _private_dht_key = MemBlock.Reference(bkey);

      _ongoing = 0;
      _steady_state = 0;
      _dht_proxy.Register(_private_dht_key, _p2p_address, PUT_DELAY_S);
    }
Exemple #49
0
        /// <summary>Uses the Dht for the bootstrap problem.</summary>
        /// <param name="node">The node needing remote tas.</param>
        /// <param name="dht">The dht for the shared overlay.</param>
        /// <param name="dht_proxy">A dht proxy for the shared overlay.</param>
        public DhtDiscovery(StructuredNode node, IDht dht, string shared_namespace,
                            RpcDhtProxy dht_proxy) :
            base(node)
        {
            _dht              = dht;
            _dht_proxy        = dht_proxy;
            _node             = node;
            _shared_namespace = shared_namespace;
            string skey = "PrivateOverlay:" + node.Realm;

            byte[] bkey = Encoding.UTF8.GetBytes(skey);
            _p2p_address     = node.Address.ToMemBlock();
            _private_dht_key = MemBlock.Reference(bkey);

            _ongoing      = 0;
            _steady_state = 0;
            _dht_proxy.Register(_private_dht_key, _p2p_address, PUT_DELAY_S);
        }
Exemple #50
0
        public static DHCPConfig GetDHCPConfig(IDht dht, string ipop_namespace)
        {
            byte[] ns_key = Encoding.UTF8.GetBytes("dhcp:" + ipop_namespace);
              Hashtable[] results = dht.Get(ns_key);

              if(results.Length == 0) {
            throw new Exception("Namespace does not exist: " + ipop_namespace);
              }

              string result = Encoding.UTF8.GetString((byte[]) results[0]["value"]);

              XmlSerializer serializer = new XmlSerializer(typeof(DHCPConfig));
              TextReader stringReader = new StringReader(result);
              DHCPConfig dhcp_config = (DHCPConfig) serializer.Deserialize(stringReader);
              if(!ipop_namespace.Equals(dhcp_config.Namespace)) {
            throw new Exception(String.Format("Namespace mismatch, expected {0}, got {1}",
              ipop_namespace, dhcp_config.Namespace));
              }
              return dhcp_config;
        }
Exemple #51
0
 public static DhtDhcpServer GetDhtDhcpServer(IDht dht, string ipop_namespace, bool enable_multicast) {
   DHCPConfig config = GetDhcpConfig(dht, ipop_namespace);
   return new DhtDhcpServer(dht, config, enable_multicast);
 }
Exemple #52
0
 /**
 <summary>Create a DhtDNS using the specified Dht object</summary>
 <param name="dht">A Dht object used to acquire name translations</param>
 */
 public DhtDNS(MemBlock ip, MemBlock netmask, IDht dht, String ipop_namespace, string dns_server, bool RA)
     : base(ip, netmask, dns_server, RA)
 {
     _ipop_namespace = ipop_namespace;
       _dht = dht;
 }
   /**
    * Constructor.
    * @param dht the dht object.
    * @param user the local user object.
    * @param certData the local certificate data.
    */
   public SocialNetworkProvider(IDht dht, SocialUser user, byte[] certData,
 BlockingQueue queue, string jabber_port)
   {
       _local_user = user;
         _dht = dht;
         _queue = queue;
         _providers = new Dictionary<string, IProvider>();
         _networks = new Dictionary<string,ISocialNetwork>();
         _local_cert_data = certData;
         _friends = new Dictionary<string, List<string>>();
         _certificates = new List<byte[]>();
         _jabber_port = jabber_port;
         RegisterBackends();
   }
Exemple #54
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     var gpio = GpioController.GetDefault();
     ledpin = gpio.OpenPin(LED_PIN);
     _pin = gpio.OpenPin(4, GpioSharingMode.Exclusive);
     _dht11 = new Dht11(_pin, GpioPinDriveMode.Input);
     _timer.Start();
 }
 /**
 <summary>Creates a DhtAddressResolver Object.</summary>
 <param name="dht">The dht object to use for dht interactions.</param>
 <param name="ipop_namespace">The ipop namespace where the dhcp server
 is storing names.</param>
 */
 public DhtAddressResolver(IDht dht, string ipop_namespace)
 {
     _dht = dht;
       _ipop_namespace = ipop_namespace;
 }
Exemple #56
0
    /// <summary>Creates a Brunet.Node, the resulting node will be available in
    /// the class as _node.</summary>
    /// <remarks>The steps to creating a node are first constructing it with a
    /// namespace, optionally adding local ip addresses to bind to, specifying
    /// local end points, specifying remote end points, and finally registering
    /// the dht.</remarks>
    public virtual void CreateNode() {
      AHAddress address = null;
      try {
        address = (AHAddress) AddressParser.Parse(_node_config.NodeAddress);
      } catch {
        address = Utils.GenerateAHAddress();
      }

      _node = new StructuredNode(address, _node_config.BrunetNamespace);
      IEnumerable addresses = IPAddresses.GetIPAddresses(_node_config.DevicesToBind);

      if(_node_config.Security.Enabled) {
        if(_node_config.Security.SelfSignedCertificates) {
          SecurityPolicy.SetDefaultSecurityPolicy(SecurityPolicy.DefaultEncryptor,
              SecurityPolicy.DefaultAuthenticator, true);
        }

        byte[] blob = null;
        using(FileStream fs = File.Open(_node_config.Security.KeyPath, FileMode.Open)) {
          blob = new byte[fs.Length];
          fs.Read(blob, 0, blob.Length);
        }

        RSACryptoServiceProvider rsa_private = new RSACryptoServiceProvider();
        rsa_private.ImportCspBlob(blob);

        CertificateHandler ch = new CertificateHandler(_node_config.Security.CertificatePath);
        _bso = new ProtocolSecurityOverlord(_node, rsa_private, _node.Rrm, ch);
        _bso.Subscribe(_node, null);

        _node.GetTypeSource(SecurityOverlord.Security).Subscribe(_bso, null);
        _node.HeartBeatEvent += _bso.Heartbeat;

        if(_node_config.Security.TestEnable) {
          blob = rsa_private.ExportCspBlob(false);
          RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
          rsa_pub.ImportCspBlob(blob);
          CertificateMaker cm = new CertificateMaker("United States", "UFL", 
              "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
              "brunet:node:abcdefghijklmnopqrs");
          Certificate cacert = cm.Sign(cm, rsa_private);

          cm = new CertificateMaker("United States", "UFL", 
              "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
              address.ToString());
          Certificate cert = cm.Sign(cacert, rsa_private);
          ch.AddCACertificate(cacert.X509);
          ch.AddSignedCertificate(cert.X509);
        }
      }

      EdgeListener el = null;
      foreach(NodeConfig.EdgeListener item in _node_config.EdgeListeners) {
        int port = item.port;
        if(item.type == "tcp") {
          try {
            el = new TcpEdgeListener(port, addresses);
          }
          catch {
            el = new TcpEdgeListener(0, addresses);
          }
        } else if(item.type == "udp") {
          try {
            el = new UdpEdgeListener(port, addresses);
          }
          catch {
            el = new UdpEdgeListener(0, addresses);
          }
        } else if(item.type == "function") {
          port = port == 0 ? (new Random()).Next(1024, 65535) : port;
          el = new FunctionEdgeListener(port, 0, null);
        } else {
          throw new Exception("Unrecognized transport: " + item.type);
        }
        if(_node_config.Security.SecureEdgesEnabled) {
          el = new SecureEdgeListener(el, _bso);
        }
        _node.AddEdgeListener(el);
      }

      ArrayList RemoteTAs = null;
      if(_node_config.RemoteTAs != null) {
        RemoteTAs = new ArrayList();
        foreach(String ta in _node_config.RemoteTAs) {
          RemoteTAs.Add(TransportAddressFactory.CreateInstance(ta));
        }
        _node.RemoteTAs = RemoteTAs;
      }

      ITunnelOverlap ito = null;
      /*
      if(_node_config.NCService.Enabled) {
        _ncservice = new NCService(_node, _node_config.NCService.Checkpoint);

        if (_node_config.NCService.OptimizeShortcuts) {
          _node.Ssco.TargetSelector = new VivaldiTargetSelector(_node, _ncservice);
        }
        ito = new NCTunnelOverlap(_ncservice);
      } else {
        ito = new SimpleTunnelOverlap();
      }
      */
      el = new Tunnel.TunnelEdgeListener(_node, ito);
      if(_node_config.Security.SecureEdgesEnabled) {
        _node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
        el = new SecureEdgeListener(el, _bso);
      }
      _node.AddEdgeListener(el);


      new TableServer(_node);
      _dht = new Dht(_node, 3, 20);
      _dht_proxy = new RpcDhtProxy(_dht, _node);
    }
Exemple #57
0
 /**
 <summary>Creates a DhtDhcpLeaseController for a specific namespace</summary>
 <param name="dht">The dht object use to store lease information.</param>
 <param name="config">The DHCPConfig used to define the Lease
 parameters.</param>
 <param name="EnableMulticast">Defines if Multicast is to be enabled during
 the lease.</param>
 */
 public DhtDhcpServer(IDht dht, DHCPConfig config, bool EnableMulticast) :
   base(config)
 {
   _dht = dht;
   _multicast = EnableMulticast;
 }
 public static void SetupDTH11()
 {
     _pin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);
     _dht = new Dht11(_pin, GpioPinDriveMode.Input);
 }
Exemple #59
0
    /**
    <summary>Creates a Brunet.Node, the resulting node will be available in
    the class as _node.</summary>
    <remarks>The steps to creating a node are first constructing it with a
    namespace, optionally adding local ip addresses to bind to, specifying
    local end points, specifying remote end points, and finally registering
    the dht.</remarks>
    */
    public virtual void CreateNode(string type) {
      NodeConfig node_config = null;
      StructuredNode current_node = null;
      AHAddress address = null;
      ProtocolSecurityOverlord bso;

      if (type == "cache") {
        node_config = _c_node_config; //Node configuration file: the description of service that node provides
        address = (AHAddress) AddressParser.Parse(node_config.NodeAddress);
        current_node = new StructuredNode(address, node_config.BrunetNamespace); // DeetooNode consists of two Structured Nodes
        bso = _c_bso;
      }
      else if ( type == "query" ) {
        node_config = _q_node_config;
        address = (AHAddress) AddressParser.Parse(node_config.NodeAddress);
        current_node = new StructuredNode(address, node_config.BrunetNamespace);
        bso = _q_bso;
      }
      else {
        throw new Exception("Unrecognized node type: " + type);
      }
      IEnumerable addresses = IPAddresses.GetIPAddresses(node_config.DevicesToBind);

      if(node_config.Security.Enabled) {
        if(node_config.Security.SelfSignedCertificates) {
          SecurityPolicy.SetDefaultSecurityPolicy(SecurityPolicy.DefaultEncryptor,
              SecurityPolicy.DefaultAuthenticator, true);
        }

        byte[] blob = null;
        using(FileStream fs = File.Open(node_config.Security.KeyPath, FileMode.Open)) {
          blob = new byte[fs.Length];
          fs.Read(blob, 0, blob.Length);
        }

        RSACryptoServiceProvider rsa_private = new RSACryptoServiceProvider();
        rsa_private.ImportCspBlob(blob);

        CertificateHandler ch = new CertificateHandler(node_config.Security.CertificatePath);
        bso = new ProtocolSecurityOverlord(current_node, rsa_private, current_node.Rrm, ch);
        bso.Subscribe(current_node, null);

        current_node.GetTypeSource(SecurityOverlord.Security).Subscribe(bso, null);
        current_node.HeartBeatEvent += bso.Heartbeat;

        if(node_config.Security.TestEnable) {
          blob = rsa_private.ExportCspBlob(false);
          RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
          rsa_pub.ImportCspBlob(blob);
          CertificateMaker cm = new CertificateMaker("United States", "UFL", 
              "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
              "brunet:node:abcdefghijklmnopqrs");
          Certificate cacert = cm.Sign(cm, rsa_private);

          cm = new CertificateMaker("United States", "UFL", 
              "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
              address.ToString());
          Certificate cert = cm.Sign(cacert, rsa_private);
          ch.AddCACertificate(cacert.X509);
          ch.AddSignedCertificate(cert.X509);
        }
      }

      EdgeListener el = null;
      foreach(NodeConfig.EdgeListener item in node_config.EdgeListeners) {
        int port = item.port;
        if (item.type =="tcp") {
          try {
            el = new TcpEdgeListener(port, addresses);
          }
          catch {
            el = new TcpEdgeListener(0, addresses);
          }
        }
        else if (item.type == "udp") {
          try {
            el = new UdpEdgeListener(port, addresses);
          }
          catch {
            el = new UdpEdgeListener(0, addresses);
          }
        }
        else if(item.type == "function") {
          port = port == 0 ? (new Random()).Next(1024, 65535) : port;
          el = new FunctionEdgeListener(port, 0, null);
        }
        else {
          throw new Exception("Unrecognized transport: " + item.type);
        }
        if (node_config.Security.SecureEdgesEnabled) {
          el = new SecureEdgeListener(el, bso);
        }
        current_node.AddEdgeListener(el);
      }

      ArrayList RemoteTAs = null;
      if(node_config.RemoteTAs != null) {
        RemoteTAs = new ArrayList();
        foreach(String ta in node_config.RemoteTAs) {
          RemoteTAs.Add(TransportAddressFactory.CreateInstance(ta));
        }
        current_node.RemoteTAs = RemoteTAs;
      }
      ITunnelOverlap ito = null;
      ito = new SimpleTunnelOverlap();

      el = new Tunnel.TunnelEdgeListener(current_node, ito);
      if(node_config.Security.SecureEdgesEnabled) {
        current_node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
        el = new SecureEdgeListener(el, bso);
      }      
      current_node.AddEdgeListener(el);

      new TableServer(current_node);
      if (type == "cache") {
        _c_dht = new Dht(current_node, 3, 20);
        _c_dht_proxy = new RpcDhtProxy(_c_dht, current_node);
        _cs = new CacheList(current_node);
	//_cll = new ClusterList(current_node);
        //current_node.MapReduce.SubscribeTask(new MapReduceClusterCache(current_node, _cll));
        current_node.MapReduce.SubscribeTask(new MapReduceCache(current_node,_cs));
        Console.WriteLine("MapReduceCacheTask is subscribed at {0}", current_node.Address);
        _c_node = current_node;
      }
      else {
        _q_dht = new Dht(current_node, 3, 20);
        _q_dht_proxy = new RpcDhtProxy(_c_dht, current_node);
        CacheList q_cs = new CacheList(current_node);
        //current_node.MapReduce.SubscribeTask(new MapReduceClusterQuery(current_node, _cll));
        current_node.MapReduce.SubscribeTask(new MapReduceQuery(current_node,_cs));
        Console.WriteLine("MapReduceQueryTask is subscribed at {0}", current_node.Address);
        _q_node = current_node;
      }
    }
Exemple #60
0
 /**
 <summary>Create a DhtDNS using the specified Dht object</summary>
 <param name="dht">A Dht object used to acquire name translations</param>
 */
 public DhtDNS(MemBlock ip, MemBlock netmask, IDht dht, String ipop_namespace)
     : base(ip, netmask)
 {
     _ipop_namespace = ipop_namespace;
       _dht = dht;
 }