Esempio n. 1
0
        public void AddReading(MReading reading)
        {
            Readings.Add(reading);

            if (Readings.Count > 100)
            {
                Readings.RemoveAt(0);
            }
        }
Esempio n. 2
0
        public void Run([IoTHubTrigger("messages/events", Connection = "wezhub")] EventData message, [CosmosDB(
                databaseName: "wezmondoIOT",
                collectionName: "wezmondoIOT",
                ConnectionStringSetting = "wezdata")]out dynamic document, ILogger log)
        {
            string bodyString = Encoding.UTF8.GetString(message.Body.Array);

            log.LogInformation($"Id: {JsonConvert.SerializeObject(message.SystemProperties["iothub-connection-device-id"])}");

            log.LogInformation($"C# IoT Hub trigger function processed a message: {bodyString}");

            // ADD READING TO SINGLETON SO WE CAN ANALYSE THE LAST 100 READINGS...

            MReading reading = JsonConvert.DeserializeObject<MReading>(bodyString);

            _readings.AddReading(reading);

            log.LogInformation($"Readings: {_readings.Readings.Count()}");

            checkExposure(message.SystemProperties["iothub-connection-device-id"].ToString());

            // CONVERT DATA INTO EXISTING PROJECT FORMAT SO I CAN QUERY IT ONLINE FOR TESTING...

            MistyPayload payload = new MistyPayload();
            payload.Alerts = reading.Alerts;
            payload.Values = reading.Payload;
            WSPayload toSend = new WSPayload();
            toSend.ProjectID = 1;
            toSend.RoleID = 6;
            toSend.DeviceUID = message.SystemProperties["iothub-connection-device-id"].ToString();
            toSend.Sent = reading.Time;
            toSend.Data = payload;

            // OUT VALUE...

            document = JsonConvert.SerializeObject(toSend);
        }