private async Task <bool> CreateServiceGroups(string url) { var jsonGroup = new Service { Apikey = FIWAREUrls.JsonKey, Resource = FIWAREUrls.JsonServiceGroupResource, Cbroker = FIWAREUrls.OrionUrl }; var ulGroup = new Service { Apikey = FIWAREUrls.UltraLightKey, Resource = FIWAREUrls.UltraLightServiceGroupResource, Cbroker = FIWAREUrls.OrionUrl }; var json = new ProvisionServiceGroupModel { Services = new List <Service> { jsonGroup, ulGroup } }; using var fiwareClient = new FIWAREClient(); var response = await fiwareClient.SendJson(HttpMethod.Post, url, json); return(response.IsSuccessStatusCode || response.StatusCode == HttpStatusCode.Conflict); }
public async Task <IActionResult> PostTestRoadTrafficReport([FromBody] string payLoad) { using var fiwareClient = new FIWAREClient(); var response = await fiwareClient.SendUltraLight(HttpMethod.Post, FIWAREUrls.UltraLightMeasurementUrl(FIWAREUrls.RoadTrafficDeviceIds.FirstOrDefault()), payLoad); var success = response.IsSuccessStatusCode; return(Ok(success)); }
public async Task <IActionResult> PostTestWeatherMeasurement(FiwareWeatherReport model) { using var fiwareClient = new FIWAREClient(); var response = await fiwareClient.SendJson(HttpMethod.Post, FIWAREUrls.JsonMeasurementUrl(FIWAREUrls.WeatherDeviceIds.FirstOrDefault()), model); var success = response.IsSuccessStatusCode; return(Ok(success)); }
public async Task <IActionResult> PostTestRoadTrafficReport() { var roadTraffic = new FiwareTrafficReport(1) { StartTime = DateTime.UtcNow, City = "Random", AddressNumber = "AddrNr", StartLatitude = 37.9600965, StartLongitude = 23.8576043 }; using var fiwareClient = new FIWAREClient(); var response = await fiwareClient.SendUltraLight(HttpMethod.Post, FIWAREUrls.UltraLightMeasurementUrl(FIWAREUrls.RoadTrafficDeviceIds.FirstOrDefault()), roadTraffic.ToUltraLightSyntax()); var success = response.IsSuccessStatusCode; return(Ok(success)); }
public async Task <IActionResult> PostTestWeatherMeasurement() { var weatherEvent = new FiwareWeatherReport(1) { Temperature = 12, WindChill = 0, Humidity = 02, Pressure = 33.33, Visibility = 100, WindDirection = "NWD", WindSpeed = 120.1, Precipitation = 30.5, ReportTime = DateTime.UtcNow }; using var fiwareClient = new FIWAREClient(); var response = await fiwareClient.SendJson(HttpMethod.Post, FIWAREUrls.JsonMeasurementUrl(FIWAREUrls.WeatherDeviceIds.FirstOrDefault()), weatherEvent); var success = response.IsSuccessStatusCode; return(Ok(success)); }
public async Task <IActionResult> ProvisionUltraLightDevices() { // Helper method to verify that services groups are created var serviceGroupsExist = await CreateServiceGroups($"{FIWAREUrls.IoTUltraLightNorth}{FIWAREUrls.ServiceGroupPath}"); if (!serviceGroupsExist) { return(Conflict("Error creating service groups")); } // Entity attributes for given IoT Agent var entityAttributes = new List <(string name, string objectId, string type)> { ("Severity", "sv", "int"), ("StartTime", "sdt", "string"), ("Latitude", "lat", "double"), ("Longitude", "lon", "double"), ("Geolocation", "geo", "string"), ("Distance", "dis", "double"), ("Description", "desc", "string"), ("AddressNumber", "addrnr", "string"), ("Street", "str", "string"), ("Side", "sd", "string"), ("City", "ct", "string"), ("County", "cn", "string"), ("State", "st", "string"), ("ZipCode", "zc", "string"), ("Country", "c", "string"), ("UID", "uid", "int") }; // POST Model for Provision of multiple devices var json = new ProvisionDevicesModel { Devices = FIWAREUrls.RoadTrafficDeviceIds.Select(id => new Device { DeviceId = id, EntityName = $"urn:ngsi-ld:{id}", EntityType = "roadTrafficReport", Attributes = entityAttributes.Select(ea => new Attribute { Name = ea.name, ObjectId = ea.objectId, Type = ea.type }).ToList() }).ToList() }; using var fiwareClient = new FIWAREClient(); var response = await fiwareClient.SendJson(HttpMethod.Post, $"{FIWAREUrls.IoTUltraLightNorth}{FIWAREUrls.DeviceProvisionPath}", json); var success = response.IsSuccessStatusCode; var returnMessage = success ? "Successfully provisioned UltraLight Devices" : $"There was an error during the execution of {nameof(ProvisionUltraLightDevices)}"; if (!success) { return(BadRequest(returnMessage)); } return(Ok(returnMessage)); }
public async Task <IActionResult> ProvisionJsonDevices() { // Helper method to verify that services groups are created var serviceGroupsExist = await CreateServiceGroups($"{FIWAREUrls.IoTAJsonNorth}{FIWAREUrls.ServiceGroupPath}"); if (!serviceGroupsExist) { return(Conflict("Error creating service groups")); } // Entity attributes for given IoT Agent var entityAttributes = new List <(string name, string objectId, string type)> { ("ReportTime", "rt", "string"), ("WeatherEvent", "we", "string"), ("Severity", "sv", "string"), ("OriginalWeatherConditionDescription", "owcd", "string"), ("Temperature", "tmp", "double"), ("WindChill", "wch", "double"), ("Humidity", "hm", "double"), ("Pressure", "pr", "double"), ("Visibility", "vs", "double"), ("CloudCoverage", "cc", "string"), ("WindDirection", "wd", "string"), ("WindSpeed", "ws", "double"), ("Precipitation", "pcpt", "double"), ("City", "ct", "string"), ("County", "cn", "string"), ("State", "st", "string"), ("ZipCode", "zc", "string"), ("Country", "c", "string"), ("UID", "uid", "int") }; // POST Model for Provision of multiple devices var json = new ProvisionDevicesModel { Devices = FIWAREUrls.WeatherDeviceIds.Select(id => new Device { DeviceId = id, EntityName = $"urn:ngsi-ld:{id}", EntityType = "weatherReport", Attributes = entityAttributes.Select(ea => new Attribute { Name = ea.name, ObjectId = ea.objectId, Type = ea.type }).ToList() }).ToList() }; using var fiwareClient = new FIWAREClient(); var response = await fiwareClient.SendJson(HttpMethod.Post, $"{FIWAREUrls.IoTAJsonNorth}{FIWAREUrls.DeviceProvisionPath}", json); var success = response.IsSuccessStatusCode; var returnMessage = success ? "Successfully provisioned JSON Devices" : $"There was an error during the execution of {nameof(ProvisionJsonDevices)}"; if (!success) { return(BadRequest(returnMessage)); } return(Ok(returnMessage)); }