Esempio n. 1
0
        private async Task SimulateButtonPush()
        {
            Guid iD = Guid.NewGuid();

            _logger.LogInformation("Generating grid zone {0} for button push", iD);

            Zone zone = new Zone
            {
                Id            = iD,
                Name          = "Zone_Button_Sim",
                IoTDeviceInfo = await _deviceManager.AddDeviceAsync(iD.ToString()).ConfigureAwait(false),
                GridLocation  = await _gridManager.AssignBlock(iD, true).ConfigureAwait(false)
            };

            Location location = await _gridManager.GetGridLocation(zone.GridLocation).ConfigureAwait(false);

            _logger.LogInformation("Creating telemetry data point for device {0}", zone.Name);

            var telemetryDataPoint = new ZoneDataPoint
            {
                DeviceId   = zone.IoTDeviceInfo.DeviceId,
                Name       = "Sim1",
                Type       = zone.Type,
                Grid_x     = location.Rowx,
                Grid_y     = location.Columny,
                Operation  = "button_pushed",
                InZone     = true,
                ZoneId     = zone.Id,
                ZoneGrid_x = location.Rowx,
                ZoneGrid_y = location.Columny,
                ZoneName   = zone.Name
            };

            _logger.LogInformation("Sending button push message to hub");

            await SendIoTHubMessage(zone, telemetryDataPoint).ConfigureAwait(false);


            _logger.LogInformation("Removing device {0} from IoT Hub", zone.Id);

            await _deviceManager.RemoveDeviceAsync(zone.Id.ToString()).ConfigureAwait(false);
        }
Esempio n. 2
0
        private async void GridZoneExited(object sender, ZoneEventArgs args)
        {
            Zone zone = _zones.Find(z => z.Id == args.GridBlock.ZoneId);

            var telemetryDataPoint = new ZoneDataPoint
            {
                DeviceId   = zone.IoTDeviceInfo.DeviceId,
                Name       = args.SimObject.Name,
                Type       = "zone",
                Grid_x     = args.GridBlock.Location.Rowx,
                Grid_y     = args.GridBlock.Location.Columny,
                Operation  = "zone_exited",
                InZone     = args.GridBlock.IsZone,
                ZoneId     = args.GridBlock.ZoneId,
                ZoneGrid_x = args.GridBlock.Location.Rowx,
                ZoneGrid_y = args.GridBlock.Location.Columny,
                ZoneName   = _zones.Find(z => z.Id == args.GridBlock.ZoneId).Name
            };

            await SendIoTHubMessage(zone, telemetryDataPoint).ConfigureAwait(false);
        }
Esempio n. 3
0
        private async void GridZoneEntered(object sender, ZoneEventArgs args)
        {
            Zone zone = _zones.Find(z => z.Id == args.GridBlock.ZoneId);

            var telemetryDataPoint = new ZoneDataPoint
            {
                DeviceId   = zone.IoTDeviceInfo.DeviceId,
                Name       = args.SimObject.Name,
                Type       = zone.Type,
                Grid_x     = args.GridBlock.Location.Rowx,
                Grid_y     = args.GridBlock.Location.Columny,
                Operation  = "zone_entered",
                InZone     = args.GridBlock.IsZone,
                ZoneId     = args.GridBlock.ZoneId,
                ZoneGrid_x = args.GridBlock.Location.Rowx,
                ZoneGrid_y = args.GridBlock.Location.Columny,
                ZoneName   = _zones.Find(z => z.Id == args.GridBlock.ZoneId).Name
            };

            await SendIoTHubMessage(zone, telemetryDataPoint).ConfigureAwait(false);

            if (_appSettings.Value.SimulateButtonPushes)
            {
                var rand = new Random();
                int c    = rand.Next(1, 10);

                if (c % 2 == 0)
                {
                    telemetryDataPoint.Operation = "button_pushed";

                    _logger.LogInformation("Sending button push message to hub");

                    await SendIoTHubMessage(zone, telemetryDataPoint).ConfigureAwait(false);
                }
            }
        }