public static IActionResult GetTemperature([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "temperature/{devicename}")] HttpRequest req, [CosmosDB(databaseName: "IoTData", collectionName: "Temperatures", ConnectionStringSetting = "cosmosDBConnectionString", Id = "{devicename}")] TemperatureItem temperatureItem, ILogger log) { return(new OkObjectResult(temperatureItem)); }
public static void Run([IoTHubTrigger("%eventHubConnectionPath%", Connection = "eventHubConnectionString")] EventData message, [CosmosDB(databaseName: "IoTData", collectionName: "Temperatures", ConnectionStringSetting = "cosmosDBConnectionString")] out TemperatureItem output, ILogger log) { var deviceId = message.SystemProperties["iothub-connection-device-id"].ToString(); var jsonBody = Encoding.UTF8.GetString(message.Body); dynamic data = JsonConvert.DeserializeObject(jsonBody); double temperature = data.temperature; double threshold = data.threshold; output = new TemperatureItem { Temperature = temperature, Threshold = threshold, Id = deviceId }; }