Showing posts with label Perl. Show all posts
Showing posts with label Perl. Show all posts

Wednesday, 8 December 2021

Serial Perl Revisited

I'd posted this item on creating a custom serial driver / interface in  PERL a few years ago, and needing to revisit it for another project, I found that there was now an issue with running the Win32::Serial module on 64-bit Windows, Windows 10 specifically.

The problem was, when I ran some Perl that previously worked for me, it now failed when querying a serial port with an error like this;

error: Second Read attempted before First is done at xantech.pl line 47.

Some Google-Fu later, I found a reference to the issue on PerlMonks, and a link by user cr8josh to the fix by Christopher Oicles which is published here.

It looks like there's a risk that the rt.cpan site will close, so I'm reproducing the fix here for my own future sanity;

Monday, 10 October 2016

Seeking Comfort



Embarking on the great home automation project of 2016, I wanted to get my openHAB installation talking to my legacy Comfort system.

I'd installed the comfort system 15 years ago, (it's a Comfort Pro), and it's been very reliable if somewhat basic since. At it's core, it's a home automation system that can function as a security system, telephone answering machine, lighting controller, infra-red blaster and a number of other tasks.

It's got a range of modular input and output systems and in my case, connects to the outside world via an RS232 serial interface. (USB and Ethernet options are also available but I don't have them). The system can be programmed and works on the basis of zones/inputs and responses so can be set up to, say, switch a light on if a particular sensor is tripped after dark.

I have window and door sensors connected up as well as a few PIRs as well as an X-10 interface for lighting control. There's a doorphone at the front door and the system is connected to the telephone line. This means that if we're not at home and the doorbell rings, we can set the system to call a mobile and we can speak to the person at the door. Neat.

Comfort has been updated over the years and version 2 has been out for a while with support for more modern protocols etc. but as an upgrade would require me to replace the entire system, I didn't bother.

Now with a renewed interest in home automation and a decision to pursue openHAB as the core, I needed to find a way to get Comfort and openHab linked up. I really don't want to throw out a perfectly good alarm system and have to rebuild it all again with new components just to get the same functionality. My ambition is to reuse and recycle what I have if it's fit for purpose.

Sunday, 9 October 2016

MQTT bi-directional communications in PERL

In attempting to interface openHab with my Comfort system, I needed to adapt an existing Perl linux driver for Comfort to work in Windows. The idea is that a small Perl program manages serial communications with the Comfort system and uses the IoT protocol MQTT to pass messages back and forth with openHab.

In doing so, I found that there was a very limited amount of information on integrating MQTT with Perl. There is a minimal MQTT interface for Perl that does the trick but the sample code was not obvious to me and there's very little else out there.

I've written a vey basic Perl <-> MQTT program to show how basic input and output is achieved.