Beispiel #1
0
        public bool Save(DeviceReading reading)
        {
            INoSqlDataAccess <Entity.DeviceReading> dataAccess = NoSqlBusinessModelFactory.CreateDeviceDataAccess();

            dataAccess.Save(reading);
            return(true);
        }
Beispiel #2
0
        public bool Save(DeviceReading reading)
        {
            DocumentdbService <DeviceReading> service = new DocumentdbService <DeviceReading>();

            // return service.CreateDatabase().Result;
            return(service.Create(reading));
        }
Beispiel #3
0
 public ItemDetailViewModel(DeviceReading item = null, Goal goal = null)
 {
     Title        = item.RoomName ?? "Unknown Room";
     Item         = item;
     _temperature = item.Temperature;
     _humidity    = item.Humidity;
     _goal        = goal;
 }
Beispiel #4
0
        public void Post([FromBody] DeviceReading input)
        {
            //IInputDeviceBLL<DeviceInput> context = ControllerFactory.CreateDeviceBusinessModel();

            //context.SaveModel(input);

            IDeviceBLL <DeviceReading> context = ControllerFactory.CreateDocumentdbDeviceBusinessModel();

            context.Save(input);
        }
Beispiel #5
0
        public void SubmitMany()
        {
            // resources for actor
            var cdb = new CosmosDB();

            cdb.OpenConnection();
            var save = ActorOf(CosmosSaveActor.Props(cdb));
            var icao = ActorOf <ICAOLookupActor>();

            // test data
            var data = getTestData();

            DeviceReading dr = data[0];
            FlightData    fd = dr.aircraft.First(z => z.flight != null && z.flight.Trim() == "JBU238");

            var flight = fd.flight.Trim();
            var str    = "activeSnap:" + flight.Trim();

            var a = ActorOf(FlightActor.Props());

            a.Tell(new FlightActor.FlightActorInit(save, flight.Trim(), icao), TestActor);

            System.Threading.Thread.Sleep(1000);

            data = data.OrderBy(z => z.now).ToList();

            foreach (var d in data.Take(2))
            {
                if (d.aircraft.Any(z => z.flight != null && z.flight.Trim() == flight))
                {
                    fd = d.aircraft.First(z => z.flight != null && z.flight.Trim() == flight);
                    dr = d;
                    a.Tell(new FlightActor.FlightDataRequest()
                    {
                        deviceId   = d.deviceId,
                        flightData = fd,
                        now        = d.now
                    }, TestActor);
                }
            }

            ExpectNoMsg(TimeSpan.FromSeconds(5));

            var res = cdb.GetDocumentQuery <FlightDataSnapshot>("flights")
                      .Where(z => z.id == str && z.flight == flight.Trim())
                      .OrderByDescending(z => z.now)
                      .ToList();

            Assert.Greater(res.Count, 0);

            var m = data.Where(z => z.now == res[0].now);

            Assert.AreEqual(res.First().now, dr.now);
            Assert.AreEqual(res.First().lat, fd.lat);
        }
Beispiel #6
0
 public DeviceRead(
     string deviceId,
     DeviceReading reading,
     string protocolType,
     string connectivityZone,
     Dictionary <string, string> properties,
     DateTime?eventTimestamp = null)
     : base(deviceId, properties, eventTimestamp)
 {
     ProtocolType     = protocolType;
     ConnectivityZone = connectivityZone;
     Reading          = reading;
 }
Beispiel #7
0
        public Task RunAsync(SimulationStrategy strategy, CancellationToken cancellationToken)
        {
            return(strategy.RunAsync((value) => {
                var reading = new DeviceReading(DateTime.UtcNow, value, _channel, string.Empty, _unit);

                var eventProps = new Dictionary <string, string>();
                eventProps["ProjectId"] = "Foo";

                var @event = new DeviceRead(_deviceId, reading, "console-sim", string.Empty, eventProps, DateTime.UtcNow);

                _sender.SendAsync(@event, cancellationToken);
            }, cancellationToken));
        }
Beispiel #8
0
        public async Task <ActionResult> Post([FromBody] DeviceReading reading)
        {
            var readings = await GetReadingsAsync();

            readings.Add(reading);

            var statistics = await GetStatisticsAsync();

            statistics.DeviceCount    = readings.Select(r => r.DeviceId).Distinct().Count();
            statistics.ReadingCount   = readings.Count();
            statistics.AverageReading = readings.Average(r => r.Reading);
            statistics.MaximumReading = readings.Max(r => r.Reading);
            statistics.MinimumReading = readings.Min(r => r.Reading);

            return(Ok());
        }
