Ponieważ okazało się, że stacja po kilku(nastu) dniach zaczna "mulić" aż do zawieszenia wprowadziłem bloczek resetujący stację (a właściwie odbiornik) co 24h.
Wejście xDelay należy połączyć z xStart bloku WH2600_weather, aby nie próbował resetować stacji podczas odczytu danych.
Deklaracje:
FUNCTION_BLOCK WH2600_resetter
(* Resetter for Renkforce WH2600 Weather Station (Weather Logger 1.1)
Based on pWorldWeatherForecast
31.05.2015 Marcin Rudzki
*)
VAR_INPUT
sAddress: STRING := '192.168.2.195';
xDelay: BOOL := FALSE; (* if TRUE reset will be delayed until FALSE *)
END_VAR
VAR_OUTPUT
sStatus: STRING;
diError: DINT;
END_VAR
VAR_IN_OUT
xStart : BOOL; (* trigger *)
END_VAR
VAR
wStateMachine: WORD;
(* Function block HTTP_GET *)
oHTTP_GET:HTTP_GET;(* Input variables: *)
oHttp_sServerName : STRING ; (* Hostname or server IP in dotted normal form *)
oHttp_pabUrlData : POINTER TO ARRAY [0..MAX_RECEIVE_TCP_CLIENT] OF BYTE ; (* The HTTP-GET-Request *)
oHttp_uiUrlLength : UINT ; (* Length of HTTP-GET-Request *)
oHttp_tTimeOut : TIME := t#24s; (* WatchDogTime, operation aborted after time is elapsed *)
oHttp_xSend : BOOL ;
oHttp_diError : DINT ; (* 0 == successful *)
oHttp_sStatus : STRING(255) ;
oHttp_abContentData : ARRAY [0..MAX_RECEIVE_TCP_CLIENT] OF BYTE ; (* The HTTP response *)
oHttp_uiContentLength : UINT ; (* Length of HTTP response in byte *)
(* Function block HTTP_GET helper *)
sUrl: STRING(250);
sUrlHelp: STRING(250);
(* HTML file *)
abXmlFileStream : ARRAY [0..MAX_RECEIVE_TCP_CLIENT] OF BYTE ; (* The HTTP response *)
uiXmlFileStreamLen : UINT ; (* Length of HTTP response in byte *)
pabXmlHandler : POINTER TO ARRAY [0..MAX_RECEIVE_TCP_CLIENT] OF BYTE;
uiXmlHandlerIndex: UINT;
uiXmlStreamLen: UINT;
sSearchedString: STRING(105);
xFail: BOOL;
sHTTP_Response: STRING;
(* Helpers *)
uiPos: UINT;
iFails: INT := 0;
END_VAR
VAR CONSTANT
iFailsMax: INT := 5;
END_VAR
Kod:
(* Function block HTTP_GET instance *)
oHTTP_GET (
(* Input variables: *)
sServerName := sAddress ,
wServerPort := 80 ,
pabUrlData := oHttp_pabUrlData,
uiUrlLength := oHttp_uiUrlLength,
tTimeOut := oHttp_tTimeOut,
(* Input/output variables: *)
xSend := oHttp_xSend,
(* Output variables: *)
diError => oHttp_diError,
sStatus => oHttp_sStatus,
abContentData => oHttp_abContentData ,
uiContentLength => oHttp_uiContentLength
);
CASE wStateMachine OF
0: (* Init *)
IF xStart AND NOT xDelay THEN
(* Url builder *)
sUrl := '/msgreboot.htm';
(* Set HTTP_GET *)
oHttp_pabUrlData := ADR(sUrl);
oHttp_uiUrlLength := LEN(sUrl);
(* Process HTTP_GET *)
oHttp_xSend := TRUE;
wStateMachine := 10;
END_IF
10: (* Process the HTTP reguest *)
IF NOT oHttp_xSend THEN
IF oHttp_diError = 0 THEN
(* Process the weather HTML response *)
wStateMachine := 20;
ELSE
(* Error *)
sStatus := oHttp_sStatus;
diError := oHttp_diError;
wStateMachine := 999;
END_IF
END_IF
20: (* Process the weather HTML response *)
(* Get HTML stream *)
abXmlFileStream := oHttp_abContentData;
uiXmlFileStreamLen := oHttp_uiContentLength;
(* Set pointer to the start of the HTML file*)
uiXmlHandlerIndex := 0;
pabXmlHandler := ADR(abXmlFileStream[0]);
uiXmlStreamLen := uiXmlFileStreamLen;
sHTTP_Response := BUFFER_TO_STRING(pabXmlHandler,SIZEOF(abXmlFileStream),0,100);
(* Search for 'Device rebooting' string in the HTML file *)
sSearchedString := 'Device rebooting, please wait';
SearchForString;
IF xFail THEN
sStatus := 'ERROR: No Device rebooting in the stream!';
xStart:= FALSE;
diError := 16#00000001;
wStateMachine := 999;
ELSE
sStatus := 'Sucessfully executed';
diError := 0;
xStart := FALSE;
(**)
wStateMachine := 0;
iFails := 0;
END_IF
999: (* Error *)
iFails := iFails + 1;
IF iFails > iFailsMax THEN
xStart := FALSE;
END_IF
wStateMachine := 0;
ELSE
xStart := FALSE;
wStateMachine := 0;
END_CASE
Musiałem napisać w drugiej wiadomości, bo inaczej przekraczało 20 000 znaków.