예제 #1
0
        /// <inheritdoc/>
        public long GetTimestampFor(LoraMessage payload)
        {
            string time           = payload.UplinkMessage.ReceivedAt;
            long   epochTimestamp = DateTimeOffset.Parse(time).ToUnixTimeMilliseconds();

            return(epochTimestamp);
        }
예제 #2
0
        /// <inheritdoc/>
        public bool CanParse(LoraMessage payload)
        {
            var validPayload = payload.UplinkMessage.DecodedPayload != null;

            if (!validPayload)
            {
                var devEui = GetDeviceIdFor(payload);
                _logger.Warning($"'{devEui}': does not contain decoded payload");
            }
            return(validPayload);
        }
예제 #3
0
        async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
        {
            LoraMessage message = new LoraMessage();

            _client   = new MongoClient();
            _database = _client.GetDatabase("lockD");

            foreach (EventData eventData in messages)
            {
                string data = Encoding.UTF8.GetString(eventData.GetBytes());
                //"{\n      \"LockId\":\"1C8779C0000000EC\",\n      \"Latitude\":\"1.0\",\n      \"Longitude\":\"1.0\",\n      \"Timestamp\":\"0\"\n}"

                Console.WriteLine(string.Format("Message received.  Partition: '{0}', Data: '{1}'", context.Lease.PartitionId, data));
                try
                {
                    message = JsonConvert.DeserializeObject <LoraMessage>(data);
                    var document = new BsonDocument
                    {
                        { "LockId", message.LockId },
                        { "Latitude", message.Latitude },
                        { "Longitude", message.Longitude },
                        { "Timestamp", DateTime.Now.ToLocalTime() }
                    };
                    string LastLocation = message.Latitude + "," + message.Longitude;

                    var loraMessages = _database.GetCollection <BsonDocument>("loraMessages");
                    await loraMessages.InsertOneAsync(document);

                    var bikes  = _database.GetCollection <BsonDocument>("bikes");
                    var filter = Builders <BsonDocument> .Filter.Eq("LockId", message.LockId);

                    var update = Builders <BsonDocument> .Update
                                 .Set("LastLocation", LastLocation);

                    var result = await bikes.UpdateOneAsync(filter, update);
                }
                catch
                {
                    Console.WriteLine("Failed To Deserialize");
                }
            }

            //Call checkpoint every 5 minutes, so that worker can resume processing from 5 minutes back if it restarts.
            if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
            {
                await context.CheckpointAsync();

                this.checkpointStopWatch.Restart();
            }
        }
예제 #4
0
 /// <inheritdoc/>
 public Dictionary <string, dynamic> GetDecodedPayloadFor(LoraMessage payload) => payload.UplinkMessage.DecodedPayload;
예제 #5
0
 /// <inheritdoc/>
 public string GetDeviceIdFor(LoraMessage payload) => payload.EndDeviceIds.DevEui;
예제 #6
0
 /// <inheritdoc/>
 public string GetApplicationIdFor(LoraMessage payload) => payload.EndDeviceIds.ApplicationIds.ApplicationId;