Tellstick Duo and php

Moderator: Telldus

Post Reply
plastbox
Posts: 22
Joined: Fri Mar 17, 2023 9:45 am

Tellstick Duo and php

Post by plastbox »

Hello

I have a few (hopefully) quick questions about interfacing with the telldus API using php. I know dll-files can be loaded into php (as COM-objects) on Windows, but I will be running homebrew software on a Raspberry Pi. This means Linux and as far as I know, there is no way to load so-files into php.

Has anyone written something that makes interfacing with the Tellstick Duo a bit easier? I'm thinking of writing a small c-application that includes the telldus-core library, and will do the following:

- Listen for incoming commands on an UDP-socket (on, off, list, dim, bell, etc).
- The "list"-command would reply by way of UDP-broadcast (since no other channels of communication are open), allowing all Tellstick-related services on the LAN to get the same device list update as a side effect.
- UDP-broadcast event data whenever an event is triggered (sensor or device data).

(First, I'm thinking about using UDP simply because a proper multi-client TCP-server needs to be threaded and as such is beyond my current c-skills (or at least the time I'd spend, skill level considered). If someone wrote a TCP-interface for the telldus-api though, I'd be more than happy to use it.)

Thus, my php daemon would need to listen for UDP broadcasts on a given port, and trigger whatever event/sensor handler I choose to write. In addition, it should store the ip from which said broadcast originated, allowing the php daemon to send control commands in return.

Any input would be appreciated as I will be receiving my Tellstick Duo tomorrow, and I find it rather irksome that there seems to be no good way of controlling it using php. Why on Earth the Telldus-devs haven't seen fit to implement something simple such as a socket/file/device one can read from to get events is beyond me. Hopefully it's my lacking knowledge that stops me from controlling my Tellstick Duo using php, not a choice by the Telldus dev team to exclude one of the most used computer languages on the planet. :?

Oh, also, is there a command line utility that does the same thing as tdtool.exe, only.. you know.. better? Tdtool's "list" option returns no info in the way of device type (dimmer, group, switch, etc). As of right now, I have to maintain data about the devices in a separate file/database, despite the fact that this information exists somewhere in the Telldus software. TelldusCenter is, after all, aware whether a device is a dimmer, a group or a switch. If "tdtool -l" could tell me this I'd be a content, if not happy camper as far as device listing and control goes.

Still though.. getting those events..
Zapper
Posts: 212
Joined: Fri Mar 17, 2023 9:45 am
Location: Där det är kallt

Re: Tellstick Duo and php

Post by Zapper »

Look a bit further, in linux there is a unix socket and in windows there is a named pipe. Not sure if there is any php libs already made but you can in linux use socat to have two TCP sockets, one for events and one for commands.

The java lib that is available utilizes this.
plastbox
Posts: 22
Joined: Fri Mar 17, 2023 9:45 am

Re: Tellstick Duo and php

Post by plastbox »

Zapper wrote:Look a bit further, in linux there is a unix socket and in windows there is a named pipe. Not sure if there is any php libs already made but you can in linux use socat to have two TCP sockets, one for events and one for commands.

The java lib that is available utilizes this.
Could you please elaborate a bit on the what's and the how's of this? I can create named pipes, great, but does the tellstick-software actually support communicating with 3rd party software by means of said pipes? Also, why would I want to have two TCP sockets? TCP is bi-directional, so if I end up using TCP over UDP I'll not really need more than one.

"The java lib".. what java lib? :P

Seriously though, why doesn't the base software for telldus include a simple TCP-interface for control and event listening? As a developer myself, this seems like the most logical choice in the world for a product series for which the main appeal is being able to communicate with almost anything over RF. Why not use the same ingenious way of thinking on the opposite end of the stick and implement a TCP-interface, allowing more or less absolutely any programming language since QBASIC7.1 to play nicely with the Tellstick devices? :?
krambriw
Posts: 654
Joined: Fri Mar 17, 2023 9:45 am

Re: Tellstick Duo and php

Post by krambriw »

@plastbox

I agree with you on that, it would have been very nice. Myself, as alternative to the dll stuff including the telldus service, I would also be just happy with a protocol to the device itself via a virtual comport.

You could eventually check the python wrapper here on the board: http://telldus.com/forum/viewtopic.php?f=15&t=2109

Even if not in php, this could be what you are looking for. The python source code shows at least some examples. I would assume you can find a lot about php with python on the net. Maybe you can use both for your purpose. Like PiP (Python in PHP).

Best regards, Walter
plastbox
Posts: 22
Joined: Fri Mar 17, 2023 9:45 am

Re: Tellstick Duo and php

Post by plastbox »

krambriw wrote:@plastbox

I agree with you on that, it would have been very nice. Myself, as alternative to the dll stuff including the telldus service, I would also be just happy with a protocol to the device itself via a virtual comport.

You could eventually check the python wrapper here on the board: http://telldus.com/forum/viewtopic.php?f=15&t=2109

Even if not in php, this could be what you are looking for. The python source code shows at least some examples. I would assume you can find a lot about php with python on the net. Maybe you can use both for your purpose. Like PiP (Python in PHP).

Best regards, Walter
Well, lacking a proper interface for php itself, that looks quite promising. I haven't used PiP before but it'll be fun to play around with integrating your Python wrapper into a php daemon, especially getting the events and function calls to work. Perhaps I'll solve it by simply modifying the Python wrapper to write event data to STDOUT and read commands from STDIN. That way, I can use proc_open in php to execute the wrapper and communicate over STDOUT/IN. :D

Thanks!
Post Reply