Python wrapper of libtelldus

Moderator: Telldus

davka003
Posts: 187
Joined: Fri Mar 17, 2023 9:45 am
Location: Sweden
Contact:

Re: Python wrapper of libtelldus

Post by davka003 »

At the moment there is one way to do it and that is by creating a signal transform but for you to be able to do that with the current level of documentation requires at least that you get signal debug working. I am currently away and writing this on a phone so it is tricky to make extensive instructions.

I answer your question with a question: how would you like it to be configurable? Should a raw tellstick device have a field that forwards incoming events to another device or do you want more flexibility to act differently for on and off for example.

In my use case I allways configure device to control switches directly and use my system for additional functionality. I don't route all device commands thru it. Basically my tellstick + raspberry pi is not needed to turn on and off lamps.
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
evertsson
Posts: 8
Joined: Fri Mar 17, 2023 9:45 am

Re: Python wrapper of libtelldus

Post by evertsson »

davka003 wrote:At the moment there is one way to do it and that is by creating a signal transform but for you to be able to do that with the current level of documentation requires at least that you get signal debug working. I am currently away and writing this on a phone so it is tricky to make extensive instructions.

I answer your question with a question: how would you like it to be configurable? Should a raw tellstick device have a field that forwards incoming events to another device or do you want more flexibility to act differently for on and off for example.

In my use case I allways configure device to control switches directly and use my system for additional functionality. I don't route all device commands thru it. Basically my tellstick + raspberry pi is not needed to turn on and off lamps.

In the long run I want to use it as a smaller alarm center.

If the motion sensor activates, sound a bell or turn on a camera or something similar. I would also like to be able to send an email or send a REST request to some server..

For now I just want to turn on a light..


Maybe this is little to of topic, is there somewhere else to discuss this? Maybe in swedish.. If you are interested to help me that is.. :)
davka003
Posts: 187
Joined: Fri Mar 17, 2023 9:45 am
Location: Sweden
Contact:

Re: Python wrapper of libtelldus

Post by davka003 »

You find my email on my homepage and I am happy to assist you in Swedish :-)
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
davka003
Posts: 187
Joined: Fri Mar 17, 2023 9:45 am
Location: Sweden
Contact:

Re: Python wrapper of libtelldus

Post by davka003 »

I've just committed a new version of my wrapper. No new functionality but the callback handling is now done in a way that I am not embarrassed of sharing with the world.

Feedback or support just ask here or you find my email on my homepage.
My home automation software: Automagically @ Raspberry Pi http://automagically.weebly.com
jkp
Posts: 42
Joined: Fri Mar 17, 2023 9:45 am

Re: Python wrapper of libtelldus

Post by jkp »

Hi,

Thanks for the python wrapper, looks quite useful.

I got my Tellstick Duo on Tuesday, and started trying to hook up various devices to it. Plans are to perhaps connect it to a Raspberry Pi and use it with XBMC among others. Or maybe in the long run even to buy cheap 433,92 Mhz receiver/transmitter sensors described in posting at http://www.telldus.com/forum/viewtopic.php?f=22&t=2175 for the Pi, see if they can be gotten to work hooked directly to Pi's i/o pins, to leave the Duo for a bigger computer.

Anyway, found an old remote control socket which worked right away, and bought some new sockets from Clas Ohlson which also work fine. So basic stuff seems good enough.

I was hoping the Duo would work with our WH1080 weather station (also from Clas Ohlson), but unfortunately it seems it doesn't react at all to the signal from the WH1080.

Bought also a simpler weather station on sale at Clas Ohlson for 20 euros, http://www.clasohlson.com/uk/Weather-St ... r364440000 - at first I thought that fine, I'm getting a temperature reading of 20,4, but the humidity is wrong at 255. On closer looks, the temp is -20,4, so that's off too. Output from tdtool.py -t:
1351120182: RawDeviceEvent: class:sensor;protocol:fineoffset;model:temperaturehumidity;temp:-20.4;humidity:0xFF;id:0xFF;
controllerId: -1
1351120182: SensorEvent
protocol: fineoffset
model: temperaturehumidity
id: 255
dataType: 1
value: -20.4
timestamp: 1351120182
1351120182: SensorEvent
protocol: fineoffset
model: temperaturehumidity
id: 255
dataType: 2
value: 255
So, am I to think that I may be out of luck with this temperature / humidity sensor, too? Did I understand correctly that the decoding is done in a PIC inside the Duo, and thus modifying the C source for telldus-core won't help? Is there any chance of an open source dev kit for coding the PIC so support for WH1080 or the cheap weather station could be added?
jkp
Posts: 42
Joined: Fri Mar 17, 2023 9:45 am

Re: Python wrapper of libtelldus

Post by jkp »

Traced the execution path, and indeed it seems like the string:
class:sensor;protocol:fineoffset;model:temperaturehumidity;temp:-20.4;humidity:0xFF;id:0xFF;
comes directly from the firmware, so apparently I'm out of luck (at least with the stock firmware in the device) with both weather sensors, despite the promising blink.

I also added a debug print for version data, and seems it's version 4, which I understand is the latest.

Apparently there have been plans to open also the Duo firmware, mentioned in thread, http://www.telldus.se/forum/viewtopic.p ... 96c21a6351 - maybe I should check in there for the current info.
jkp
Posts: 42
Joined: Fri Mar 17, 2023 9:45 am

Re: Python wrapper of libtelldus

Post by jkp »

One interesting-looking approach to add 433.92 Mhz comms (among other things) to the Raspberry Pi is a piggyback board with a RFM22B radio, infrared receiver, a wMBUS stack, RTC clock with battery, breadboard area etc.

