TellStick Net API

Moderator: Telldus

Post Reply
RajenK
Posts: 1
Joined: Fri Mar 17, 2023 9:45 am

TellStick Net API

Post by RajenK »

Hi,

Is there any way to address TellStick Net without the cloud service? I would really like the TellStick Net as it does not rely on a computer, but I'd like to develop my own software to manage it and not rely on Telldus Live! for this. Is it at all possible?

Thanks!
joemensor
Posts: 11
Joined: Fri Mar 17, 2023 9:45 am

Re: TellStick Net API

Post by joemensor »

I think we are all still waiting, just bought a Tellstick Net but was a bit disappointed when I found that I also needed a Tellstick Duo for 'full functionality'.

I really really need the ability to receive signals from Nexa switches...is there any timescales whatsoever for this? As I feel I'm going to have to look elsewhere for this functionality at the moment.
jkp
Posts: 42
Joined: Fri Mar 17, 2023 9:45 am

Re: TellStick Net API

Post by jkp »

Well, there is a firmware version with local access published as source code for the Net, but apparently it isn't considered as mature/stable as the normal firmware. I haven't tried this, don't even have a Net device - one of the main reasons for me in choosing the Duo instead was that the Net was reported to not be usable locally.

Info on the firmware: http://developer.telldus.se/blog/2012/0 ... n-firmware
thohell
Posts: 2
Joined: Fri Mar 17, 2023 9:45 am

Re: TellStick Net API

Post by thohell »

I received my TellStick earlier today and I must say it looks very easy to build and use a local server without even modifying the firmware.

Following these simple steps to use a local server it's really a no-brainer to build a server that can either proxy to the live server or completely take over using the original firmware.

This has already been documented but I will repeat for clarity:

You need to have a local dns server. You need to have a webserver somewhere.

First, you need to create two A records in your DNS server. I assume you know how to do this.
Create one dns A record for api.telldus.com that points to a webserver under your control (local or remote makes no difference).
Create one dns A record for local.telldus.com that points to the computer you want the Tellstick Net to use as a server.

Second, you need to create a file at http://api.telldus.com/server/assign with the text content "11:local.telldus.comiAFCAs". I assume you know how to do this.

Third, you need to start some kind of server that the Tellstick Net can connect to. As a very simple proof of concept I am using the vb.net code below.

The POC server is practically useless but it will register with the unit, it will keep the connection up (ping/pong) and it will print anything the unit receives from transmitters.

Have fun and good luck!

-----8<-----
Module Module1
Sub Main()
Dim s As New TellstickNetProxyServer.Server
End Sub
End Module
----->8-----

-----8<-----
Imports System.Text
Imports System.Net.Sockets
Imports System.Threading
Imports System.Net

Namespace TellstickNetProxyServer
Class Server
Private tcpListener As TcpListener
Private listenThread As Thread

Public Sub New()
Me.tcpListener = New TcpListener(IPAddress.Any, 45002)
Me.listenThread = New Thread(New ThreadStart(AddressOf ListenForClients))
Me.listenThread.Start()
End Sub


Private Sub ListenForClients()
Me.tcpListener.Start()

While True
Dim client As TcpClient = Me.tcpListener.AcceptTcpClient()

Dim clientThread As New Thread(New ParameterizedThreadStart(AddressOf HandleClientComm))
clientThread.Start(client)
End While
End Sub

Private Sub HandleClientComm(client As TcpClient)
Dim tcpClient As TcpClient = client
Dim clientStream As NetworkStream = tcpClient.GetStream()

Dim message As Byte() = New Byte(4095) {} ' 4k buffer should be more than enough
Dim bytesRead As Integer

While True
bytesRead = 0

Try
bytesRead = clientStream.Read(message, 0, 4096)
Catch
Exit Try
End Try

If bytesRead = 0 Then
Exit While
End If

Dim encoder As New ASCIIEncoding()
Dim s As String = encoder.GetString(message, 0, bytesRead)

ParseString(s, clientStream)

End While

tcpClient.Close()
End Sub

Private Sub ParseString(s As String, t As NetworkStream)
Static l As String

Dim a() As String = s.Split(":")

Dim m As String
Dim encoder As New ASCIIEncoding()

Select Case a(2)

Case "4"
Console.WriteLine("Ping/pong")
m = "28:4df8af148e8cc310c85929fffaf4d3617c8492236:4:pong"
t.Write(encoder.GetBytes(m), 0, encoder.GetByteCount(m))


Case ("8")
Console.WriteLine("Register")
m = "A=28::A:"
t.Write(encoder.GetBytes(m), 0, encoder.GetByteCount(m))


Case "7"
If l <> s Then
Console.WriteLine("RF-Signal: " & s)
l = s
End If


Case Else
Console.WriteLine("Unknown message: " & s)

End Select


End Sub
End Class
End Namespace
----->8-----
Last edited by thohell on Mon Feb 04, 2013 9:42 pm, edited 1 time in total.
joemensor
Posts: 11
Joined: Fri Mar 17, 2023 9:45 am

