Example #1
0
        public async static Task ProcessSumpPumpDataPoint([EventHubTrigger("iothub-ehub-sumppump-i-31562-57e63b098f")] DataPointPayload payload)
        {
            var newDataPoint = new DataPointEntity()
            {
                PartitionKey = payload.DeviceId,
                RowKey       = payload.Timestamp.ToRowKey(),
                WaterLevel   = payload.WaterLevel,
                PumpRunning  = payload.PumpRunning
            };

            DataPointRepository.Insert(newDataPoint);

            /*
             * // Get Current Duty Cycle we're in the middle of
             * var currentDutyCycle = await GetCurrentDutyCycle(payload);
             *
             * // Sump Pump turned on or off - start a new Duty Cycle
             * if (currentDutyCycle.IsEmptying != payload.PumpRunning)
             *  currentDutyCycle = CreateDutyCycle(payload);
             *
             * // Update the end time with the current statistics
             * currentDutyCycle.EndLevel = payload.WaterLevel;
             * currentDutyCycle.EndTime = payload.Timestamp;
             * DutyCycleRepository.Upsert(currentDutyCycle);
             */
        }
Example #2
0
 private static DutyCycleEntity CreateDutyCycle(DataPointPayload payload)
 {
     return(new DutyCycleEntity
     {
         PartitionKey = payload.DeviceId,
         RowKey = payload.Timestamp.ToRowKey(),
         StartLevel = payload.WaterLevel,
         StartTime = payload.Timestamp,
         IsEmptying = payload.PumpRunning
     });
 }
Example #3
0
        private async static Task <DutyCycleEntity> GetCurrentDutyCycle(DataPointPayload payload)
        {
            var dutyCycleList = await DutyCycleRepository.Top(payload.DeviceId, 1);

            var dutyCycle = dutyCycleList.FirstOrDefault();

            if (dutyCycle == null)
            {
                return(CreateDutyCycle(payload));
            }

            return(dutyCycle);
        }
Example #4
0
        private async Task SendDataPoint()
        {
            var payload = new DataPointPayload
            {
                DeviceId    = DeviceId,
                Timestamp   = DateTime.Now,
                WaterLevel  = CurrentWaterLevel,
                PumpRunning = PumpStatus
            };

            var json = JsonConvert.SerializeObject(payload);

            using (var message = new Message(Encoding.UTF8.GetBytes(json)))
            {
                message.Properties.Add("DeviceName", DeviceId);
                await iotClient.SendEventAsync(message);
            }
        }