Beispiel #9
0
        private static async void SendDeviceToCloudSometimesCriticalMessagesAsync(DeviceClient deviceClient, Constants.device device)
        {
            double minTemperature = 20;
            double minHumidity    = 60;
            Random rand           = new Random();

            while (true)
            {
                double currentTemperature = minTemperature + rand.NextDouble() * 15;
                double currentHumidity    = minHumidity + rand.NextDouble() * 20;

                var telemetryDataPoint = new
                {
                    deviceId    = device.Name,
                    temperature = currentTemperature,
                    humidity    = currentHumidity
                };
                DeviceReading data = new DeviceReading();
                data.Id          = Guid.NewGuid().ToString();
                data.DeviceId    = "pankaj/home/dth12";
                data.QOutTime    = DateTime.Now;
                data.ReadingTime = DateTime.Now;
                data.Value       = "{ temperature : " + currentTemperature.ToString() + ",humidity:" + currentHumidity.ToString() + "}";
                var messageString = JsonConvert.SerializeObject(data);
                //var messageString = JsonConvert.SerializeObject(telemetryDataPoint);
                string levelValue;

                if (rand.NextDouble() > 0.7)
                {
                    messageString = "This is a critical message " + device.Name;
                    levelValue    = "critical";
                }
                else
                {
                    levelValue = "normal";
                }

                var message = new Message(Encoding.ASCII.GetBytes(messageString));
                message.Properties.Add("level", levelValue);

                await deviceClient.SendEventAsync(message);

                Console.WriteLine("{0} > Sent message: {1}", DateTime.Now, messageString);

                await Task.Delay(1000);
            }
        }
        public async Task AddAsync(DeviceReading reading)
        {
            if (reading == null)
            {
                throw new ArgumentNullException(nameof(reading));
            }

            using (var connection = await _connectionFactory.CreateConnectionAsync())
            {
                var sql = $"INSERT INTO {DeviceReadingsTableName} ({nameof(DeviceReading.DeviceId)}, {nameof(DeviceReading.DateTime)}, {nameof(DeviceReading.Speed)}," +
                          $" {nameof(DeviceReading.PackageTrackingAlarmState)}, {nameof(DeviceReading.CurrentBoards)}, {nameof(DeviceReading.CurrentRecipeCount)})"
                          + $" VALUES(@{nameof(DeviceReading.DeviceId)}, @{nameof(DeviceReading.DateTime)}, @{nameof(DeviceReading.Speed)}," +
                          $" @{nameof(DeviceReading.PackageTrackingAlarmState)}, @{nameof(DeviceReading.CurrentBoards)}, @{nameof(DeviceReading.CurrentRecipeCount)})";

                await connection.ExecuteAsync(sql, reading);

                Log.Information($"A deviceReading with ID '{reading.DeviceId}' added.");
            }
        }
Beispiel #11
0
 public bool Update(DeviceReading reading)
 {
     throw new NotImplementedException();
 }
 public async Task UpdateReadingFromDevice(DeviceReading entity)
 {
     await _deviceReadingRepository.UpdateAsync(entity);
 }
 public async Task CreateReading(DeviceReading entity)
 {
     await _deviceReadingRepository.InsertAsync(entity);
 }
Beispiel #14
0
        private DeviceReading Connect(FoundBluetoothDevice device)
        {
            // client is connected
            NetworkStream stream = device.Client.GetStream();

            if (stream.CanRead)
            {
                do
                {
                    stream.ReadTimeout = 2500; // 500 millisecond timeout, if unable to get data feed
                    int numberOfBytesRead = stream.Read(_myReadBuffer, 0, _myReadBuffer.Length);
                    if (numberOfBytesRead <= 1)
                    {
                        continue;
                    }

                    string sensorTempValue = Encoding.ASCII.GetString(_myReadBuffer, 0, numberOfBytesRead);
                    if (string.IsNullOrWhiteSpace(sensorTempValue))
                    {
                        return(null);
                    }

                    string[] arr = sensorTempValue.Split(Environment.NewLine).ToArray();

                    if (arr.Length == 0)
                    {
                        return(null); // nothing to get
                    }
                    DeviceReading deviceReading = new DeviceReading();

                    string latestReading = arr.LastOrDefault(x => !string.IsNullOrWhiteSpace(x));

                    if (string.IsNullOrWhiteSpace(latestReading))
                    {
                        return(null);
                    }

                    string[] latestData = latestReading.Split(' ')
                                          .Where(x => !string.IsNullOrWhiteSpace(x))
                                          .ToArray();

                    if (latestData.Length == 1) // only one value in the array suspect stoppage
                    {
                        if (latestData[0].Equals("-sleep", StringComparison.CurrentCultureIgnoreCase))
                        {
                            throw new SleepException("The device is now sleeping");
                        }
                    }

                    int sdCardIndex = Array.IndexOf(latestData, "-sdCardData");
                    if (sdCardIndex > -1) // has sd card data
                    {
                        // loop through elements after sd card data element
                        SdCardDeviceReading sdCardData = ExtractBluetoothData(latestData, sdCardIndex + 1);
                        deviceReading.SdCardDeviceReading = sdCardData;
                    }

                    LiveDeviceReading liveDeviceReading = ExtractBluetoothData(latestData);
                    deviceReading.LiveDeviceReading = liveDeviceReading;

                    return(deviceReading);
                }while (stream.DataAvailable); // only continue if there is more to stream and the parse was successful.

                return(null);
            }

            return(null);
        }