Python wrapper of libtelldus

Moderator: Telldus

Python wrapper of libtelldus

Postby davka003 » Thu Jun 28, 2012 8:25 pm

Hi
I have put togheter a wrapper for python linux users that want to skip tdtool and work directly against the libtelldus.

Source is available here:
http://bitbucket.org/davka003/pytelldus/

There is also an example that mimics tdtool but is written in python.

Currently I am lacking support for the API commands for changing the configuration and event handling.

Configuration will come, just missing answer to a question on permissions here: viewtopic.php?f=8&t=2107

Event handling will probably also come, but as I am lacking a DUO it doesnt make much sense to develop that yet.

Please let me know what you think. Contributions are allways welcome.
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
davka003
 
Posts: 126
Joined: Sat Oct 29, 2011 8:56 am
Location: Sweden

Re: Python wrapper of libtelldus

Postby davka003 » Mon Jul 09, 2012 2:54 pm

Now configuration and most event handling is added as well.
Currently missing support for:
Code: Select all
int tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context );
int tdRegisterControllerEvent( TDControllerEvent eventFunction, void *context);
int tdSendRawCommand(const char *command, int reserved);


All the remaining APIs are in there, as well as untested Windows support.

An example tdtool is there as well that is able to serve as an example of how it can be used.

Let me know if you have any questions.
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
davka003
 
Posts: 126
Joined: Sat Oct 29, 2011 8:56 am
Location: Sweden

Re: Python wrapper of libtelldus

Postby micke.prag » Mon Jul 09, 2012 3:24 pm

Great wrapper. I have just one note.

Regarding your init function. You may never assume which methods the library client will implement. This goes against the purpose of the supportedMethods variable. You should define the ini function like this:
Code: Select all
def init(defaultMethods = 0):


It is always up to the end software to decide the methods.
Micke Prag
Software
Telldus Technologies
micke.prag
Site Admin
 
Posts: 2068
Joined: Thu Jul 27, 2006 8:25 pm
Location: Lund

Re: Python wrapper of libtelldus

Postby Klas » Wed Jul 11, 2012 6:13 pm

Noticed a bug in __main__

Code: Select all
    for i in range(getNumberOfDevices()):
        print getDeviceId(i), getName(i), methods(i)

Should be
Code: Select all
   for i in range(getNumberOfDevices()):
        id = getDeviceId(i)
        print id, getName(id), methods(id)


Same problem exists in getDeviceIdFromStr()
Klas
 
Posts: 12
Joined: Wed Jul 11, 2012 8:25 am

Re: Python wrapper of libtelldus

Postby davka003 » Thu Jul 12, 2012 4:45 pm

Thanks for the bugreport, i Will look into it when i am back from vacation.
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
davka003
 
Posts: 126
Joined: Sat Oct 29, 2011 8:56 am
Location: Sweden

Re: Python wrapper of libtelldus

Postby davka003 » Fri Jul 13, 2012 8:13 pm

Thanks Klas and Micke for pointing out these problems. They are now fixed and pushed to the git repository. At the same time I added support for raw device event's as I just got hold of an DUO.
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
davka003
 
Posts: 126
Joined: Sat Oct 29, 2011 8:56 am
Location: Sweden

Re: Python wrapper of libtelldus

Postby Klas » Sat Jul 14, 2012 8:35 am

Great,

A suggestion, it would be nice with a debug-flag. To be used instead of if 0: in the callbacks.
Klas
 
Posts: 12
Joined: Wed Jul 11, 2012 8:25 am

Re: Python wrapper of libtelldus

Postby Mahlstrom » Sun Jul 15, 2012 9:44 am

Great wrapper!

I've tried it out using mac os x adding
Code: Select all
elif (platform.system() == 'Darwin'):
    #Mac
    from ctypes import cdll, CFUNCTYPE
    tdlib = cdll.LoadLibrary('/Library/Frameworks/TelldusCore.framework/TelldusCore')


