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

Reading values changes them! #11

Open
Benjalien opened this issue Nov 21, 2018 · 4 comments
Open

Reading values changes them! #11

Benjalien opened this issue Nov 21, 2018 · 4 comments

Comments

@Benjalien
Copy link

Hi,
I'd like to use this nice piece of code to read the temperatures from my house and see if my setting are good (if my house is cooling down when I leave and warming up again before I come back.
I have more foreseen, but one step at a time.
Here's my issue: I did setup a script that "calls" all me devices every 15 minutes and fills a DB with the values. Every time I activate this I have about 50% of my devices loosing their config over a single day. Typically one value is missing: I have 2 open/close cycles and when I open the iOS app, I can only see 3 values instead of 4.
Did anyone experience this?
I was thinking about using only the "backup" command and then splitting the JSON inside my script, but I'm afraid I'll just invest a few hours to come to the same result :(

Hereby my script just in case someone would like to do something similar:

`#!/bin/bash

#read the devices from the DB

declare -A myDevices
deviceCount=0 # I have to keep track of it as my 2D array is simulated and Bash can't really loop them itself
declare -A myMeasures

while read device
do
devices+=("$device")
done < <(mysql -u CometBlue -pCometBluePass -D CometBlue --host localhost -BN -e "select id , '|', MAC, '|', PIN, '|', Name , '|', description from devices;")

#read the array of devices and split the lines to get the details into a bigger 2D table

for device in "${devices[@]}"
do
#echo "Device: " $device
((deviceCount++))
IFS='|' read -r -a array <<< "$device"
#trimming the whitespaces... should probably be done at "read" part rather than here :(
trimmed_ID=$(echo ${array[0]} | xargs)
myDevices[$trimmed_ID, MAC]=$(echo ${array[1]} | xargs)
myDevices[$trimmed_ID, PIN]=${array[2]}
myDevices[$trimmed_ID, Name]=${array[3]}
myDevices[$trimmed_ID, Description]=${array[4]}
done

#read the data from the CometBlues
for ((cptr=1; cptr<=$deviceCount; cptr++))
do
myMeasures[$cptr, MAC]=${myDevices[$cptr, MAC]}
echo ============================================================
echo $cptr - ${myDevices[$cptr, Description]} - ${myDevices[$cptr, MAC]}
echo ============================================================

counter=0
temperatures=""
until [ "$temperatures" ]
do
	((counter++))
	echo "Temperatures, try "$counter
	temperatures=$(cometblue device -p ${myDevices[$cptr, PIN]} ${myDevices[$cptr, MAC]} get temperatures 2>/dev/null)
	if [ $counter -ge 5 ]
		then break
	fi
	
done


#echo "temperatures " $temperatures
myMeasures[$cptr, t_current]=$(echo $temperatures | awk '{print ($3)}')
myMeasures[$cptr, t_manual_mode]=$(echo $temperatures | awk '{print ($9)}')
myMeasures[$cptr, t_target_low]=$(echo $temperatures | awk '{print ($14)}')
myMeasures[$cptr, t_target_high]=$(echo $temperatures | awk '{print ($19)}')
myMeasures[$cptr, t_offset]=$(echo $temperatures | awk '{print ($23)}')
myMeasures[$cptr, W_open_detection]=$(echo $temperatures | awk '{print ($28)}')
myMeasures[$cptr, W_open_minutes]=$(echo $temperatures | awk '{print ($32)}')


counter=0
until [ "${myMeasures[$cptr, Battery]}" ]
do
	((counter++))
	echo "Battery, try "$counter
	myMeasures[$cptr, Battery]=$(cometblue device -p ${myDevices[$cptr, PIN]} ${myDevices[$cptr, MAC]} get battery 2>/dev/null)
	if [ $counter -ge 5 ]
		then break
	fi
done
#remove the % sign
myMeasures[$cptr, Battery]=${myMeasures[$cptr, Battery]//%}



echo "Battery: "${myMeasures[$cptr, Battery]}"%"
echo "T_current: "${myMeasures[$cptr, t_current]}"°C"
echo "T_manual: "${myMeasures[$cptr, t_manual_mode]}"°C"
echo "T_target_low: "${myMeasures[$cptr, t_target_low]}"°C"
echo "T_target_high: "${myMeasures[$cptr, t_target_high]}"°C"
echo "T_offset: "${myMeasures[$cptr, t_offset]}"°C"
echo "W_open_detection: "${myMeasures[$cptr, W_open_detection]}
echo "W_open_miuntes: "${myMeasures[$cptr, W_open_minutes]}" minutes"
SQLInsert="insert into measures (device, t_current, t_manual_mode,  t_target_low, t_target_high, t_offset, W_open_detection, W_open_minutes, Battery) values ((SELECT id from devices WHERE MAC='${myMeasures[$cptr, MAC]}'), '${myMeasures[$cptr, t_current]}', '${myMeasures[$cptr, t_manual_mode]}', '${myMeasures[$cptr, t_target_low]}', '${myMeasures[$cptr, t_target_high]}', '${myMeasures[$cptr, t_offset]}', '${myMeasures[$cptr, W_open_detection]}', '${myMeasures[$cptr, W_open_minutes]}', '${myMeasures[$cptr, Battery]}');"
mysql -u CometBlue -pCometBluePass -D CometBlue --host localhost -BN -e "$SQLInsert"
if [ $? -eq 0 ];then
	echo -ne ""
else
	echo "SQL insert failed: "$SQLInsert
fi

done
`

If someone wants the SQL creation script, just ask :)

BR
Benja

@Benjalien
Copy link
Author

No idea? :)

@Benjalien
Copy link
Author

I have a good news for you: it's a firmware bug: I adapted my scripts to base them on torsten traenkner's expect scripts and I have the same bug.
So good news for you, but worst case for me: what I want to do seems impossible :(

@Hades32
Copy link

Hades32 commented Feb 23, 2020

@Benjalien what device/firmware version do you have exactly? I wanted to do just the same as you but after reading your issue I remembered that even with the official app I had the impression that I lost the config some times , but always assumed it was some connection issue...

Also, did you just try writing the whole config after reading? You probably don't change it manually often and it would be easy to detect the default config...

@Benjalien
Copy link
Author

Benjalien commented Mar 1, 2020 via email

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

2 participants