http://www.raspberrypi.org/phpBB3/viewt ... 45&t=13264
http://www.raspberrypi.org/phpBB3/viewt ... 45&t=20432
jkp
Posts: 42
Joined: Fri Mar 17, 2023 9:45 am

Re: Python wrapper of libtelldus

Post by jkp »

Apparently the 20.4 temp at the start value probably was a correct observation after all - looks like there are occasional bit errors in the readings, which sometimes result in 20.4. But mostly it's -20.4.
SENSORS:

PROTOCOL MODEL ID TEMP HUMIDITY LAST UPDATED
fineoffset temperaturehumidity 255 -20.4° 255% 2012-10-26 07:45:16
fineoffset temperaturehumidity 254 20.4° 255% 2012-10-25 12:53:48
fineoffset temperaturehumidity 127 -20.4° 255% 2012-10-25 17:17:54
fineoffset temperaturehumidity 223 -20.4° 255% 2012-10-25 19:24:15
heisenberg
Posts: 3
Joined: Fri Mar 17, 2023 9:45 am

Re: Python wrapper of libtelldus

Post by heisenberg »

Great tool, thank you for sharing. I struggled quite a bit some time back to figure out ctypes memory management, so as I'm starting to do a little python programming again with my Duo, I would much rather use this wrapper.

One question: under what license are you sharing your code? I could not find any information about this. Would be great to have details about this in the source headers. Without license information it can't really be used in any projects (including non-commercial or personal).
larslund
Posts: 2
Joined: Fri Mar 17, 2023 9:45 am

Re: Python wrapper of libtelldus

Post by larslund »

Hi,

thank you for this wrapper. I started developing a small alarm system recently and appreciate this wrapper.

However, in my project calling the td.registerSensorEvent() causes a segmentation fault. Basically I am doing the following:

From my application I spawn a thread (implemented in a class inheriting from threading.Thread) where I run more or less the code provided here: http://lassesunix.wordpress.com/2013/08 ... pberry-pi/.

I can control the loop from outside the thread to stop it, followed by the unregistering of the events and closing td as in the example. The first time this works fine. If I create another instance of my thread, then I get the segmentation fault upon calling registerSensorEvent(). All the stuff is running on a Raspberry Pi, Debian Wheezy, Python 2.7.

Do you have any ideas?

Thanks,

Lars
larslund
Posts: 2
Joined: Fri Mar 17, 2023 9:45 am

Re: Python wrapper of libtelldus

Post by larslund »

Hi again,

regarding the problem in my last post it turned out to be a bug in telldus-core. What's even better that this bug has been fixed and released with telldus-core 2.1.2!

Thanks to the guys at Telldus support!

Problem solved,

Lars
bpa
Posts: 2
Joined: Fri Mar 17, 2023 9:45 am

Re: Python wrapper of libtelldus

Post by bpa »

Hi,

I have this segmentation problem with the python wrapper and using the tdtool.py applications.

I have a core i5 Ubuntu 14.04 system and have a Tellstick Duo (batch no:13131) and a Nexa LMST-606 magnetic door switch.

I installed using Ubuntu packages the Telldus Center and Telldus 2.1.2 packages.

I initially had problems with Tellstick which was fw 5 and had to upgrade 12 but it wouldn't upgrade until I used MProg3.5 and change the C0,C1 & C2 settings.

Once fw was upgrade switch seemed to work OK with tdtool.py and was able to configure and use with TelldusCenter. However now when tdtool.py using "-t" to display events - I get segmentation errors. Sometime after first event, sometimes after a few events. Core dump shows crash is happening in the EventHandler code which was the area this bug had a ticket open and where changes had been made.

I removed the Ubuntu Telldus-Core packaged and rebuilt Telldus-core from downloaded code from Trac - but still the same problem. My guess is the problem, which has had a few fixes, is still there in timing and mutex locking and the fast i5 multi-core processor is making the issue visible.

Any suggestions on code changes to try ?

tks
bpa
Posts: 2
Joined: Fri Mar 17, 2023 9:45 am

Re: Python wrapper of libtelldus

Post by bpa »

I found the problem - nothing to do with mutex or locking.

I have a Linux 64 bit system and the segementation crash is caused by the same tdReleaseString crash on Darwin that was reported back in 2012 in the thread.
What is happening is that the 64 bit string pointer is passed to the tdReleaseString fucntiopn but top 32 bit are corrupted (e.g the pointer 7F37F8000C90 becomes in tdReleaseString 0xfffffffff8000c90 ) - it looks like the handling by FFI of a c_void_p argument gets mixed up on Linux 64 and thinks it is a 32 bit integer. Scanning various post it seem it is is a general 64 bit problem initially found with OSX Darwin and then with a Java 64 bit.

In the td.y code in many places there is the workaround for Darwin shown as

Code: Select all

  cp = c_char_p(vp)
  s = cp.value
    
  if (platform.system() != 'Darwin'): #Workaround, mac crashes on nest line
      tdlib.tdReleaseString(vp)
1. The code should be updated to indicate that "crash" is a segementation violation and that it happens not just on Darwin so workaround is limited.
2. I think a better workaround might be to use "cp" instead of "vp" in the tdReleaseString. The addresses are equal because it is Python which doesn't create a new string just copies the pointer and 64 bit address is passed correctly to tdReleaseString. This would need to be tested on 32 bit and other systems.

Code: Select all

  cp = c_char_p(vp)
  s = cp.value
   
  tdlib.tdReleaseString(cp)
Post Reply