Sure, no rush at all. My other challenge will be getting the data to my Vera home automation gateway, so i'll work on that first :-) I'll be happy to test new firmware, once you've had time to update the module.
The Azure endpoint I created is an 'Azure Function'. Another logical endpoint would be an Azure Logic App, those unfortunately only support HTTP POST. In case you someday have a need/wish to add POST support; a sample endpoint would be:
https://prod-06.westeurope.logic.azure.c...vVP7PHXD_Q
In a logic app you define a json schema for the data, the endpoint above expects the following body:
{
"co2": 701.34,
"temp": 24.53,
"hum": 44.43,
"pres": 999
}
Then there are several other Azure endpoints, depending on the scenario. The thing I like about the 'Azure Function' is that it allows me to accept the data from the device and store it in 'Azure table storage' with just a few lines of code:
Code:
#r "Microsoft.WindowsAzure.Storage"
using System.Net;
using Microsoft.WindowsAzure.Storage.Table;
using System.Globalization;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, IAsyncCollector<CO2DataPoint> co2Table, TraceWriter log)
{
log.Info($"Incoming CO2 data");
// parse query parameter
var parameters = req.GetQueryNameValuePairs();
double co2 = GetDbl(parameters, "co2");
double temp = GetDbl(parameters, "temp");
double hum = GetDbl(parameters, "hum");
double pres = GetDbl(parameters, "pres");
var timestamp = DateTime.Now;
log.Info($"data received at {timestamp}, CO2 is {co2}.");
var dataPoint = new CO2DataPoint() {
PartitionKey = $"{timestamp.Year}-{timestamp.Month}-{timestamp.Day}",
RowKey = $"{timestamp.Hour}-{timestamp.Minute}-{timestamp.Second}",
CO2 = co2,
Temperature = temp,
Humidity = hum,
Pressure = pres
};
await co2Table.AddAsync(dataPoint);
return req.CreateResponse(HttpStatusCode.OK, "Thanx");
}
public static double GetDbl(IEnumerable<System.Collections.Generic.KeyValuePair<string, string>> parameters, string name)
{
string value = parameters
.FirstOrDefault(q => string.Compare(q.Key, name, true) == 0)
.Value;
return double.Parse(value, CultureInfo.InvariantCulture);
}
public class CO2DataPoint : TableEntity
{
public double CO2 {get;set;}
public double Temperature {get;set;}
public double Humidity {get;set;}
public double Pressure {get;set;}
}