Ejemplo n.º 1
0
        public static void Power(this TelemetryStatus ts, string newValue, int?powerIndex = null)
        {
            const string ipi = "Invalid powerIndex";

            if (powerIndex == null)
            {
                ts.Power = (ts.Power ?? throw new Exception(ipi)) == "" ? newValue : newValue;
            }
            if (powerIndex == 1)
            {
                ts.Power1 = (ts.Power1 ?? throw new Exception(ipi)) == "" ? newValue : newValue;
            }
            if (powerIndex == 2)
            {
                ts.Power2 = (ts.Power2 ?? throw new Exception(ipi)) == "" ? newValue : newValue;
            }
            if (powerIndex == 3)
            {
                ts.Power3 = (ts.Power3 ?? throw new Exception(ipi)) == "" ? newValue : newValue;
            }
            if (powerIndex == 4)
            {
                ts.Power4 = (ts.Power4 ?? throw new Exception(ipi)) == "" ? newValue : newValue;
            }
        }
Ejemplo n.º 2
0
        private async Task TelemetryReceivedAsync(Device device, TelemetryStatus telemetryStatus)
        {
            var fieldsToUpdate = new Device()
            {
                _id     = device._id,
                Status  = telemetryStatus.ToDeviceStatus(),
                Offline = false
            };
            var fieldsToUnset = new string[0];

            if (device.State == DeviceState.Provisioning)
            {
                _logger.LogInformation("Device '{hostname}' has completed provisioning.", device.HostName);
                fieldsToUpdate.ProvisionedAt = DateTime.Now;
                fieldsToUnset = new[] { "state" };
            }
            await _deviceRepository.UpdateDeviceAsync(fieldsToUpdate, isUpsert : false, fieldsToUnset : fieldsToUnset);

            // After provision or restart
            if (device.State == DeviceState.Provisioning || telemetryStatus.UptimeSec < device.Status.UptimeSeconds)
            {
                // Fetch all device information again and update device in db
                await _masterService.ScanDeviceAsync(device.Ipv4Address);
            }
        }
Ejemplo n.º 3
0
        public static MongoDb.Models.DeviceStatus ToDeviceStatus(this TelemetryStatus status)
        {
            return(new MongoDb.Models.DeviceStatus()
            {
                UptimeSeconds = status.UptimeSec,
                HeapKb = status.Heap,
                CpuLoad = status.LoadAvg,

                MqttRetries = status.MqttCount,

                WiFiRssi = status.WiFi.Rssi,
                WiFiDbm = status.WiFi.Signal,
                WiFiRetries = status.WiFi.LinkCount,
                WiFiDowntimeSeconds = ConvertToSeconds(status.WiFi.Downtime),

                PowerStates = new[] { status.Power, status.Power1, status.Power2, status.Power3, status.Power4 }
                .Where(p => p != null)
                .Select(p => p !)
                .ToArray()
            });
Ejemplo n.º 4
0
 public static string Power(this TelemetryStatus ts, int?powerIndex = null)
 {
     if (powerIndex == null)
     {
         return(ts.Power !);
     }
     if (powerIndex == 1)
     {
         return(ts.Power1 !);
     }
     if (powerIndex == 2)
     {
         return(ts.Power2 !);
     }
     if (powerIndex == 3)
     {
         return(ts.Power3 !);
     }
     if (powerIndex == 4)
     {
         return(ts.Power4 !);
     }
     throw new Exception("Invalid powerIndex");
 }