NUT Mini BATTERY SERVICE

All kinds of 'OS' scripts

Moderator: leecollings

Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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!
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post by Artursd »

Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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"
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post by Artursd »

Thanks for any help.
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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 - оба на месте, скрипт их не находит
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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! ;)
The most dangerous phrase in any language is:
"We always done this way"
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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
The most dangerous phrase in any language is:
"We always done this way"
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post by Artursd »

А как сделать проверку батареи? Может тот скрипт можно переделать? А за ссылку спасибо !!!
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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&param=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}"
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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"
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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

}
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post by Artursd »

if [[ $USEBEACONSERVICE == "1" ]]; then
svcBeacon "start"
fi
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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!
Artursd
Posts: 86
Joined: Sunday 16 December 2018 17:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post by Artursd »

https://yadi.sk/i/3kGa8TRCqZAXqg

Где ошибка ???
Olivrius
Posts: 4
Joined: Thursday 12 July 2018 10:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NUT Mini BATTERY SERVICE

Post 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)


++
Raspberry Pi 3 - RFlink - Ardunio - NUT - IR com - Xiaomi
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: NUT Mini BATTERY SERVICE

Post by emme »

3 months is what NusSpace declare for NUT Mini
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests