async void Setup() { try { if (!IsConnected) { if (s_deviceClient != null) { s_deviceClient.Dispose(); } // Connect to the IoT hub using the MQTT protocol s_deviceClient = DeviceClient.CreateFromConnectionString(s_connectionString, TransportType.Mqtt); s_deviceClient.SetMethodHandlerAsync("DoAction", DoAction, null).Wait(); //SendDeviceToCloudMessagesAsync(); BtnPlay.Click += (a, b) => { PlaySound("monster.mp3"); }; this.hat = await GIS.FEZHAT.CreateAsync(); this.hat.S1.SetLimits(500, 2400, 0, 180); this.hat.S2.SetLimits(500, 2400, 0, 180); IsConnected = true; } if (client == null) { client = new HttpClient(); } } catch (Exception ex) { Console.WriteLine(ex); } }
private async void Setup() { MqttTxt.Text = "Init Hat"; this.hat = await GIS.FEZHAT.CreateAsync(); this.hat.S1.SetLimits(500, 2400, 0, 180); this.hat.S2.SetLimits(500, 2400, 0, 180); this.timer2 = new DispatcherTimer(); this.timer2.Interval = TimeSpan.FromSeconds(3); this.timer2.Tick += Timer2_Tick; this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(100); this.timer.Tick += this.OnTick; this.timer.Start(); this.hat.D2.Color = GIS.FEZHAT.Color.Black; this.hat.D3.Color = GIS.FEZHAT.Color.Black; MqttTxt.Text = "Init Mqtt"; //mqtt if (client == null) { // create client instance MQTT_BROKER_ADDRESS = "cloud.makestro.com"; client = new MqttClient(MQTT_BROKER_ADDRESS); string clientId = Guid.NewGuid().ToString(); client.Connect(clientId, "mifmasterz", "123qweasd"); SubscribeMessage(); MqttTxt.Text = "Mqtt ready"; } }
private async void Setup() { this.hat = await GIS.FEZHAT.CreateAsync(); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(1500); this.timer.Tick += this.OnTick; this.timer.Start(); }
private async void Setup() { sensorTimer.Interval = TimeSpan.FromSeconds(sensorInterval); sensorTimer.Tick += sensorTimer_Tick; flashTimer.Interval = TimeSpan.FromSeconds(flashInterval); flashTimer.Tick += flashTimer_Tick; this.hat = await GIS.FEZHAT.CreateAsync(); //deviceClient = DeviceClient.CreateFromConnectionString(IOTHUBCONNECTIONSTRING); //ReceiveCommands(); sensorTimer.Start(); readingsStartedAt = DateTimeOffset.Now; }
private async void Setup() { this.hat = await GIS.FEZHAT.CreateAsync(); this.hat.D2.Color = GIS.FEZHAT.Color.Black; this.hat.D3.Color = GIS.FEZHAT.Color.Black; //mqtt if (client == null) { // create client instance MQTT_BROKER_ADDRESS = "cloud.makestro.com"; client = new MqttClient(MQTT_BROKER_ADDRESS); string clientId = Guid.NewGuid().ToString(); client.Connect(clientId, "mifmasterz", "123qweasd"); SubscribeMessage(); } }
private async void Setup() { WriteLog("Device Setup is begin..\n"); deviceClient = DeviceClient.CreateFromConnectionString(DeviceConn, TransportType.Mqtt); this.hat = await GIS.FEZHAT.CreateAsync(); this.hat.S1.SetLimits(500, 2400, 0, 180); this.hat.S2.SetLimits(500, 2400, 0, 180); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(5000); this.timer.Tick += this.OnTick; this.timer.Start(); ReceiveC2dAsync(); //Task RecThread = new Task(new Action(ReceiveC2dAsync)); //RecThread.Start(); }
private async void Setup() { this.hat = await GIS.FEZHAT.CreateAsync(); // Motors typically require a frequency in excess of 10KHz // Servos typically require 50Hz. this.hat.S1.SetLimits(500, 2400, 0, 180); this.hat.S2.SetLimits(500, 2400, 0, 180); //Other sensors Debug.WriteLine($"Light: {this.hat.GetLightLevel()}"); Debug.WriteLine($"Temp: {this.hat.GetTemperature()}"); double x, y, z; this.hat.GetAcceleration(out x, out y, out z); Debug.WriteLine($"Accel: ({x:N2}, {y:N2}, {z:N2})"); }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { if (Guid.Empty == MSIoTKiTHoLJP.IoTHoLConfig.DeviceID) { FixDeviceId(); if (deviceId == "minwinpc") { Debug.Write("Please set deviceID or unique machine name"); throw new ArgumentOutOfRangeException("Please set deviceID or unique machine name"); } } else { deviceId = MSIoTKiTHoLJP.IoTHoLConfig.DeviceID.ToString(); } tbDeviceId.Text = deviceId.ToString(); fezHat = await GIS.FEZHAT.CreateAsync(); fezHat.D2.TurnOff(); fezHat.D3.TurnOff(); try { var result = await TryConnect(); if (result) { await InitializeUpload(); } geolocator = new Windows.Devices.Geolocation.Geolocator(); geolocator.PositionChanged += Geolocator_PositionChanged; } catch (Exception ex) { Debug.WriteLine(ex.Message); } lastSensorReading = new List <SensorReadingBuffer>(); measureTimer = new DispatcherTimer(); measureTimer.Interval = TimeSpan.FromMilliseconds(measureIntervalMSec); measureTimer.Tick += MeasureTimer_Tick; measureTimer.Start(); }
async void Setup() { try { if (!IsConnected) { /* * if (s_deviceClient != null) * { * s_deviceClient.Dispose(); * } * // Connect to the IoT hub using the MQTT protocol * s_deviceClient = DeviceClient.CreateFromConnectionString(s_connectionString, TransportType.Mqtt); * s_deviceClient.SetMethodHandlerAsync("DoAction", DoAction, null).Wait(); */ //SendDeviceToCloudMessagesAsync(); SetupMqtt(); BtnPlay.Click += (a, b) => { PlaySound("monster.mp3"); }; this.hat = await GIS.FEZHAT.CreateAsync(); this.hat.S1.SetLimits(500, 2400, 0, 180); this.hat.S2.SetLimits(500, 2400, 0, 180); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(10000); //10 minutes this.timer.Tick += this.OnTick; this.timer.Start(); IsConnected = true; } if (client == null) { client = new HttpClient(); } } catch (Exception ex) { Console.WriteLine(ex); } }
async void Setup() { try { if (client == null) { client = new HttpClient(); } /* * if (s_deviceClient != null) * { * s_deviceClient.Dispose(); * } * // Connect to the IoT hub using the MQTT protocol * s_deviceClient = DeviceClient.CreateFromConnectionString(s_connectionString, TransportType.Mqtt); * s_deviceClient.SetMethodHandlerAsync("DoAction", DoAction, null).Wait(); */ //SendDeviceToCloudMessagesAsync(); SetupMqtt(); CheckInternet(); TxtIpAddress.Text = GetLocalIp(); generateJoke(); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(10000); //10 minutes this.timer.Tick += this.OnTick; this.timer.Start(); this.hat = await GIS.FEZHAT.CreateAsync(); this.hat.S1.SetLimits(500, 2400, 0, 180); this.hat.S2.SetLimits(500, 2400, 0, 180); } catch (Exception ex) { Console.WriteLine(ex); } }
/// <summary> /// Creates a new instance of the FEZ HAT. /// </summary> /// <returns>The new instance.</returns> public static async Task <FEZHAT> CreateAsync() { var gpioController = GpioController.GetDefault(); var i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector(FEZHAT.I2cDeviceName)))[0]; var hat = new FEZHAT(); hat.accelerometer = new MMA8453(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(MMA8453.GetAddress(false)))); hat.analog = new ADS7830(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); hat.pwm = new PCA9685(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true))), gpioController.OpenPin(13)); hat.pwm.OutputEnabled = true; hat.pwm.Frequency = 1500; hat.dio16 = gpioController.OpenPin(16); hat.dio26 = gpioController.OpenPin(26); hat.dio24 = gpioController.OpenPin(24); hat.dio18 = gpioController.OpenPin(18); hat.dio22 = gpioController.OpenPin(22); hat.dio16.SetDriveMode(GpioPinDriveMode.Input); hat.dio26.SetDriveMode(GpioPinDriveMode.Input); hat.dio24.SetDriveMode(GpioPinDriveMode.Output); hat.dio18.SetDriveMode(GpioPinDriveMode.Input); hat.dio22.SetDriveMode(GpioPinDriveMode.Input); hat.motorEnable = gpioController.OpenPin(12); hat.motorEnable.SetDriveMode(GpioPinDriveMode.Output); hat.motorEnable.Write(GpioPinValue.High); hat.MotorA = new Motor(hat.pwm, 14, 27, 23); hat.MotorB = new Motor(hat.pwm, 13, 6, 5); hat.D2 = new RgbLed(hat.pwm, 1, 0, 2); hat.D3 = new RgbLed(hat.pwm, 4, 3, 15); hat.S1 = new Servo(hat.pwm, 9); hat.S2 = new Servo(hat.pwm, 10); return(hat); }
private async void Setup() { var hubConnection = new HubConnection(signalRHub); var hubProxy = hubConnection.CreateHubProxy(signalRHubProxy); hubProxy.On <string>("toDevice", HandleEvent); hubConnection.Start().Wait(); _connectionid = hubConnection.ConnectionId; // chat.Invoke<string>("Register", _piID); this.hat = await GIS.FEZHAT.CreateAsync(); this.hat.S1.SetLimits(500, 2400, 0, 180); this.hat.S2.SetLimits(500, 2400, 0, 180); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(100); this.timer.Tick += Timer_Tick; this.timer.Start(); }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { if (Guid.Empty == MSIoTKiTHoLJP.IoTHoLConfig.DeviceID) { FixDeviceId(); if (deviceId == "minwinpc") { Debug.Write("Please set deviceID or unique machine name"); throw new ArgumentOutOfRangeException("Please set deviceID or unique machine name"); } } else { deviceId = MSIoTKiTHoLJP.IoTHoLConfig.DeviceID.ToString(); } tbDeviceId.Text = deviceId.ToString(); fezHat = await GIS.FEZHAT.CreateAsync(); fezHat.D2.TurnOff(); fezHat.D3.TurnOff(); try { var result = await TryConnect(); if (result) { await InitializeUpload(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } lastSensorReading = new List<SensorReadingBuffer>(); measureTimer = new DispatcherTimer(); measureTimer.Interval = TimeSpan.FromMilliseconds(measureIntervalMSec); measureTimer.Tick += MeasureTimer_Tick; measureTimer.Start(); }
private async void SetupHardware() { this.hat = await GIS.FEZHAT.CreateAsync(); this.hat.DIO24On = true; }
private async void Setup() { this.hat = await GIS.FEZHAT.CreateAsync(); //this.hat.S1.SetLimits(500, 2400, 0, 180); //this.hat.S2.SetLimits(500, 2400, 0, 180); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(100); this.timer.Start(); Mobil = new MobilRemote(); this.timer.Tick += (a, b) => { /* * double x, y, z; * * this.hat.GetAcceleration(out x, out y, out z); * * this.LightTextBox.Text = this.hat.GetLightLevel().ToString("P2"); * this.TempTextBox.Text = this.hat.GetTemperature().ToString("N2"); * this.AccelTextBox.Text = $"({x:N2}, {y:N2}, {z:N2})"; * this.Button18TextBox.Text = this.hat.IsDIO18Pressed().ToString(); * this.Button22TextBox.Text = this.hat.IsDIO22Pressed().ToString(); * this.AnalogTextBox.Text = this.hat.ReadAnalog(GIS.FEZHAT.AnalogPin.Ain1).ToString("N2"); */ if (isNavigating) { return; } isNavigating = true; this.hat.D2.Color = GIS.FEZHAT.Color.Black; this.hat.D3.Color = GIS.FEZHAT.Color.Black; switch (Mobil.Arah) { case MobilRemote.ArahJalan.Maju: this.hat.MotorA.Speed = 1.0; this.hat.MotorB.Speed = 1.0; this.hat.D2.Color = GIS.FEZHAT.Color.Green; this.hat.D3.Color = GIS.FEZHAT.Color.Green; break; case MobilRemote.ArahJalan.Mundur: this.hat.MotorA.Speed = -1.0; this.hat.MotorB.Speed = -1.0; this.hat.D2.Color = GIS.FEZHAT.Color.Yellow; this.hat.D3.Color = GIS.FEZHAT.Color.Yellow; break; case MobilRemote.ArahJalan.Kiri: this.hat.MotorA.Speed = -0.7; this.hat.MotorB.Speed = 0.7; this.hat.D2.Color = GIS.FEZHAT.Color.Blue; this.hat.D3.Color = GIS.FEZHAT.Color.Blue; break; case MobilRemote.ArahJalan.Kanan: this.hat.MotorB.Speed = -0.7; this.hat.MotorA.Speed = 0.7; this.hat.D2.Color = GIS.FEZHAT.Color.Cyan; this.hat.D3.Color = GIS.FEZHAT.Color.Cyan; break; case MobilRemote.ArahJalan.Stop: this.hat.MotorA.Speed = 0.0; this.hat.MotorB.Speed = 0.0; this.hat.D2.Color = GIS.FEZHAT.Color.Red; this.hat.D3.Color = GIS.FEZHAT.Color.Red; break; } isNavigating = false; }; timer.Start(); client = new MqttClient(MQTT_BROKER_ADDRESS); string clientId = Guid.NewGuid().ToString(); client.Connect(clientId); SubscribeMessage(); }
private async void Setup() { this.hat = await GIS.FEZHAT.CreateAsync(); //this.hat.S1.SetLimits(500, 2400, 0, 180); //this.hat.S2.SetLimits(500, 2400, 0, 180); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(100); this.timer.Start(); Mobil = new MobilRemote(); this.timer.Tick += (a,b) => { /* double x, y, z; this.hat.GetAcceleration(out x, out y, out z); this.LightTextBox.Text = this.hat.GetLightLevel().ToString("P2"); this.TempTextBox.Text = this.hat.GetTemperature().ToString("N2"); this.AccelTextBox.Text = $"({x:N2}, {y:N2}, {z:N2})"; this.Button18TextBox.Text = this.hat.IsDIO18Pressed().ToString(); this.Button22TextBox.Text = this.hat.IsDIO22Pressed().ToString(); this.AnalogTextBox.Text = this.hat.ReadAnalog(GIS.FEZHAT.AnalogPin.Ain1).ToString("N2"); */ if (isNavigating) return; isNavigating = true; this.hat.D2.Color = GIS.FEZHAT.Color.Black; this.hat.D3.Color = GIS.FEZHAT.Color.Black; switch (Mobil.Arah) { case MobilRemote.ArahJalan.Maju: this.hat.MotorA.Speed = 1.0; this.hat.MotorB.Speed = 1.0; this.hat.D2.Color = GIS.FEZHAT.Color.Green; this.hat.D3.Color = GIS.FEZHAT.Color.Green; break; case MobilRemote.ArahJalan.Mundur: this.hat.MotorA.Speed = -1.0; this.hat.MotorB.Speed = -1.0; this.hat.D2.Color = GIS.FEZHAT.Color.Yellow; this.hat.D3.Color = GIS.FEZHAT.Color.Yellow; break; case MobilRemote.ArahJalan.Kiri: this.hat.MotorA.Speed = -0.7; this.hat.MotorB.Speed = 0.7; this.hat.D2.Color = GIS.FEZHAT.Color.Blue; this.hat.D3.Color = GIS.FEZHAT.Color.Blue; break; case MobilRemote.ArahJalan.Kanan: this.hat.MotorB.Speed = -0.7; this.hat.MotorA.Speed = 0.7; this.hat.D2.Color = GIS.FEZHAT.Color.Cyan; this.hat.D3.Color = GIS.FEZHAT.Color.Cyan; break; case MobilRemote.ArahJalan.Stop: this.hat.MotorA.Speed = 0.0; this.hat.MotorB.Speed = 0.0; this.hat.D2.Color = GIS.FEZHAT.Color.Red; this.hat.D3.Color = GIS.FEZHAT.Color.Red; break; } isNavigating = false; }; timer.Start(); client = new MqttClient(MQTT_BROKER_ADDRESS); string clientId = Guid.NewGuid().ToString(); client.Connect(clientId); SubscribeMessage(); }
private async void Setup() { this.hat = await GIS.FEZHAT.CreateAsync(); this.hat.S1.SetLimits(500, 2400, 0, 180); this.hat.S2.SetLimits(500, 2400, 0, 180); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(100); IPublicClientApplication confidentialClientApplication = PublicClientApplicationBuilder .Create("yourazureappid") .WithRedirectUri("urn:ietf:wg:oauth:2.0:oob") .WithAuthority(new Uri("https://login.microsoftonline.com/azuresecretstring")) .WithLogging((level, message, containsPii) => { Debug.WriteLine($"MSAL: {level} {message} "); }, LogLevel.Warning, enablePiiLogging: false, enableDefaultPlatformLogging: true) .Build(); string[] scopes = new string[] { "https://graph.microsoft.com/.default" }; var result = await confidentialClientApplication.AcquireTokenInteractive(scopes).ExecuteAsync(); HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", result.AccessToken); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); while (true) { Task.Delay(5000).Wait(); var myrequest = new { schedules = new List <String>() { "*****@*****.**" }, startTime = new DateTimeTimeZone { DateTime = DateTimeOffset.Now.ToString(), TimeZone = "Pacific Standard Time" }, endTime = new DateTimeTimeZone { DateTime = DateTimeOffset.Now.AddHours(.5).ToString(), TimeZone = "Pacific Standard Time" }, availabilityViewInterval = 15 }; string content = JsonConvert.SerializeObject(myrequest); HttpResponseMessage contentResult = await httpClient.PostAsync("https://graph.microsoft.com/v1.0/users/[email protected]/calendar/getschedule", new StringContent(content, Encoding.UTF32, "application/json")); string mycontent = await contentResult.Content.ReadAsStringAsync(); JObject jObject = JObject.Parse(mycontent); calendarValue = (string)jObject.SelectToken("value[0].scheduleItems[0].status"); if (this.calendarValue == "busy") { this.hat.D2.Color = this.next ? GIS.FEZHAT.Color.Red : GIS.FEZHAT.Color.Yellow; } else { this.hat.D2.Color = this.next ? GIS.FEZHAT.Color.Green : GIS.FEZHAT.Color.Blue; } } }