Re: TellStick Net API

Post by joemensor »

This is awesome.

Will let you know how I get on.
thohell
Posts: 2
Joined: Fri Mar 17, 2023 9:45 am

Re: TellStick Net API

Post by thohell »

Here is a simple class I use to snoop the protocol while still being able to use Tellstick Live.

It's missing pretty much everything from common sense trough good design to errorhandling but it's only meant to do one thing; snoop the protocol. Hope this helps you on your way! :)

---8<---
Imports System.Text
Imports System.Net.Sockets
Imports System.Threading
Imports System.Net

Namespace TellstickMonoProxyServer
Class Server

' /server/access (file content) CNAME IP
' ----------------------------- -------------------------- ---------------
' 11:alice.telldus.comiAFCAs alice.machine.telldus.com 46.21.105.101
' 11:tanja.telldus.comiAFCAs tanja.machine.telldus.com 46.21.105.7
' 11:julia.telldus.comiAFCAs julia.machine.telldus.com 62.20.121.252
' 11:wilma.telldus.comiAFCAs wilma.machine.telldus.com 79.99.6.173
' 11:zaida.telldus.comiAFCA zaida.machine.telldus.com 46.21.105.98

Private m_LiveServerList() As String = {"alice.telldus.com", "tanja.telldus.com", "julia.telldus.com", "wilma.telldus.com", "zaida.telldus.com"}
Private m_LiveServerPort As Long = 45002
Private m_LiveServerTcpClient As TcpClient = New TcpClient
Private m_LiveServerStream As NetworkStream
Private m_LiveServerConnected As Boolean = False


' Tellstick Net server
Private m_TellstickServerPort As Long = 45002
Private m_TellstickConnected As Boolean = False
Private m_TellstickServerListener As TcpListener = New TcpListener(IPAddress.Any, m_TellstickServerPort)
Private m_TellstickServerStream As NetworkStream
Private m_TellstickServerRegisterReceived As String = vbNullString

' ***************************************************************************************************************
'
' ***************************************************************************************************************
Public Sub New()
m_TellstickServerListener.Start() ' Start local server

Do
' Get client connection
log("[INFO] Listening for Tellstick clients on port " & m_TellstickServerPort)
Dim _tcpClient As TcpClient = m_TellstickServerListener.AcceptTcpClient()

Dim _t = New Thread(New ParameterizedThreadStart(AddressOf _serverThread))
_t.Start(_tcpClient)

' Do nothing while client is connected
While _t.IsAlive
Thread.Sleep(100)
End While
Loop

End Sub

' ***************************************************************************************************************
' Serverthread
' ***************************************************************************************************************
Private Sub _serverThread(_tcpClient As TcpClient)
Dim RemoteIpEndpoint As IPEndPoint = _tcpClient.Client.RemoteEndPoint
Dim ClientIP As String = RemoteIpEndpoint.Address.ToString
Dim ClientPort As String = RemoteIpEndpoint.Port
Dim encoder As New ASCIIEncoding()

log("[SERVER] Client connected! IP:" & ClientIP & " Port:" & ClientPort)

log("[INFO] Client connected!")

m_TellstickConnected = True
m_TellstickServerStream = _tcpClient.GetStream()

Dim m As Byte() = New Byte(4095) {} ' 4k buffer should be more than enough
Dim b As Integer = 0

m_TellstickServerStream.ReadTimeout = 130 * 1000 ' Ping every 120 seconds


While _tcpClient.Connected
b = 0

Try
b = m_TellstickServerStream.Read(m, 0, 4096)
Catch
log("[INFO] No data or ping from Tellstick Net in 130 seconds. Disconnecting!")
Exit While
End Try

If Not b = 0 Then

Dim s As String = encoder.GetString(m, 0, b)

Select Case s.Split(":")(2)
Case ("8")
log("[STICK -> SERVER] Register? - " & s)
log("[SERVER -> STICK] Ok! - A=28::A:")
m_TellstickServerStream.Write(encoder.GetBytes("A=28::A:"), 0, encoder.GetByteCount("A=28::A:"))

' We have a valid string to register with. Let's connect to Telldus Live!
m_TellstickServerRegisterReceived = s
ConnectToLiveServer()


Case "4"
log("[STICK -> SERVER] Ping! - " & s)
log("[SERVER -> STICK] Pong! - 28:4df8af148e8cc310c85929fffaf4d3617c8492236:4:pong")
m_TellstickServerStream.Write(encoder.GetBytes("28:4df8af148e8cc310c85929fffaf4d3617c8492236:4:pong"), 0, encoder.GetByteCount("28:4df8af148e8cc310c85929fffaf4d3617c8492236:4:pong"))

' Proxy this
log("[SERVER -> LIVE] Ping! - " & s)
m_LiveServerStream.Write(m, 0, b)

Case "7"
log("[STICK -> LIVE] RF signal - " & s)

' Proxy this
m_LiveServerStream.Write(m, 0, b)

Case "3"
log("[STICK -> LIVE] ACK! - " & s)

' Proxy this
m_LiveServerStream.Write(m, 0, b)

Case Else
log("[STICK -> LIVE] UNKNOWN! - " & s)

' Proxy this
m_LiveServerStream.Write(m, 0, b)

End Select
End If

End While

log("[INFO] Client disconnected!")
m_TellstickConnected = False
m_TellstickServerStream = Nothing
m_TellstickServerRegisterReceived = vbNullString
_tcpClient.Close()
End Sub

' ***************************************************************************************************************
' Connect to live server
' ***************************************************************************************************************
Private Sub ConnectToLiveServer()
log("[SERVER] Connecting to live server.")

For Each servername In m_LiveServerList
log("[SERVER] Trying trying server: " & servername)

Try
m_LiveServerTcpClient.Connect(servername, m_LiveServerPort)
Catch
log("[SERVER] No luck...")
End Try
If m_LiveServerTcpClient.Connected = True Then
log("[SERVER] Connected!")
Exit For
End If

Next

If m_LiveServerTcpClient.Connected = True Then
Dim _t = New Thread(New ParameterizedThreadStart(AddressOf _proxyThread))
_t.Start(m_LiveServerTcpClient)
End If

End Sub


' ***************************************************************************************************************
' Proxythread
' ***************************************************************************************************************
Private Sub _proxyThread(_tcpClient As TcpClient)
Dim RemoteIpEndpoint As IPEndPoint = _tcpClient.Client.RemoteEndPoint
Dim ClientIP As String = RemoteIpEndpoint.Address.ToString
Dim ClientPort As String = RemoteIpEndpoint.Port
Dim encoder As New ASCIIEncoding()

log("[SERVER] Connected to Live server! IP:" & ClientIP & " Port:" & ClientPort)

m_LiveServerConnected = True
m_LiveServerStream = _tcpClient.GetStream()

Dim m As Byte() = New Byte(4095) {} ' 4k buffer should be more than enough
Dim b As Integer = 0

'm_LiveServerStream.ReadTimeout = 130 * 1000 ' Ping every 120 seconds

' Send register packet.
log("[SERVER -> LIVE] Register? - " & m_TellstickServerRegisterReceived)
m_LiveServerStream.Write(encoder.GetBytes(m_TellstickServerRegisterReceived), 0, encoder.GetByteCount(m_TellstickServerRegisterReceived))

While _tcpClient.Connected
b = 0

Try
b = m_LiveServerStream.Read(m, 0, 4096)
Catch
log("[INFO] No data or ping from Live server in 130 seconds. Disconnecting!")
Exit While
End Try

If Not b = 0 Then
Dim s As String = Encoder.GetString(m, 0, b)

Select Case s.Split(":")(2)
Case ("8")
log("[LIVE -> SERVER ] OK! - " & s)

Case "4"
log("[LIVE -> STICK] Command - " & s)

' Proxy this
m_TellstickServerStream.Write(m, 0, b)

Case Else
log("[LIVE -> STICK] UNKNOWN! - " & s)

' Proxy this
m_TellstickServerStream.Write(m, 0, b)

End Select
End If

End While

log("[INFO] Live server disconnected!")
m_LiveServerConnected = False
m_LiveServerStream = Nothing
_tcpClient.Close()
End Sub


' ***************************************************************************************************************
' Logger
' ***************************************************************************************************************
Private Sub log(s As String)
Console.WriteLine("{0:T} " & s, Now)

End Sub

End Class
End Namespace

--->8---
Ankan
Posts: 44
Joined: Fri Mar 17, 2023 9:45 am

Re: TellStick Net API

Post by Ankan »

joemensor & RajenK: How is it going?

I was also thinking of setting up a local server to get all those benefits as Live gives you, but offline with total control.

I will try that vb.net class. But if someone already have added features and codefixes to it I would be glad if that someone would like to share it.
simonbove
Posts: 109
Joined: Fri Mar 17, 2023 9:45 am

Re: TellStick Net API

Post by simonbove »

Anything new about installing a private live server?
NeedAnswersB4Buying
Posts: 3
Joined: Fri Mar 17, 2023 9:45 am

Re: TellStick Net API

Post by NeedAnswersB4Buying »

I think it is total bullshit that this issue of making the Tellstick Net controllable from inside the local network has still not been addressed properly by the developers. I'm waiting for a proper python lib for this purpose and searching for other products while they sit on their thumbs.
GokMasE
Posts: 10
Joined: Fri Mar 17, 2023 9:45 am
Contact:

Re: TellStick Net API

Post by GokMasE »

While I really love my Tellstick Net already as it stands, I am sorry to have to agree with you here - too much time has passed without any progress on this matter. Local access is a feature that is requested and longed for by quite a few.

It is also discouraging to see that there still are only PHP-examples of the Live API at hand for coders interested in new implementations/applications on new platforms (other than web services). I think clearer and better sorted dev documentation would be a more inviting approach to programmers out there.

Regards,

/Joakim
Post Reply