Hi,
I'm trying to connect to server to send some data and I'm having problem with HTTPS connection, specifically with TLS set-up. I'm getting HTTP_REQ_CONN_TIMEDOUT on FB_IotHttpRequest function block.
According to my server provider I'm using valid certificates and port.
I can ping the server from IPC and plain HTTP works fine.
The code is very simple and done according to the sample.
I wrote to Beckhoff support too, but they are yet to answer.
This is my first time working with HTTPS and cloud services.
Below th code. As you can see there is not much I can change there.
I'm trying to connect to server to send some data and I'm having problem with HTTPS connection, specifically with TLS set-up. I'm getting HTTP_REQ_CONN_TIMEDOUT on FB_IotHttpRequest function block.
According to my server provider I'm using valid certificates and port.
I can ping the server from IPC and plain HTTP works fine.
The code is very simple and done according to the sample.
I wrote to Beckhoff support too, but they are yet to answer.
This is my first time working with HTTPS and cloud services.
Below th code. As you can see there is not much I can change there.
Code:
VAR
IoThttpCLIENT: FB_iothttpclient := (sHostName := 'deleted',
bKeepAlive := FALSE,
tConnectionTimeout := T#10S);
Connect: BOOL;
Connect_TOF: TOF;
Post: fbJsonPost;
Send: BOOL;
Keep: BOOL;
Busy: BOOL;
Error: BOOL;
Code:
IF NOT IoThttpCLIENT.bConfigured THEN
IoThttpCLIENT.stTLS.sCA := 'C:\Users\GriegLSI001\Crt\fullchain1.pem';
IoThttpCLIENT.stTLS.sCert := 'C:\Users\GriegLSI001\Crt\cert1.pem';
IoThttpCLIENT.stTLS.sKeyFile := 'C:\Users\GriegLSI001\Crt\privkey1.pem';
IoThttpCLIENT.nHostPort := 443;
END_IF
IF Connect THEN
IoThttpCLIENT.Execute();
ELSE
IoThttpCLIENT.Disconnect();
END_IF
IF IoThttpCLIENT.bConfigured THEN
Post(bSend:=Send, fbClient:=IoThttpCLIENT, bBusy => Busy, bError => Error, bKeepSending := Keep);
END_IF
Code:
FUNCTION_BLOCK fbJsonPost
VAR_INPUT
bSend: BOOL;
bKeepSending: BOOL;
END_VAR
VAR_OUTPUT
bBusy: BOOL;
bError: BOOL;
END_VAR
VAR
R_TRIG: R_TRIG;
sContent: SJsonValue;
sContent_2: STRING(511);
nState: USINT;
RN: DRAND;
JsonDomParser: FB_JsonDomParser;
JsonWriter: FB_JsonSaxWriter;
fbRequest: FB_IotHttpRequest;
header: FB_IotHttpHeaderFieldMap;
TON: TON;
test: BOOL;
END_VAR
VAR_IN_OUT
fbClient: FB_IotHttpClient;
END_VAR
Code:
CASE nState OF
0: R_TRIG(CLK := bSend);
IF R_TRIG.Q OR bKeepSending THEN
sContent := JsonDomParser.NewDocument();
JsonDomParser.AddStringMember(sContent, 'key', 'sensor');
JsonDomParser.AddIntMember(sContent, 'value', DINT_TO_UDINT(fbClient.nMessagesSent));
sContent_2 := JsonDomParser.GetDocument();
nState := 1;
END_IF
1: fbRequest.SendJsonDomRequest(sUri:= '', fbClient:= fbClient,
eRequestType := ETcIotHttpRequestType.HTTP_POST,
fbJson := JsonDomParser, fbHeader := header);
nState := 2;
2: IF NOT fbRequest.bBusy THEN
nState := 0;
test := TRUE;
JsonDomParser.RemoveAllMembers(sContent);
END_IF
END_CASE
bBusy := fbRequest.bBusy;