Page 2 of 6
Re: NUT Mini BATTERY SERVICE
Posted: Sunday 16 December 2018 17:54
by Artursd
Hello everyone, I need help, I installed this script myself, it gives an error at startup.
root@raspberrypi:/home/pi/scripts# ./nut_test.sh
- - - - - - - - - - - - - - -
parse error: Invalid numeric literal at line 1, column 60
Analyzing NUT: Nut_Egita Domoticz State:
XX NUT not found in BLE Scan!
- - - - - - - - - - - - - - -
parse error: Invalid numeric literal at line 1, column 60
Analyzing NUT: Nut_Arturs Domoticz State:
XX NUT not found in BLE Scan!
Re: NUT Mini BATTERY SERVICE
Posted: Sunday 16 December 2018 17:55
by Artursd
root@raspberrypi:/home/pi/scripts# hciconfig
hci1: Type: BR/EDR Bus: USB
BD Address: 00:15:83:F2:26:66 ACL MTU: 310:10 SCO MTU: 64:8
UP RUNNING
RX bytes:9808985 acl:0 sco:0 events:232671 errors:0
TX bytes:19397 acl:0 sco:0 commands:997 errors:0
hci0: Type: BR/EDR Bus: UART
BD Address: B8:27:EB:7C:EC:0A ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:17615918 acl:75 sco:0 events:405712 errors:0
TX bytes:20594 acl:67 sco:0 commands:969 errors:0
Re: NUT Mini BATTERY SERVICE
Posted: Sunday 16 December 2018 17:59
by Artursd
Re: NUT Mini BATTERY SERVICE
Posted: Sunday 16 December 2018 18:00
by Artursd
NUTBATT=(
"ed:c5:51:27:23:96" "NUT_Egita_Batery" "162" "Nut_Egita"
"78:bd:bc:da:50:77" "NUT_Arturs_Batery2" "161" "Nut_Arturs"
Re: NUT Mini BATTERY SERVICE
Posted: Sunday 16 December 2018 18:02
by Artursd
Thanks for any help.
Re: NUT Mini BATTERY SERVICE
Posted: Sunday 16 December 2018 19:23
by Artursd
root@raspberrypi:/home/pi/scripts# ./nut_test.sh
- - - - - - - - - - - - - - -
Analyzing NUT: Nut_Egita Domoticz State: On
XX NUT not found in BLE Scan!
Updating Variable HOME => AWAY
- - - - - - - - - - - - - - -
Analyzing NUT: Nut_Arturs Domoticz State: On
XX NUT not found in BLE Scan!
Updating Variable HOME => AWAY
Вот что получилось. NUT - оба на месте, скрипт их не находит
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 8:41
by emme
Ciao,
if you cut/paste the script from a window PC to a ssh session it could be it pasted some wired chars...
could you please paste the entire script?
thanks
ciao
M
P.S.
please evaluate to move to the nodeRed flow for BLE scan which is much more reliable!

Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 17:34
by Artursd
P.S.
please evaluate to move to the nodeRed flow for BLE scan which is much more reliable!
Hey. Or maybe there are ready solutions from nodeRed
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 18:15
by emme
I made a flow for it but the inconvenience is that I no longer check the battery
https://flows.nodered.org/flow/7343f804 ... 221e9ed3b9
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 18:42
by Artursd
А как сделать проверку батареи? Может тот скрипт можно переделать? А за ссылку спасибо !!!
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 18:57
by Artursd
default BLE interface (hci0) should NOT be used in any other scripts or ssh/terminal usage, it became unstable and unusable until next reboot
root@raspberrypi:/home/pi/scripts# hciconfig
hci1: Type: BR/EDR Bus: USB
BD Address: 00:15:83:F2:26:66 ACL MTU: 310:10 SCO MTU: 64:8
UP RUNNING
RX bytes:9808985 acl:0 sco:0 events:232671 errors:0
TX bytes:19397 acl:0 sco:0 commands:997 errors:0
hci0: Type: BR/EDR Bus: UART
BD Address: B8:27:EB:7C:EC:0A ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:17615918 acl:75 sco:0 events:405712 errors:0
TX bytes:20594 acl:67 sco:0 commands:969 errors:0
я так понимаю мне нужно HCI1
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 21:39
by Artursd
#!/bin/bash
# SETTING UP PARAMETERS
## DOMOTICZ SETUP (no authentication required, ensure that you have IP in whitelist)
#DOMOIP="127.0.0.1"
DOMOIP="192.168.1.128"
DOMOPORT="8080"
DAWVAR="/json.htm?type=command¶m=updateuservariable&vname=VARIABLENAME&vtype=2&vvalue=VARIABLEVALUE"
DARDEV="/json.htm?type=devices&rid=DEVICEIDX"
DCHECKSTS="1"
#Check status of switches before continuing
#Set to 0 to force all configured NUT
BATTUUID="0x2a19"
BATTAWAYMSG="UNAVAILABLE"
# Creating Main array (MAC Address UPPERCASE - Variable Name - Switch Name - NUT Device (variable) Name )
NUTBATT=(
"ed:c5:51:27:23:96" "NUT_Egita_Batery" "162" "Nut_Egita"
"78:bd:bc:da:50:77" "NUT_Arturs_Batery" "161" "Nut_Arturs"
)
# Other Parameters
USEBEACONSERVICE="0"
#Set to 0 if you do not have a beaconing serive deamon running
BEACONSERVICENAME="ble.service"
HCIINTERFACE="hci1"
BLEDISCOVERY=5 #Timeout for BLE Discovery
BLEDISCFILE="/home/pi/ScanResult.txt"
function domoWriteVar () {
URLREQ="http://"$DOMOIP":"$DOMOPORT$DAWVAR
# URLREQ="${URLREQ/VARIABLENAME/${NUTBATT[arrNut+1]}}"
URLREQ="${URLREQ/VARIABLENAME/$2}"
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 21:40
by Artursd
URLREQ="${URLREQ/VARIABLEVALUE/$1}"
dzAPIWriteVar=$(curl -s "$URLREQ" )
}
function domoGetStatus {
URLREQ="http://"$DOMOIP":"$DOMOPORT$DARDEV
#echo $URLREQ
dzAPIStatus="${URLREQ/DEVICEIDX/${NUTBATT[arrNut+2]}}"
# Getting switch status prom Domoticz
dzDevRAW=$(curl -s "$dzAPIStatus")
dzDevJSON=$(echo ${dzDevRAW} | jq .result[0].Data)
dzDevSTATUS=$(echo $dzDevJSON | sed "s/\"//g")
}
function svcBeacon() {
if [[ $1 == "stop" ]]; then
echo "Stopping Beaconing Service"
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 21:41
by Artursd
if [[ $1 == "start" ]]; then
echo "Starting Beaconing Service"
sudo systemctl start ${BEACONSERVICENAME}
fi
}
function restartHCI () {
sudo hciconfig ${HCIINTERFACE} down
sleep 1
sudo hciconfig ${HCIINTERFACE} up
}
function getBLEBat (){
restartHCI
HANDLE=$(sudo hcitool lecc --random ${NUTBATT[arrNut]} | awk '{print $3}')
sleep 1
sudo hcitool ledc $HANDLE
BATHEX=$(sudo gatttool -t random --char-read --uuid $BATTUUID -b ${NUTBATT[arrNut]} | awk '{print $4}')
BATDEC=$((0x$BATHEX))
# if [ "$BATDEC" == "0" ]; then
# BATDEC=$BATTAWAYMSG
# fi
echo "Risultato finale: HEX :"$BATHEX" DEC: "$BATDEC
if [ "$BATDEC" -ne "0" ]; then
domoWriteVar $BATDEC ${NUTBATT[arrNut+1]}
fi
}
function discBLE (){
restartHCI
timeout -s SIGINT ${BLEDISCOVERY}s hcitool -i $HCIINTERFACE lescan > $BLEDISCFILE
restartHCI
}
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 21:42
by Artursd
function nutLookup (){
if [ -s $BLEDISCFILE ]; then
if grep -q "${NUTBATT[arrNut]}" ${BLEDISCFILE}; then
printf "== NUT found in BLE Scan!\n"
if [[ $dzDevSTATUS == "Off" ]]; then
printf "Updating Variable AWAY => HOME\n"
domoWriteVar "HOME" ${NUTBATT[arrNut+3]}
getBLEBat
fi
else
printf "XX NUT not found in BLE Scan!\n"
if [[ $dzDevSTATUS == "On" ]]; then
printf "Updating Variable HOME => AWAY\n"
domoWriteVar "AWAY" ${NUTBATT[arrNut+3]}
fi
fi
fi
}
# BEGINNING MAIN SCRIPT
discBLE
if [[ $USEBEACONSERVICE == "1" ]]; then
svcBeacon "stop"
fi
printf "\n- - - - - - - - - - - - - - -\n"
for arrNut in $(seq 0 4 $((${#NUTBATT[@]} - 1))); do
if [[ $DCHECKSTS == "1" ]]; then
domoGetStatus
echo "Analyzing NUT: "${NUTBATT[arrNut+3]}" Domoticz State: "$dzDevSTATUS
else
dzDevSTATUS="On"
fi
nutLookup
printf "\n- - - - - - - - - - - - - - -\n"
done
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 21:43
by Artursd
if [[ $USEBEACONSERVICE == "1" ]]; then
svcBeacon "start"
fi
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 21:43
by Artursd
root@raspberrypi:/home/pi/scripts# ./nut_test.sh
- - - - - - - - - - - - - - -
Analyzing NUT: Nut_Egita Domoticz State: Off
XX NUT not found in BLE Scan!
- - - - - - - - - - - - - - -
Analyzing NUT: Nut_Arturs Domoticz State: Off
XX NUT not found in BLE Scan!
Re: NUT Mini BATTERY SERVICE
Posted: Monday 17 December 2018 21:45
by Artursd
Re: NUT Mini BATTERY SERVICE
Posted: Tuesday 18 December 2018 17:02
by Olivrius
Just 1 information for the Mini Nut lifetime battery :
I use NUT for presence sensor with domotique and the battery have a lifetime approximaly 3 month. It's not very long.
Is it the same for you ?
I have adapted a CR22 battery instead of the original, it's work very well and you have now very long time autonomy.( 1 year with a daily use)
So, the original box can be adapted with schotch (for the moment, i have do this and i'll p'repare a 3D files to print for replace the original box)
++
Re: NUT Mini BATTERY SERVICE
Posted: Thursday 20 December 2018 16:30
by emme
3 months is what NusSpace declare for NUT Mini