Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VClient does not return error in $? #116

Open
MrFly72 opened this issue Nov 8, 2022 · 1 comment
Open

VClient does not return error in $? #116

MrFly72 opened this issue Nov 8, 2022 · 1 comment

Comments

@MrFly72
Copy link

MrFly72 commented Nov 8, 2022

Currently it seems, that if an error appears on a query, the vclient will still return a $? = 0.
In my eyes it should not zero the lasterror and should deliver an error value.
In my case:

INSERT=$(/usr/bin/vclient -c getFlammeStatus,getBrennerStatus,getLeistungIst,getUmschaltventil,getTempA,getTempAged,getTempAtp,getTempWWist,getTempWWsoll,getTempKist,getTempKsoll,getTempVListM1,getTempVLsollM1,getNeigungM1,getNiveauM1,getTempAbgas,getBrennerStarts,getBrennerStunden1,getPumpeStatusIntern,getPumpeDrehzahlIntern,getTempRL17A,getVolStrom -t /home/pi/sql6.tmpl)

Does just deliver empty values on queries it does not work on, as this error appears from time to time:

SRV ERR: >FRAMER: Error 0x15 != 0x06 (P300_INIT_OK)
Error in send, terminating
Error executing getFlammeStatus
SRV ERR: >FRAMER: Error 0x15 != 0x06 (P300_INIT_OK)
Error in send, terminating
Error executing getBrennerStatus

I would like to redo the query, if an error appears.
the code for this looks like this (and does not work as vclient does not return an error value):

INSERT=$(/usr/bin/vclient -c getFlammeStatus,getBrennerStatus,getLeistungIst,getUmschaltventil,getTempA,getTempAged,getTempAtp,getTempWWist,getTempWWsoll,getTempKist,getTempKsoll,getTempVListM1,getTempVLsollM1,getNeigungM1,getNiveauM1,getTempAbgas,getBrennerStarts,getBrennerStunden1,getPumpeStatusIntern,getPumpeDrehzahlIntern,getTempRL17A,getVolStrom -t /home/pi/sql6.tmpl)
if [ $? -ne 0 ]
then
	date >>/home/pi/sqlgetdata.log
	echo "Error : $INSERT"
	INSERT=$(/usr/bin/vclient -c getFlammeStatus,getBrennerStatus,getLeistungIst,getUmschaltventil,getTempA,getTempAged,getTempAtp,getTempWWist,getTempWWsoll,getTempKist,getTempKsoll,getTempVListM1,getTempVLsollM1,getNeigungM1,getNiveauM1,getTempAbgas,getBrennerStarts,getBrennerStunden1,getPumpeStatusIntern,getPumpeDrehzahlIntern,getTempRL17A,getVolStrom -t /home/pi/sql6.tmpl)
	echo "Repeat: $INSERT"
fi
sqlite3 /home/pi/viessmann.sqlite3 "$INSERT"
@MrFly72
Copy link
Author

MrFly72 commented Nov 14, 2022

As vclient does not return an error I worked on an interim. The first part (the catch function) I found on the internet, it splits the output into error and stdout stream.
This makes it possible to check the stderr for a problem in the query.
If that happens I rerun the query, which normally does yield to getting all values.
But anyhow, vclient should in my eyes set the exitcode.

#!/bin/bash
: catch STDOUT STDERR cmd args..
catch()
{
eval "$({
__2="$(
  { __1="$("${@:3}")"; } 2>&1;
  ret=$?;
  printf '%q=%q\n' "$1" "$__1" >&2;
  exit $ret
  )";
ret="$?";
printf '%s=%q\n' "$2" "$__2" >&2;
printf '( exit %q )' "$ret" >&2;
} 2>&1 )";
}

#INSERT=$(/usr/bin/vclient -c getFlammeStatus,getBrennerStatus,getLeistungIst,getUmschaltventil,getTempA,getTempAged,getTempAtp,getTempWWist,getTempWWsoll,getTempKist,getTempKsoll,getTempVListM1,getTempVLsollM1,getNeigungM1,getNiveauM1,getTempAbgas,getBrennerStarts,getBrennerStunden1,getPumpeStatusIntern,getPumpeDrehzahlIntern,getTempRL17A,getVolStrom -t /home/pi/sql6.tmpl)
catch INSERT stderr /usr/bin/vclient -c getFlammeStatus,getBrennerStatus,getLeistungIst,getUmschaltventil,getTempA,getTempAged,getTempAtp,getTempWWist,getTempWWsoll,getTempKist,getTempKsoll,getTempVListM1,getTempVLsollM1,getNeigungM1,getNiveauM1,getTempAbgas,getBrennerStarts,getBrennerStunden1,getPumpeStatusIntern,getPumpeDrehzahlIntern,getTempRL17A,getVolStrom -t /home/pi/sql6.tmpl
if [[ "$stderr" == *"SRV ERR"* ]]; then
        echo "Error : $INSERT"
        catch INSERT stderr /usr/bin/vclient -c getFlammeStatus,getBrennerStatus,getLeistungIst,getUmschaltventil,getTempA,getTempAged,getTempAtp,getTempWWist,getTempWWsoll,getTempKist,getTempKsoll,getTempVListM1,getTempVLsollM1,getNeigungM1,getNiveauM1,getTempAbgas,getBrennerStarts,getBrennerStunden1,getPumpeStatusIntern,getPumpeDrehzahlIntern,getTempRL17A,getVolStrom -t /home/pi/sql6.tmpl
        echo "Repeat: $INSERT"
fi
sqlite3 /home/pi/viessmann.sqlite3 "$INSERT"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant