Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions CSK_Module_MultiHTTPClient/project.mf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,11 @@ Needs then to be called via "Script.callFunction".</desc>
<param desc="Endpoint" multiplicity="1" name="endpoint" type="string"/>
<param desc="Port" multiplicity="1" name="port" type="int"/>
<param desc="Optional list of headers (JSON)." multiplicity="?" name="header" type="string"/>
<param desc="Body content (JSON)." multiplicity="?" name="body" type="string"/>
<param desc="Optional body content (JSON)." multiplicity="?" name="body" type="string"/>
<param desc="Type of content." multiplicity="?" name="contentType" type="string"/>
<param desc="Set status if full respond content should be logged.&#10;Set to false if e.g. bigger binary data should not be processed." multiplicity="?" name="logContent" type="bool"/>
<return desc="Response (JSON)" multiplicity="1" name="response" type="string"/>
<return alias="HTTPClient.Response" desc="Response" multiplicity="?" name="response" type="object"/>
</function>
</serves>
</crown>
Expand Down Expand Up @@ -563,7 +565,7 @@ Needs then to be called via "Script.callFunction".</desc>
</crown>
</crown>
<meta key="author">SICK AG</meta>
<meta key="version">2.2.0</meta>
<meta key="version">2.3.0</meta>
<meta key="priority">low</meta>
<meta key="copy-protected">false</meta>
<meta key="read-protected">false</meta>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
34 changes: 24 additions & 10 deletions docu/CSK_Module_MultiHTTPClient.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.12">
<meta name="author" content="SICK AG">
<title>Documentation - CSK_Module_MultiHTTPClient 2.2.0</title>
<title>Documentation - CSK_Module_MultiHTTPClient 2.3.0</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
/* Stylesheet for CodeRay to match GitHub theme | MIT License | http://foundation.zurb.com */
Expand Down Expand Up @@ -615,11 +615,11 @@
</head>
<body class="article toc2 toc-left">
<div id="header">
<h1>Documentation - CSK_Module_MultiHTTPClient 2.2.0</h1>
<h1>Documentation - CSK_Module_MultiHTTPClient 2.3.0</h1>
<div class="details">
<span id="author" class="author">SICK AG</span><br>
<span id="revnumber">version 2.2.0,</span>
<span id="revdate">2025-05-28</span>
<span id="revnumber">version 2.3.0,</span>
<span id="revdate">2026-01-30</span>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
Expand Down Expand Up @@ -805,11 +805,11 @@ <h2 id="_document_metadata">Document metadata</h2>
</tr>
<tr>
<th class="tableblock halign-left valign-top"><p class="tableblock">Version</p></th>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.2.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.3.0</p></td>
</tr>
<tr>
<th class="tableblock halign-left valign-top"><p class="tableblock">Date</p></th>
<td class="tableblock halign-left valign-top"><p class="tableblock">2025-05-28</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2026-01-30</p></td>
</tr>
<tr>
<th class="tableblock halign-left valign-top"><p class="tableblock">Author</p></th>
Expand Down Expand Up @@ -1868,14 +1868,21 @@ <h6 id="_parameters_5">Parameters</h6>
<td class="tableblock halign-left valign-top"><p class="tableblock">body</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">STRING</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">?</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Body content (JSON).</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional body content (JSON).</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">contentType</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">STRING</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">?</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Type of content.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">logContent</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">BOOL</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">?</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Set status if full respond content should be logged.
Set to false if e.g. bigger binary data should not be processed.</p></td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -1903,14 +1910,21 @@ <h6 id="_return_values_6">Return values</h6>
<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Response (JSON)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">response</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">OBJECT<br>
<a href="#API:Crown:HTTPClient.Response">HTTPClient.Response</a></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">?</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Response</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect5">
<h6 id="_sample_auto_generated_17">Sample (auto-generated)</h6>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="lua">response = CSK_MultiHTTPClient.sendRequestNUM(mode, endpoint, port, header, body, contentType)</code></pre>
<pre class="CodeRay highlight"><code data-lang="lua">response, response = CSK_MultiHTTPClient.sendRequestNUM(mode, endpoint, port, header, body, contentType, logContent)</code></pre>
</div>
</div>
</div>
Expand Down Expand Up @@ -6703,8 +6717,8 @@ <h3 id="API:Enum:CSK_MultiHTTPClient.RequestMode"><span class="api-enum">CSK_Mul
</div>
<div id="footer">
<div id="footer-text">
Version 2.2.0<br>
Last updated 2025-05-28 13:47:20 +0200
Version 2.3.0<br>
Last updated 2026-01-30 16:27:21 +0100
</div>
</div>
<script type="text/javascript">
Expand Down