#' @get /heatmapIDW #' @serializer unboxedJSON heatmapIDW <- function(city, long_min, long_max, lat_min, lat_max, epsgProjection, subnature, valueType, fromDateTime, toDateTime, heatmapName, colorMap){ print(showConnections(all = T)) memfree <- as.numeric(system("awk '/MemFree/ {print $2}' /proc/meminfo", intern=TRUE)) print(memfree) print(gc()) print("--------- INSTALL PACKAGES - START ---------") print(Sys.time()) #------------------------------------------------ #install.packages #------------------------------------------------ if("jsonlite" %in% rownames(installed.packages()) == FALSE) {install.packages("jsonlite")} suppressMessages(library(jsonlite)) if("dplyr" %in% rownames(installed.packages()) == FALSE) {install.packages("dplyr")} suppressMessages(library(dplyr)) if("scales" %in% rownames(installed.packages()) == FALSE) {install.packages("scales")} suppressMessages(library(scales)) if("httr" %in% rownames(installed.packages()) == FALSE) {install.packages("httr")} suppressMessages(library(httr)) if("akima" %in% rownames(installed.packages()) == FALSE) {install.packages("akima")} suppressMessages(library(akima)) if("reshape2" %in% rownames(installed.packages()) == FALSE) {install.packages("reshape2")} suppressMessages(library(reshape2)) if("geoR" %in% rownames(installed.packages()) == FALSE) {install.packages("geoR")} suppressMessages(library(geoR)) if("RNetCDF" %in% rownames(installed.packages()) == FALSE) {install.packages("RNetCDF")} suppressMessages(require(RNetCDF)) if("sp" %in% rownames(installed.packages()) == FALSE) {install.packages("sp")} suppressMessages(require(sp)) if("rgdal" %in% rownames(installed.packages()) == FALSE) {install.packages("rgdal")} suppressMessages(require(rgdal)) if("tmap" %in% rownames(installed.packages()) == FALSE) {install.packages("tmap")} suppressMessages(require(tmap)) if("gstat" %in% rownames(installed.packages()) == FALSE) {install.packages("gstat")} suppressMessages(require(gstat)) if("stringr" %in% rownames(installed.packages()) == FALSE) {install.packages("stringr")} suppressMessages(require(stringr)) #------------------------------------------------ print("--------- INSTALL PACKAGES - END ---------") print(Sys.time()) print("------------------------------------------------") print(paste("city: ",city, ", long_min: ",long_min,", long_max: ",long_max, ", lat_min: ",lat_min,"epsgProjection: ", epsgProjection, ", subnature: ",subnature, ", valueType: ",valueType,", fromDateTime: ",fromDateTime, ", toDateTime: ",toDateTime, ", heatmapName: ",heatmapName, ", colorMap: ",colorMap, sep = "")) print("--------- CHECK ON PARAMETERS - START ---------") print(Sys.time()) #CHECK ON PARAMETERS: #------------------------------------------------ if(nchar(city)==0){ return("Please insert 'city' parameter correctly and inject the node again") } if(is.character(city)==F){ return("Please insert 'city' parameter correctly and inject the node again. The parameter has to be a string") } #--- if(nchar(long_min)==0){ return("Please insert 'long_min' parameter correctly and inject the node again") }else{ long_min = as.numeric(long_min) } if(is.na(long_min)){ return("Please insert 'long_min' parameter correctly and inject the node again. The parameter has to be numeric") } #--- if(nchar(long_max)==0){ return("Please insert 'long_max' parameter correctly and inject the node again") }else{ long_max = as.numeric(long_max) } if(is.na(long_max)){ return("Please insert 'long_max' parameter correctly and inject the node again. The parameter has to be numeric") } #--- if(nchar(lat_min)==0){ return("Please insert 'lat_min' parameter correctly and inject the node again") }else{ lat_min = as.numeric(lat_min) } if(is.na(lat_min)){ return("Please insert 'lat_min' parameter correctly and inject the node again. The parameter has to be numeric") } #--- if(nchar(lat_max)==0){ return("Please insert 'lat_max' parameter correctly and inject the node again") }else{ lat_max = as.numeric(lat_max) } if(is.na(lat_max)){ return("Please insert 'lat_max' parameter correctly and inject the node again. The parameter has to be numeric") } #--- if(long_max<=long_min){ return("Please insert 'long_max' and 'long_min' parameters correctly and inject the node again. The parameter 'long_max' has to be grather than 'long_min'") } if(lat_max<=lat_min){ return("Please insert 'lat_max' and 'lat_min' parameters correctly and inject the node again. The parameter 'lat_max' has to be grather than 'lat_min'") } #--- if(nchar(epsgProjection)==0){ return("Please insert 'epsgProjection' parameter correctly and inject the node again") }else{ epsgProjection = as.numeric(epsgProjection) } if(is.na(epsgProjection)){ return("Please insert 'epsgProjection' parameter correctly and inject the node again. The parameter has to be numeric") } #--- if(nchar(subnature)==0){ return("Please insert 'subnature' parameter correctly and inject the node again") } if(is.character(subnature)==F){ return("Please insert 'subnature' parameter correctly and inject the node again. The parameter has to be a string") } if(nchar(valueType)[1]==0){ return("Please insert 'valueType' parameter correctly and inject the node again") } if(is.character(valueType)[1]==F){ return("Please insert 'valueType' parameter correctly and inject the node again. The parameter has to be a string or an array of strings") } #--- IsDate <- function(mydate, date.format = "%Y-%m-%dT%H:%M:%S") { tryCatch(!is.na(as.Date(mydate, date.format)), error = function(err) {FALSE}) } #--- if(nchar(fromDateTime)==0){ return("Please insert 'fromDateTime' parameter correctly and inject the node again") } if(IsDate(fromDateTime)==F & str_detect(fromDateTime, "-day")==F & str_detect(fromDateTime, "-hour")==F){ return("Please insert 'fromDateTime' parameter correctly and inject the node again. The parameter has to be in a string format (n-hour or n-day) or in a date and time format (yyyy-mm-ddThh:mm:ss)") } #--- if(nchar(toDateTime)==0){ return("Please insert 'toDateTime' parameter correctly and inject the node again") } if(IsDate(toDateTime)==F){ return("Please insert 'toDateTime' parameter correctly and inject the node again. The parameter has to be in a date and time format (yyyy-mm-ddThh:mm:ss)") } #--- if(IsDate(fromDateTime)==T){ if(strptime(toDateTime, format= "%Y-%m-%dT%H:%M:%S") <= strptime(fromDateTime, format= "%Y-%m-%dT%H:%M:%S")){ return("Please insert 'fromDateTime' and 'toDateTime' parameters correctly and inject the node again. The parameter 'toDateTime' has to be a later date than 'fromDateTime'") } } #--- if(nchar(heatmapName)==0){ return("Please insert 'heatmapName' parameter correctly and inject the node again") } if(is.character(heatmapName)==F){ return("Please insert 'heatmapName' parameter correctly and inject the node again. The parameter has to be a string") } #--- if(nchar(colorMap)==0){ return("Please insert 'colorMap' parameter correctly and inject the node again") } if( colorMap!="airHumidity"& colorMap!="airQualityCO"& colorMap!="airQualityCO2"& colorMap!="airQualityNO2"& colorMap!="airQualityNOx"& colorMap!="airQualityO3"& colorMap!="airQualityPM10"& colorMap!="airQualityPM2_5"& colorMap!="airQualitySO2"& colorMap!="airTemperature"& colorMap!="Benzene"& colorMap!="dewPoint"& colorMap!="EnfuserAirQualityIndex"& colorMap!="HighDensityNO2"& colorMap!="HighDensityNOx"& colorMap!="HighDensityPM10"& colorMap!="HighDensityPM25"& colorMap!="LAeq"& colorMap!="maxTemperature"& colorMap!="minGroundTemperature"& colorMap!="minTemperature"& colorMap!="NO2"& colorMap!="noiseLA"& colorMap!="noiseLAeq"& colorMap!="noiseLAmax"& colorMap!="PM10"& colorMap!="PM2_5"& colorMap!="windGust"& colorMap!="windSpeed"){ return("The entered 'colorMap' parameter does not correspond to any color map. Please insert 'colorMap' parameter correctly and inject the node again") } #------------------------------------------------ #Via nodered the valueType parameter is not entered as an array but as a string. #Splitting of the elements and creation of the array: valueType=strsplit(valueType,",") valueType=unlist(valueType) print(valueType) metricName=colorMap sensorCategory=subnature print("--------- CHECK ON PARAMETERS END ---------") print(Sys.time()) print("------------------------------------------------") #------------------------------------------------------- # UPLOAD All Service Uris (sensor stations) In the Area #------------------------------------------------------- print("--------- UPLOAD ALL SENSOR STATIONS IN THE AREA OF INTEREST - START---------") print(Sys.time()) query <- paste("https://servicemap.disit.org/WebAppGrafo/api/v1/?selection=", lat_min,";", long_min,";", lat_max,";", long_max, "&categories=", sensorCategory, "&maxResults=0&maxDists=0.1&format=json", sep="") sensorCategoryJson <- fromJSON(query) #jsonlite package - upload data from json suri <- sensorCategoryJson$Services$features$properties$serviceUri #serviceUri list if(length(suri)==0){ return("No Sensor Station in the selected area. Please, correct the coordinates") } print("--------- UPLOAD ALL SENSOR STATIONS IN THE AREA OF INTEREST - END---------") print(Sys.time()) print("------------------------------------------------") #------------------------------------------------------------------- # Creation of a list with data per each station (serviceUri) # Upload data #------------------------------------------------------------------- sensorData <- vector("list", length(suri)) print("--------- UPLOAD DATA FOR EACH SENSOR STATION - START ---------") print(Sys.time()) for (i in 1:length(suri)){ temp=c() #SUPERSERVICEMAP api <- paste("https://www.disit.org/superservicemap/api/v1/?serviceUri=", suri[i], "&fromTime=", fromDateTime, "&toTime=", toDateTime, sep="") tryCatch({ sensorCategoryData <- fromJSON(api) if(length(sensorCategoryData$realtime)>0){ names(sensorData) <- suri sensorData[[i]]$sensorCoordinates <- sensorCategoryData$Service$features$geometry$coordinates[[1]] if (sensorCategoryData$Service$features$properties$name[[1]]==""){ sensorData[[i]]$sensorName <- paste(sensorCategory,i,sep="_") }else { sensorData[[i]]$sensorName <- sensorCategoryData$Service$features$properties$name[[1]] } variableNames <- colnames(sensorCategoryData$realtime$results$bindings)[-which(colnames(sensorCategoryData$realtime$results$bindings)=="measuredTime")] temp <- as.data.frame(matrix(NA, ncol=length(variableNames)+1, dim(sensorCategoryData$realtime$results$bindings)[1])) colnames(temp) <- colnames(sensorCategoryData$realtime$results$bindings) for (k in 1:length(variableNames)){ temp[,variableNames[k]] <- unlist(sensorCategoryData$realtime$results$bindings[variableNames[k]][,1][,1],use.names = FALSE) } temp[,"measuredTime"] <- sensorCategoryData$realtime$results$bindings$measuredTime timex=c() datex=c() dayx=c() timex=format(strptime(temp$measuredTime, "%Y-%m-%dT%H:%M"), "%H:%M") datex=format(strptime(temp$measuredTime, "%Y-%m-%dT%H:%M"), "%Y-%m-%d") dayx=weekdays(as.Date(datex)) #rounding time slots every 10 minutes for(j in 1:length(timex)){ if(substr(timex[j],5,5)!=0){ if(substr(timex[j],4,5)=="59" | substr(timex[j],4,5)=="58" | substr(timex[j],4,5)=="57" | substr(timex[j],4,5)=="56"){ hour=as.numeric(substr(timex[j],1,2)) if(hour==23){ timex[j]="00:00" }else if(substr(timex[j],1,2)=="00"){ timex[j]="01:00" }else { if(substr(timex[j],1,1)=="0" & substr(timex[j],1,2)!="09"){ timex[j]=paste("0",hour+1,":00",sep="") }else if(substr(timex[j],1,1)!="0" | substr(timex[j],1,2)=="09") { timex[j]=paste(hour+1,":00",sep="") } } }else if(substr(timex[j],5,5)=="9" | substr(timex[j],5,5)=="8" | substr(timex[j],5,5)=="7" | substr(timex[j],5,5)=="6"){ minute=as.numeric(substr(timex[j],4,4)) timex[j]=paste(substr(timex[j],1,3),minute+1,"0",sep="") }else if(substr(timex[j],5,5)=="1" | substr(timex[j],5,5)=="2" | substr(timex[j],5,5)=="3" | substr(timex[j],5,5)=="4"){ timex[j]=paste(substr(timex[j],1,4),"0",sep="") } } } #saving time date day measures in temp matrix and in sensorData[[i]]$sensorRealtimeData list temp[,"time"] <- timex temp[,"date"] <- datex temp[,"day"] <- dayx temp[,"dateTime"] <- paste(datex, paste(timex, "00", sep=":"), sep="T") temp <- temp[order(temp[,"measuredTime"]), ] temp[,"sensorName"] <- sensorData[[i]]$sensorName sensorData[[i]]$sensorRealtimeData <- temp } }, error=function(e){ print(paste("Error on ServiceUri: ", suri[i], sep="")) }) } print("--------- SensorData List Creation Completed ---------") print("--------- UPLOAD DATA FOR EACH SENSOR STATION - END ---------") print(Sys.time()) print("------------------------------------------------") #------------------------------------------------------------------- # List For Messages #------------------------------------------------------------------- infoHeatmap=list("heatmapName"=heatmapName, "dateTime"=toDateTime) infoHeatmap$message=list() #--------------------------------------------------------------------------------------------------------------------------------------# #--------------------------------------------------------------------------------------------------------------------------------------# #------------------------------------------------ DATA MANIPULATION -------------------------------------------------------------------# #--------------------------------------------------------------------------------------------------------------------------------------# #--------------------------------------------------------------------------------------------------------------------------------------# print("--------- DATA MANIPULATION -- START ---------") print(Sys.time()) #------------------------------------------------------------------- #drop empty suri #------------------------------------------------------------------- print("--------- 1. Drop empty ServiceUris ---------") indexNull=c() for(h in 1:length(sensorData)){ if (length(sensorData[[h]]$sensorRealtimeData)==0){ index=h indexNull=c(indexNull,index) } } if(length(indexNull)>0){ sensorData=sensorData[-indexNull] } if(length(sensorData) == 0){ infoHeatmap$message=paste("No Availabe Data for", valueType) return(infoHeatmap) } #------------------------------------------------------------------- # CONTROL on the names of airQuality variables #------------------------------------------------------------------- print("--------- 2. Check on ValueType ---------") valTypeIndex=c() valTypeIndexTemp=c() varNameList=c() varNameListTemp=c() sensorDataIndexTemp=c() sensorDataIndex=c() for(i in 1:length(sensorData)){ dattemp= sensorData[[i]]$sensorRealtimeData for(t in 1:length(valueType)){ ind=which(names(dattemp) == valueType[t]) if(length(ind)>0){ sensorDataIndexTemp=i valTypeIndexTemp=which(names(dattemp) == valueType[t]) varNameListTemp=valueType[t] } } valTypeIndex = c(valTypeIndex,valTypeIndexTemp) varNameList = c(varNameList, varNameListTemp) sensorDataIndex = c(sensorDataIndex,sensorDataIndexTemp) } namesMatrix=as.data.frame(cbind(sensorDataIndex,varNameList,valTypeIndex)) if(is.null(varNameList)){ print("The valueType is uncorrect. Please, change the parameter and inject the node again") return("The valueType is uncorrect. Please, change the parameter and inject the node again") } print("--------- 3. Average Values Matrix creation and null values editing ---------") data=matrix(NA, ncol=3, nrow=length(sensorData)) colnames(data)=c("lat", "long", "value") for(j in 1:length(sensorData)){ temp = sensorData[[j]]$sensorRealtimeData temp = temp[ , which(colnames(temp)!="measuredTime" & colnames(temp)!="time" & colnames(temp)!="date" & colnames(temp)!="dateObserved" & colnames(temp)!="reliability" & colnames(temp)!="source" & colnames(temp)!="day" & colnames(temp)!="sensorName")] varName = as.character(namesMatrix[which(sensorDataIndex==j), "varNameList"]) print(paste("sensorData:", j)) print(varName) tempNew=temp[, which(colnames(temp)==varName | colnames(temp)=="dateTime")] sensorData[[j]]$indexValues=tempNew #null values editing if(length(which(tempNew[,varName]=="null" | tempNew[,varName]=="#" | tempNew[,varName]=="" | tempNew[,varName]=="NULL" | is.nan(tempNew[,varName])==T | tempNew[,varName]== -9999 | tempNew[,varName]=="-9999"))>0){ nullIndex = which(tempNew[,varName]=="null" | tempNew[,varName]=="#" | tempNew[,varName]=="" | tempNew[,varName]=="NULL" | is.nan(tempNew[,varName])==T | tempNew[,varName]== -9999 | tempNew[,varName]=="-9999") tempNew[nullIndex, varName] = NA } if(is.null(tempNew[,varName])){ print(paste("No Available Measures for the Variable '", varName,"' in ServiceUri '", names(sensorData)[i],"'", sep="")) data[j, "value"] = NA data[j, "lat"] = as.numeric(sensorData[[j]]$sensorCoordinates)[2] data[j, "long"] = as.numeric(sensorData[[j]]$sensorCoordinates)[1] }else if(length(which(is.na(tempNew[,varName])))==length(tempNew[,varName])){ print(paste("No Available Measures for the Variable '", varName,"' in ServiceUri '", names(sensorData)[i],"'", sep="")) data[j, "value"] = NA data[j, "lat"] = as.numeric(sensorData[[j]]$sensorCoordinates)[2] data[j, "long"] = as.numeric(sensorData[[j]]$sensorCoordinates)[1] }else{ data[j, "value"] = mean(as.numeric(tempNew[,varName]), na.rm = T) data[j, "lat"] = as.numeric(sensorData[[j]]$sensorCoordinates)[2] data[j, "long"] = as.numeric(sensorData[[j]]$sensorCoordinates)[1] } } if(sum(is.na(data[,"value"])) == length(data[,"value"])){ infoHeatmap$message=paste("No Availabe Data for", valueType,": All ServiceUris are empty") return(infoHeatmap) } #correzione finale 9999 e -9999 index9999=which(data[,"value"]==-9999 | data[,"value"]==9999) if(length(index9999)>0){ data[index9999,"value"]=NA } print("--------- DATA MANIPULATION -- END ---------") print(Sys.time()) print("------------------------------------------------") #--------------------------------------------------------------------------------------------------------------------------------------# print("--------- LAT-LONG BBOX CONVERSION TO UTM - START---------") print(Sys.time()) long_min=as.numeric(long_min) long_max=as.numeric(long_max) lat_min=as.numeric(lat_min) lat_max=as.numeric(lat_max) long=c(long_min ,long_max) lat=c(lat_min ,lat_max) bboxCoordinates <- data.frame(long, lat) print(bboxCoordinates) names(bboxCoordinates) <- c("X", "Y") coordinates(bboxCoordinates) <- c("X", "Y") proj4string(bboxCoordinates) <- CRS("+proj=longlat +datum=WGS84") #utm_coordinates = as.data.frame(spTransform(coordinates, CRS("+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs"))) utm_bboxCoordinates = as.data.frame(spTransform(bboxCoordinates, CRS(paste("+init=epsg:",epsgProjection,sep="")))) print("utm_bboxCoordinates") print(utm_bboxCoordinates) x <- c(utm_bboxCoordinates$X[2], utm_bboxCoordinates$X[1]) y <- c(utm_bboxCoordinates$Y[2], utm_bboxCoordinates$Y[1]) xy <- cbind(x,y) city_bbox <- SpatialPoints(xy, proj4string = CRS("+proj=longlat")) print("city_bbox") print(city_bbox) print("--------- LAT-LONG BBOX CONVERSION TO UTM - END ---------") print(Sys.time()) print("------------------------------------------------") #--------------------------------------------------------------------------------------------------------------------------------------# #--------------------------------------------------------------------------------------------------------------------------------------# #------------------------------------------------ DATA INTERPOLATION ------------------------------------------------------------------# #--------------------------------------------------------------------------------------------------------------------------------------# #--------------------------------------------------------------------------------------------------------------------------------------# print("--------- DATA INTERPOLATION - START ---------") print(Sys.time()) if(dim(data)[1]>3){ data=na.omit(data) data=as.data.frame(data) data=unique(data) value = data.frame("value" = data[,"value"]) coordinates <- data.frame(data[,"long"],data[,"lat"]) names(coordinates) <- c("X", "Y") coordinates(coordinates) <- c("X", "Y") proj4string(coordinates) <- CRS("+proj=longlat +datum=WGS84") #utm_coordinates = as.data.frame(spTransform(coordinates, CRS("+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs"))) utm_coordinates = as.data.frame(spTransform(coordinates, CRS(paste("+init=epsg:",epsgProjection,sep="")))) #stations <- SpatialPointsDataFrame(utm_coordinates, value, proj4string =CRS("+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs")) stations <- SpatialPointsDataFrame(utm_coordinates, value, proj4string = CRS(paste("+init=epsg:",epsgProjection,sep=""))) stations <- stations[!is.na(stations$value),] stations@bbox <- bbox(city_bbox) #Define grid grd <- as.data.frame(spsample(stations, "regular", n=10000)) names(grd) <- c("X", "Y") coordinates(grd) <- c("X", "Y") gridded(grd) <- TRUE # Create SpatialPixel object fullgrid(grd) <- TRUE # Create SpatialGrid object # Add stations's projection information to the empty grid proj4string(grd) <- proj4string(stations) # Interpolate the grid cells stations.idw <- gstat::idw(value ~ 1, stations, newdata=grd, idp=2.0) coordGrd=round(coordinates(grd),0) interpolatedData=cbind(coordGrd,stations.idw$var1.pred) interpolatedData=as.data.frame(interpolatedData) colnames(interpolatedData)=c("X","Y","V3") xLength=round(as.numeric(stations.idw@grid@cellsize["X"]),0) yLength=round(as.numeric(stations.idw@grid@cellsize["Y"]),0) }else{ infoHeatmap$message="No sufficient number of data for interpolation" return(infoHeatmap) } print("interpolatedData dim:") print(dim(interpolatedData)[1]) print("--------- DATA INTERPOLATION - END ---------") print(Sys.time()) print("------------------------------------------------") #------------------------------------------------------------ # HEATMAP LIST #------------------------------------------------------------ # List containing the interpolated data - UTM COORDINATES #------------------------------------------------------------ print("--------- INTERPOLATED DATA LIST CREATION - START ---------") print(Sys.time()) interpolatedHeatmap=vector("list", dim(interpolatedData)[1]) statusCode200 = 0; interpolatedHeatmap=list() interpolatedHeatmap$attributes=vector("list", dim(interpolatedData)[1]) interpolatedHeatmap$saveStatus=list() for(i in 1:dim(interpolatedData)[1]) { #list x = as.numeric(interpolatedData[i, "X"]) y = as.numeric(interpolatedData[i, "Y"]) meanObs = as.numeric(interpolatedData[i, "V3"]) listAttribTemp = list("mapName"=heatmapName, "metricName"= metricName, "description"= paste("Average from",fromDateTime,"to",toDateTime,sep=" "), "clustered"= 0, "latitude"=x, "longitude"=y, "value"= meanObs, "date"= paste(toDateTime, "Z", sep=""),"xLength"=xLength, "yLength"=yLength, "projection"=epsgProjection, "file"=0, "org"="DISIT") interpolatedHeatmap$attributes[[i]]=listAttribTemp } print("interpolatedHeatmap list length:") print(length(interpolatedHeatmap$attributes)) print("--------- INTERPOLATED DATA LIST CREATION - END ---------") print(Sys.time()) print("------------------------------------------------") #--------------------------------------------------------------------------------------------------------------------------------------# #--------------------------------------------------------------------------------------------------------------------------------------# #------------------------------------------------ SAVE INTERP RESULTS -----------------------------------------------------------------# #--------------------------------------------------------------------------------------------------------------------------------------# #--------------------------------------------------------------------------------------------------------------------------------------# print("--------- SAVING INTERPOLATED DATA LIST - START ---------") print(Sys.time()) request_body_json <- toJSON(interpolatedHeatmap$attributes, auto_unbox = TRUE, digits = 10) # resultPOST <- POST(url = "http://snap4city:disit2019@192.168.0.59:8000/insertArray", # body = request_body_json, # encode = "json", add_headers("Content-Type" = "application/json"), config(forbid.reuse = 1)) my_handle <- handle("http://snap4city:disit2019@192.168.0.59:8000/") resultPOST <- POST(handle=my_handle, path="insertArray", body = request_body_json, url = NULL, encode = "json", add_headers("Content-Type" = "application/json")) rm(my_handle) interpolatedHeatmap$saveStatus=resultPOST$status_code if(resultPOST$status_code == 200){ print("StatusCode 200") completed = 1 }else{ print("Completed Status = 0") completed = 0 } apiFinal <- paste("http://192.168.0.59/setMap.php?mapName=",heatmapName, "&metricName=",metricName, "&date=",paste(toDateTime, "Z", sep=""), "&completed=", completed, sep="") resultPOST <- GET(url = apiFinal) resultPOST$status_code print("Return SensorHeatmap List") print("--------- SAVING INTERPOLATED DATA LIST - END ---------") print(Sys.time()) print("------------------------------------------------") #------------------------------------------------ infoHeatmap$message="Interpolation and Heatmap Completed" print("Interpolation and Heatmap Completed") if(resultPOST$status_code==200){ infoHeatmap$POSTstatus = "Interpolated data saved correctly" print("Interpolated data saved correctly") }else{ infoHeatmap$POSTstatus = "Problems on saving interpolated data" print("Problems on saving interpolated data") } print(ls()) rm(list=setdiff(ls(), "infoHeatmap")) print(ls()) return(infoHeatmap) #------------------------------------------------ }