Tired of telldusd and SK losing connection?

Andra typer av bidrag | Other contributions
Post Reply
akeson
1 star
1 star
Posts: 11
Joined: Tue 04 Sep 2012, 19:32

Tired of telldusd and SK losing connection?

Post by akeson » Fri 28 Dec 2012, 11:22

Hi,

Got tired of the bug the makes SK lose connection with telldusd (at least on Linux) and wrote a hack to work around the problem.
The hack is a bash script that I add to crontab to make it run at a set interval.
The script is in no way pretty and might not work for you, but it works just fine for me.
What it does is to invoke tdtool --list and extract the sensor values from there, and then save the values into one file for each sensor for easy adding into SK.

It is expected that you have some (limited) knowledge in cron and bash to make this work for you.
Remember to make the script executable...

Code: Select all

#!/bin/bash

# Define path to save files. Do not add trailing slash.
CONF_PATH="/var/www/default/telldus"

# Define sensors, one array id per sensor
# Example:
# CONF_PROTOCOL[1]=protocol_name
# CONF_MODEL[1]=model_name
# CONF_ID[1]=id_number

CONF_PROTOCOL[1]=mandolyn
CONF_MODEL[1]=temperaturehumidity
CONF_ID[1]=11

CONF_PROTOCOL[2]=mandolyn
CONF_MODEL[2]=temperaturehumidity
CONF_ID[2]=12

CONF_PROTOCOL[3]=mandolyn
CONF_MODEL[3]=temperaturehumidity
CONF_ID[3]=51

# Run 'tdtool --list' and save into array
values=($(tdtool --list))

# Loop through array
while :
do
	# If array index is empty, break loop
	if [ -z ${values[i]} ]; then
		break
	fi

	# Loop through defined sensors to find matches
	for (( j = 0 ; j <= ${#CONF_PROTOCOL[@]} ; j++ ))
	do
		# Found match? All three identifiers must match.
		if [ "${values[i]}" == "${CONF_PROTOCOL[j]}" -a "${values[i+1]}" == "${CONF_MODEL[j]}" -a "${values[i+2]}" == "${CONF_ID[j]}" ]
		then
			# For debugging, uncomment to print match
			# echo ID:${values[i+2]}, TEMP:${values[i+3]}, HUM:${values[i+4]}, TIME:${values[i+5]} ${values[i+6]}

			# Save matched values in variables for easier reading
			save_id=${values[i+2]}
			save_temp=$(tr -d "°" <<< ${values[i+3]}) # Strip degree char
			save_hum=$(tr -d "%" <<< ${values[i+4]}) # Strip percent char
			save_time="${values[i+5]} ${values[i+6]}"
			# Write values into file
			echo "$save_temp;$save_hum;$save_time" > $CONF_PATH/$save_id
		fi
	done

	# Increment counter
	i=$((i+1));

done
//Akeson

edit: fixed wrong variable in a for-loop

akeson
1 star
1 star
Posts: 11
Joined: Tue 04 Sep 2012, 19:32

Re: Tired of telldusd and SK losing connection?

Post by akeson » Sat 29 Dec 2012, 14:03

New version that handles sensors with only temperature too, in addition to temperature + humidity.

Code: Select all

#!/bin/bash

# Define path to save files. Do not add trailing slash.
CONF_PATH="/var/www/default/telldus"

# Define sensors, one array id per sensor
# Example:
# CONF_PROTOCOL[1]=protocol_name
# CONF_MODEL[1]=model_name
# CONF_ID[1]=id_number

CONF_PROTOCOL[1]=mandolyn
CONF_MODEL[1]=temperaturehumidity
CONF_ID[1]=11

CONF_PROTOCOL[2]=fineoffset
CONF_MODEL[2]=temperature
CONF_ID[2]=77

# Run 'tdtool --list' and save into array
values=($(tdtool --list))

# Loop through array
while  [ ${values[i]} ]
do

	# Loop through defined sensors to find matches
	for (( j = 0 ; j <= ${#CONF_PROTOCOL[@]} ; j++ ))
	do
		# Found match? All three identifiers must match.
		if [ "${values[i]}" == "${CONF_PROTOCOL[j]}" -a "${values[i+1]}" == "${CONF_MODEL[j]}" -a "${values[i+2]}" == "${CONF_ID[j]}" ]
		then
			# For debugging, uncomment to print match
			# echo ID:${values[i+2]}, TEMP:${values[i+3]}, HUM:${values[i+4]}, TIME:${values[i+5]} ${values[i+6]}

			# Save matched values in variables for easier reading
			save_id=${values[i+2]}
			save_temp=$(tr -d "°" <<< ${values[i+3]}) # Strip degree char
			if [ ${CONF_MODEL[j]} == "temperaturehumidity" ]
			then
				save_hum=$(tr -d "%" <<< ${values[i+4]}) # Strip percent char
				save_time="${values[i+5]} ${values[i+6]}"
				save_data="$save_temp;$save_hum;$save_time"
			fi
			if [ ${CONF_MODEL[j]} == "temperature" ]
			then
				save_time="${values[i+4]} ${values[i+5]}"
                                save_data="$save_temp;$save_time"
			fi

			# Write values into file
			echo $save_data > $CONF_PATH/$save_id
		fi
	done

	# Increment counter
	i=$((i+1));

done
edit 2013-01-02: Moved loop condition into while statement
Last edited by akeson on Wed 02 Jan 2013, 11:09, edited 2 times in total.

Martin
Administrator
Administrator
Posts: 2655
Joined: Tue 09 Nov 2010, 20:25

Re: Tired of telldusd and SK losing connection?

Post by Martin » Sat 29 Dec 2012, 21:14

@Akeson: If you haven't done so already, please notify Telldus that you are experiencing the same behavior in Linux that Windows users does in Windows. Maybe Telldus can provide the same fix for Linux as for Windows.
Martin | Switch King

akeson
1 star
1 star
Posts: 11
Joined: Tue 04 Sep 2012, 19:32

Re: Tired of telldusd and SK losing connection?

Post by akeson » Wed 02 Jan 2013, 10:44

I have, but they didn't expect the root cause to be the same since the architecture differs a lot.
They are however re-writing alot of the code for Linux.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests