Simple java app to read sensor values from Telldus Live!

Moderator: Telldus

logge
Posts: 14
Joined: Fri Mar 17, 2023 9:45 am

Simple java app to read sensor values from Telldus Live!

Post by logge »

Hello,

As my hosting provider (godaddy) does not support OAuth and I really wanted to have some graphs showing the temperature readings on my website, I created a small java tool to read sensor values from Telldus Live!. The tool simply reads the values of the sensors you indicate, creates a small text file and then upload this file to a FTP server.

You can see the graphs for my sensors on the link below. I just received the second one so the indoor page does not have much history yet:

http://antibes.pelogeo.com

The tool can be downloaded here:
http://antibes.pelogeo.com/SensorReader.jar

Source code available here:
https://github.com/logge/SensorReader

It's very easy to use. First you have to get your api tokens from Telldus (http://api.telldus.com/keys/index)

Then, you can use the tool to get the ids of your sensors, like this:

java -jar SensorReader.java PublicKey PrivateKey PublicToken SecretToken

It's displayed as xml, but you can easily see the sensor ids in there.

Then, to start retrieving sensor values, you do this:

SensorReader.java PublicKey PrivateKey PublicToken SecretToken
FtpServer FtpUser FtpPassword ReadIntervalInMinutes sensorId1 sensorId2 ... sensorIdN

The tool will create one file for each sensor (sensorid.txt) and upload it to your ftp server. The content of the file is simply a timestamp for each reading (not taken from the sensor, but rather when the tool received the values) as well as the temperature and humidity. This file can then simply be read by something on the webserver that generates a graph. Personally I used amcharts.com. Each line in the file looks like this:

22/08/2012/12/00,30.4,69

Happy sensor reading,
//Peter
Last edited by logge on Tue Oct 02, 2012 3:25 pm, edited 2 times in total.
petzno
Posts: 116
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by petzno »

logge wrote:Hello,
Then, to start retrieving sensor values, you do this:

SensorReader.java PublicKey PrivateKey PublicToken SecretToken ReadIntervalInMinutes
FtpServer FtpUser FtpPassword sensorId1 sensorId2 ... sensorIdN
I managed to receive the sensor ID's with the first command, but how do you execute the above command from the command line? I just get the following error:
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at SensorReader.main(SensorReader.java:88)
logge
Posts: 14
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by logge »

petzno wrote:
logge wrote:Hello,
Then, to start retrieving sensor values, you do this:

SensorReader.java PublicKey PrivateKey PublicToken SecretToken ReadIntervalInMinutes
FtpServer FtpUser FtpPassword sensorId1 sensorId2 ... sensorIdN
I managed to receive the sensor ID's with the first command, but how do you execute the above command from the command line? I just get the following error:
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at SensorReader.main(SensorReader.java:88)

Sorry, a small typo in the example. The Read interval should be after the ftp password. Like this for example:

java -jar SensorReader.jar PublicKey PrivateKey PublicToken SecretToken ftphost username password 30 86413 128565

This command will read the value of two sensors every 30 minutes.
petzno
Posts: 116
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by petzno »

OK, let me try this later today.

BTW; How is your setup to do the collection of data for trending/graphing? Do you have a computer setup where you simply run this command constantly (with e.g. 30 minutes as interval setting)? If so I thought maybe using the windows scheduler without the interval setting could be a better option? Your input and experience with this is highly appreciated.

I have the possibilities to have both a windows and linux computer setup. Ideally I would like to do this from a webserver/my domain so that I don't have to have a computer running all the time.
logge
Posts: 14
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by logge »

petzno wrote:OK, let me try this later today.

BTW; How is your setup to do the collection of data for trending/graphing? Do you have a computer setup where you simply run this command constantly (with e.g. 30 minutes as interval setting)? If so I thought maybe using the windows scheduler without the interval setting could be a better option? Your input and experience with this is highly appreciated.

I have the possibilities to have both a windows and linux computer setup. Ideally I would like to do this from a webserver/my domain so that I don't have to have a computer running all the time.
For the moment I have the tool running constantly on my computer at work (which is basically on all day). It would of course be ideal to run it directly on a webserver, but my hosting provider does not support this. Using the windows scheduler would also be an option, in fact, if you download the tool again, I changed it slightly so that if you put 0 as time interval it will exit after having read the sensor data.
petzno
Posts: 116
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by petzno »

Great idea with the 0 option!

Unfortunately I have run into problems with your script when I tried it back home. I don't know if it is the latest version you uploaded or if it is the fact I changed computer, because I don't have your previous version. Here is the error I am facing, seems to be something with the ftpclient used in the script:

Code: Select all