The only problem I've got was when calling tdlib.tdReleaseString(vp)
python2.6(10014,0x7fff752b2180) malloc: *** error for object 0xffffffffb2601c50: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

Do you guys know how to solve this?
Or is skipping tdReleaseString the only solution?
Mahlstrom
 
Posts: 2
Joined: Sun Jul 15, 2012 9:31 am

Re: Python wrapper of libtelldus

Postby davka003 » Mon Jul 16, 2012 4:04 pm

If you dont mind I will include your code snippet in the git repository. Is that ok?

At least once the memory handling has been strighten out.
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
davka003
 
Posts: 126
Joined: Sat Oct 29, 2011 8:56 am
Location: Sweden

Re: Python wrapper of libtelldus

Postby Mahlstrom » Mon Jul 16, 2012 9:41 pm

No problem at all.
Found it while running thou the forums to learn about python/telldus.
And btw, while adding, what i did was just adding
Code: Select all
if (platform.system() != 'Darwin'):
before tdReleaseString

Right now i'm thinking about tackle the tdSendRawCommand
How far have you come so far?
Mahlstrom
 
Posts: 2
Joined: Sun Jul 15, 2012 9:31 am

Re: Python wrapper of libtelldus

Postby davka003 » Tue Jul 17, 2012 7:16 am

I include your source contributions then. (With a comment about potentially memory leak).

For Raw Command sending I havent tried anything at all. (I dont know any good way of testing if I am correct). But I think it should be as simple as:

Code: Select all
def sendRawCommand(command, reserved = 0):
    return tdlib.tdSendRawCommand(command, reserved)


I allways push all my changes to the git repo as soon as I have done anything so all I got is in there.
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
davka003
 
Posts: 126
Joined: Sat Oct 29, 2011 8:56 am
Location: Sweden

Re: Python wrapper of libtelldus

Postby UglyBob » Fri Aug 10, 2012 7:15 am

Hi!

I can't get this to work. If I run the python script with -t option and trigger a sensor, nothing happens. Am I missing something? I can't add the sensor to tellstick.conf as I have no information about it. I think I have installed all libraries from the repo, so what am I missing? Is there a guide for getting sensors to work in linux with tellstick duo? I can't seem to find any useful information...
UglyBob
 
Posts: 15
Joined: Wed Aug 25, 2010 1:43 pm

Re: Python wrapper of libtelldus

Postby davka003 » Fri Aug 10, 2012 11:04 am

You dont have to configure anything in Linux to get sensors to work. But be aware that the range may not be very good. My temp sensor sends a signal every 50 sec. If the duo receive the signal it flashes blue. Also you could try pressing the button on a ordinary nexa remote or similar. This should also give you blue blink.
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
davka003
 
Posts: 126
Joined: Sat Oct 29, 2011 8:56 am
Location: Sweden

Re: Python wrapper of libtelldus

Postby UglyBob » Fri Aug 10, 2012 11:54 am

Yes, I do see it flashes when triggering my motion sensor or pressing the remote. But how will I access the data? Is using the API the only way or are there other tools for testing?
UglyBob
 
Posts: 15
Joined: Wed Aug 25, 2010 1:43 pm

Re: Python wrapper of libtelldus

Postby davka003 » Fri Aug 10, 2012 8:24 pm

I think there is a clarification needed.

Sensors in the tellstick world are not Nexa motion detectors or light sensor. It is only temperature and humidity that is sensors. All others are deviceevent or rawdeviceevent.
If you see the duo flashes you should see a rawDeviceEvent (or many) if you run python tdtool.py --event

To make it device event you need to create a device entry in /etc/tellstick.conf matching the protocol/house/unit code reported in the rawdeviceevent.
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
davka003
 
Posts: 126
Joined: Sat Oct 29, 2011 8:56 am
Location: Sweden

Next

Return to Linux

Who is online

Users browsing this forum: No registered users and 1 guest

cron