Skip to content

Instantly share code, notes, and snippets.

@mabbotts9797
Created May 26, 2018 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mabbotts9797/47606cf5bdd83dea8199e327c5b55958 to your computer and use it in GitHub Desktop.
Save mabbotts9797/47606cf5bdd83dea8199e327c5b55958 to your computer and use it in GitHub Desktop.
Code for the Azure serverless function that persists sensor readings
using System.Net;
public static HttpResponseMessage Run(HttpRequestMessage req, out object airQualityDocument, TraceWriter log)
{
string latitude = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "latitude", true) == 0)
.Value;
string longitude = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "longitude", true) == 0)
.Value;
string ppm = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "ppm", true) == 0)
.Value;
airQualityDocument = new {
Latitude = latitude ,
Longitude = longitude,
Ppm = ppm,
RequestDateTime = DateTime.Now
};
return (latitude != string.Empty && longitude != string.Empty && ppm != string.Empty) ? req.CreateResponse(HttpStatusCode.OK) : req.CreateResponse(HttpStatusCode.BadRequest);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment