diff --git a/CHANGELOG.md b/CHANGELOG.md index 067f143..7daa7f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ # Changelog All notable changes to this project will be documented in this file. +## Release 2.3.0 + +### Improvements +- Dynamically created function "sendRequestNUM" return now the HTTPClient.Response as second return value. +- Parameter "logContent" within "sendRequestNUM" function can configure if the full HTTP response content should be logged. Set to FALSE to prevent unnecessary high processing loads for bigger data content like images. + +### Bugfix +- Headers did not work via sendRequestNUM +- Headers were mixed up for requests send via UI and sendRequestNUM function + ## Release 2.2.0 ### New features diff --git a/CSK_Module_MultiHTTPClient/project.mf.xml b/CSK_Module_MultiHTTPClient/project.mf.xml index fd5488a..5fdc279 100644 --- a/CSK_Module_MultiHTTPClient/project.mf.xml +++ b/CSK_Module_MultiHTTPClient/project.mf.xml @@ -529,9 +529,11 @@ Needs then to be called via "Script.callFunction". - + + + @@ -563,7 +565,7 @@ Needs then to be called via "Script.callFunction". SICK AG - 2.2.0 + 2.3.0 low false false diff --git a/CSK_Module_MultiHTTPClient/scripts/CSK_MultiHTTPClient_Processing.lua b/CSK_Module_MultiHTTPClient/scripts/CSK_MultiHTTPClient_Processing.lua index 299e887..903e007 100644 --- a/CSK_Module_MultiHTTPClient/scripts/CSK_MultiHTTPClient_Processing.lua +++ b/CSK_Module_MultiHTTPClient/scripts/CSK_MultiHTTPClient_Processing.lua @@ -190,8 +190,10 @@ end ---@param tempRequestActive bool Status if it is just a temporarly configured request or a preconfigured one ---@param showResponse bool Status if response should be notified as event (e.g. to show it on UI) ---@param eventName string? Optional name of event to notify the response +---@param logContent bool? Set status if full respond content should be logged ---@return string response Response of HTTP request -local function sendInternalRequest(tempRequestActive, showResponse, eventName) +---@return HTTPClient.Response response Response of HTTP request +local function sendInternalRequest(tempRequestActive, showResponse, eventName, logContent) local timerQueueSize = 0 local eventQueueSize = 0 @@ -248,8 +250,10 @@ local function sendInternalRequest(tempRequestActive, showResponse, eventName) end end - jsonResponse.Response = HTTPClient.Response.getContent(response) - responseMessage = responseMessage .. helperFuncs.jsonLine2Table(HTTPClient.Response.getContent(response)) .. '\n' + if logContent then + responseMessage = responseMessage .. helperFuncs.jsonLine2Table(HTTPClient.Response.getContent(response)) .. '\n' + jsonResponse.Response = HTTPClient.Response.getContent(response) + end else local error = HTTPClient.Response.getError(response) local errorDetail = HTTPClient.Response.getErrorDetail(response) @@ -268,12 +272,26 @@ local function sendInternalRequest(tempRequestActive, showResponse, eventName) Script.notifyEvent("MultiHTTPClient_OnNewValueToForward" .. multiHTTPClientInstanceNumberString, "MultiHTTPClient_OnNewResponseMessage", responseMessage) end end - return json.encode(jsonResponse) + local encodedData = json.encode(jsonResponse) + return encodedData, response end end -local function sendRequest(mode, endpoint, port, header, body, contentType) - processingParams.extendedResponse = true +local function sendRequest(mode, endpoint, port, header, body, contentType, logContent) + processingParams.headers = {} + if header ~= nil and header ~= '' then + local headerTable = json.decode(header) + for key, value in pairs(headerTable) do + processingParams.headers[key] = value + end + end + + if contentType ~= nil then + processingParams.requestContentType = contentType + else + processingParams.requestContentType = 'application/json' + end + processingParams.requestMode = mode processingParams.requestEndpoint = endpoint processingParams.requestPort = port @@ -284,11 +302,16 @@ local function sendRequest(mode, endpoint, port, header, body, contentType) processingParams.requestContent = '' end - local response = sendInternalRequest(true, false) + local responseString, response + if logContent == true or logContent == nil then + responseString, response = sendInternalRequest(true, false, nil, true) + else + responseString, response = sendInternalRequest(true, false, nil, false) + end - return response + return responseString, response end -Script.serveFunction('CSK_MultiHTTPClient.sendRequest' .. multiHTTPClientInstanceNumberString, sendRequest, 'string, string, int, string:?, string:?, string:?', 'string') +Script.serveFunction('CSK_MultiHTTPClient.sendRequest' .. multiHTTPClientInstanceNumberString, sendRequest, 'string, string, int, string:?, string:?, string:?, bool:?', 'string:1, object:?:HTTPClient.Response') --- Function to set timer if request should be executed periodically ---@param requestName string Name of preconfigured request @@ -303,9 +326,9 @@ local function setTimer(requestName) if processingParams.clientActivated then setSpecificRequest(requestName) if selectedRequest == requestName then - sendInternalRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) + sendInternalRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName, true) else - sendInternalRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) + sendInternalRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName, true) end end end @@ -349,9 +372,9 @@ local function setRegisteredEvent(requestName) end setSpecificRequest(requestName) if selectedRequest == requestName then - sendInternalRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) + sendInternalRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName, true) else - sendInternalRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) + sendInternalRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName, true) end end end @@ -544,14 +567,18 @@ local function handleOnNewProcessingParameter(multiHTTPClientNo, parameter, valu elseif parameter == 'sendRequest' then if processingParams.clientActivated then - sendInternalRequest(true, true) + sendInternalRequest(true, true, nil, true) end - elseif parameter == 'headerUpdate' then - processingParams.headers[value] = value2 + elseif parameter == 'setHeaders' then + processingParams.headers = {} - elseif parameter == 'deleteHeader' then - deleteHeader(value) + if value ~= nil and value ~= '""' then + local headerTable = json.decode(value) + for headerKey, headerValue in pairs(headerTable) do + processingParams.headers[headerKey] = headerValue + end + end elseif parameter == 'selectedRequest' then if value then diff --git a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Controller.lua b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Controller.lua index 6c80d89..727f2f0 100644 --- a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Controller.lua +++ b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Controller.lua @@ -669,6 +669,15 @@ Script.serveFunction('CSK_MultiHTTPClient.setRequestPort', setRequestPort) local function sendRequestViaUI() if multiHTTPClient_Instances[selectedInstance].parameters.clientActivated == true then + Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'requestMode', multiHTTPClient_Instances[selectedInstance].requestMode) + Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'requestEndpoint', multiHTTPClient_Instances[selectedInstance].requestEndpoint) + Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'requestPort', multiHTTPClient_Instances[selectedInstance].requestPort) + + Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'setHeaders', json.encode(multiHTTPClient_Instances[selectedInstance].headers)) + + Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'requestContentType', multiHTTPClient_Instances[selectedInstance].requestContentType) + Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'requestContent', multiHTTPClient_Instances[selectedInstance].requestContent) + Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'sendRequest') else _G.logger:fine(nameOfModule .. ": Client currently not active.") @@ -703,7 +712,6 @@ local function addHeader() _G.logger:fine(nameOfModule .. ": Add header key = " .. tostring(multiHTTPClient_Instances[selectedInstance]['headerKey']) .. " with value = " .. tostring(multiHTTPClient_Instances[selectedInstance]['headerValue'])) multiHTTPClient_Instances[selectedInstance].headers[multiHTTPClient_Instances[selectedInstance]['headerKey']] = multiHTTPClient_Instances[selectedInstance]['headerValue'] multiHTTPClient_Instances[selectedInstance].selectedHeaderKey = multiHTTPClient_Instances[selectedInstance]['headerKey'] - Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'headerUpdate', multiHTTPClient_Instances[selectedInstance]['headerKey'], multiHTTPClient_Instances[selectedInstance]['headerValue']) handleOnExpiredTmrMultiHTTPClient() end Script.serveFunction('CSK_MultiHTTPClient.addHeader', addHeader) @@ -712,7 +720,6 @@ local function deleteHeader() _G.logger:fine(nameOfModule .. ": Delete header key = " .. tostring(multiHTTPClient_Instances[selectedInstance]['headerKey'])) multiHTTPClient_Instances[selectedInstance].headers[multiHTTPClient_Instances[selectedInstance]['headerKey']] = nil collectgarbage() - Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'deleteHeader', multiHTTPClient_Instances[selectedInstance]['headerKey']) local check = false for key, _ in pairs(multiHTTPClient_Instances[selectedInstance].headers) do diff --git a/README.md b/README.md index 385ed67..50b1255 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Tested on |Device|Firmware|Module version| |--|--|--| +|SIM800|V1.2.0|V2.3.0| |SICK AppEngine|V1.7.0|V2.2.0| |SICK AppEngine|V1.7.0|V2.0.0| |SIM1012|V2.4.2|V2.1.0| diff --git a/docu/CSK_Module_MultiHTTPClient.html b/docu/CSK_Module_MultiHTTPClient.html index 664539f..6aa0a07 100644 --- a/docu/CSK_Module_MultiHTTPClient.html +++ b/docu/CSK_Module_MultiHTTPClient.html @@ -6,7 +6,7 @@ -Documentation - CSK_Module_MultiHTTPClient 2.2.0 +Documentation - CSK_Module_MultiHTTPClient 2.3.0