@stepan-ozana
Dear Štěpán,
I can confirm that the Matlab script behaves the same way for me as it does for you. Thanks for reporting the bug. Can you please test the following modified script? This modification works for me:
clc;
clear all;
serviceUrl = 'http://192.168.100.2:8008';
username = 'admin';
password = '';
% Data to be written
value_double = 17.89;
value_long = 1234;
value_bool = 1;
value_string = "External string";
% URLs of the data points
url_double = "/api/tasks/rest_api_task/CNR_IN:ycn";
url_long = "/api/tasks/rest_api_task/CNI_IN:icn";
url_bool = "/api/tasks/rest_api_task/CNB_IN:YCN";
url_string = "/api/tasks/rest_api_task/CNS_IN:scv";
% Basic authentication header
credentials = base64encode([username ':' password]);
authHeader = ['Basic ' credentials];
% Writing data type double
data_double = struct('v', value_double);
writeData(serviceUrl, url_double, data_double, authHeader);
% Writing data type long
data_long = struct('v', value_long);
writeData(serviceUrl, url_long, data_long, authHeader);
% Writing data type Boolean
data_bool = struct('v', value_bool);
writeData(serviceUrl, url_bool, data_bool, authHeader);
% Writing data type string
data_string = struct('v', value_string);
writeData(serviceUrl, url_string, data_string, authHeader);
% Function to encode base64
function encoded = base64encode(str)
encoder = java.util.Base64.getEncoder();
encoded = char(encoder.encodeToString(uint8(str)));
end
% Function to write data to the server
function writeData(serviceUrl, url, data, authHeader)
options = weboptions('RequestMethod', 'post', ...
'ContentType', 'json', ...
'MediaType', 'application/json', ...
'HeaderFields', {'Authorization', authHeader});
try
response = webwrite(strcat(serviceUrl, url), data, options);
disp(['Successfully wrote data to ', url]);
catch ME
fprintf('Error writing data to %s:\n%s\n', url, ME.message);
end
end
Cheers,
Jan