java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
        at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
        at sun.nio.cs.StreamDecoder.read(Unknown Source)
        at sun.nio.cs.StreamDecoder.read0(Unknown Source)
        at sun.nio.cs.StreamDecoder.read(Unknown Source)
        at java.io.InputStreamReader.read(Unknown Source)
        at it.sauronsoftware.ftp4j.NVTASCIIReader.readLine(NVTASCIIReader.java:1
05)
        at it.sauronsoftware.ftp4j.FTPCommunicationChannel.read(FTPCommunication
Channel.java:142)
        at it.sauronsoftware.ftp4j.FTPCommunicationChannel.readFTPReply(FTPCommu
nicationChannel.java:187)
        at it.sauronsoftware.ftp4j.FTPClient.openPassiveDataTransferChannel(FTPC
lient.java:3614)
        at it.sauronsoftware.ftp4j.FTPClient.openDataTransferChannel(FTPClient.j
ava:3549)
        at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2677)
        at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2586)
        at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2457)
        at SensorReader.main(SensorReader.java:175)
UPDATE:
I found the solution, have a look here if somebody face the same problem:
http://stackoverflow.com/questions/1016 ... pplication

Question: Any options to set the path for the ftp server?
petzno
Posts: 116
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by petzno »

I have tried your script the last few days and I like it! However there are a few changes that could be nice to do, e.g. adding more than one sensor to the same csv file and comparing read value with previous values (based on having a problem if sensor or Tellstick is unavailable, then the reading will just show last value with a new timestamp).

Are you able to give access to the source code? If so I am more than happy to do the changes myself.
logge
Posts: 14
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by logge »

petzno wrote:I have tried your script the last few days and I like it! However there are a few changes that could be nice to do, e.g. adding more than one sensor to the same csv file and comparing read value with previous values (based on having a problem if sensor or Tellstick is unavailable, then the reading will just show last value with a new timestamp).

Are you able to give access to the source code? If so I am more than happy to do the changes myself.
Yes, I will give access to the source code, I don't have so much time to add more features myself unfortunately.
petzno
Posts: 116
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by petzno »

Perfect!
Not sure how it is most easy to do that, seems like the PM features is turned off in the forum so I am not able to send you a message.
liverpoolarn
Posts: 65
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by liverpoolarn »

When I'm running the sensor finding I get no results at all. Just an empty sensor tag.
Any ideas what might be wrong?
logge
Posts: 14
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by logge »

petzno wrote:Perfect!
Not sure how it is most easy to do that, seems like the PM features is turned off in the forum so I am not able to send you a message.
I created a public Github repository where you can get the source. Feel free to commit any improvements you do there if you want to share them.

The code is very simple, it's just one file. Then it uses one lib for the FTP part and another lib for OAuth.

https://github.com/logge/SensorReader
logge
Posts: 14
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by logge »

liverpoolarn wrote:When I'm running the sensor finding I get no results at all. Just an empty sensor tag.
Any ideas what might be wrong?
Does your temperature sensors show up in the Telldus live web interface? Could you post the xml output?
liverpoolarn
Posts: 65
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by liverpoolarn »

logge wrote:
liverpoolarn wrote:When I'm running the sensor finding I get no results at all. Just an empty sensor tag.
Any ideas what might be wrong?
Does your temperature sensors show up in the Telldus live web interface? Could you post the xml output?
When looking at live.telldus.com there is only devices, no sensors... But in the win-app they show up no problem.

Output in cmd-win is like this:

F:\Programs\Tellstick>java -jar SensorReader.jar FEHxxx ZUXyyy 952### 553###
Sensor list response: <?xml version="1.0" encoding="utf-8" ?>
<sensors />
logge
Posts: 14
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by logge »

liverpoolarn wrote:
logge wrote:
liverpoolarn wrote:When I'm running the sensor finding I get no results at all. Just an empty sensor tag.
Any ideas what might be wrong?
Does your temperature sensors show up in the Telldus live web interface? Could you post the xml output?
When looking at live.telldus.com there is only devices, no sensors... But in the win-app they show up no problem.

Output in cmd-win is like this:

F:\Programs\Tellstick>java -jar SensorReader.jar FEHxxx ZUXyyy 952### 553###
Sensor list response: <?xml version="1.0" encoding="utf-8" ?>
<sensors />
If there are no sensors in Telldus Live, then you have to direct this question to Telldus. My software can only retrieve what is listed there.
petzno
Posts: 116
Joined: Fri Mar 17, 2023 9:45 am

Re: Simple java app to read sensor values from Telldus Live!

Post by petzno »

logge wrote:
petzno wrote:Perfect!
I created a public Github repository where you can get the source. Feel free to commit any improvements you do there if you want to share them.

The code is very simple, it's just one file. Then it uses one lib for the FTP part and another lib for OAuth.

https://github.com/logge/SensorReader
Same like you the hardest thing is to find time for such things. But I will let you know if I do any changes :D
Post Reply