PLCBUS and Linux

Forum about PLCBUS devices & software.

Moderator: Digit

Jfn
Member
Member
Posts: 332
Joined: Tue Feb 26, 2008 2:01 pm
Location: Netherlands
Contact:

PLCBUS and Linux

Post by Jfn »

Last week I finished fitting all light-switches in my house with PLCBUS micromodules, so I decided to continue working on the software that eventually will control those modules.

I use LAMP (Linux, Apache, MySQL, PHP) and Perl and intend to build my home-automation system with this software.

I want to be able to control PLCBUS devices from within any application that is running on my system, being it a scheduler, event-handler or a web-based application for manual control. The easiest way of realising this is a central hub that collects all messages, transmits them to the PLCBUS interface and returns a status to the calling process.

For this I implemented a UDP server that continuously monitors a socket for incoming messages. When it receives a message it will process it and return the status.

For example, sending the command 'AB,ON' will turn micromodule A11 on (I use HEX values for the unit codes). These kind of commands can be send easily from a web-page, of from a another script / program.

Attached you will find the hub and a client program, should give you an idea of how things are working. There are some minor issues left to be solved (Mainly status-reports), the code needs cleaning-up, but at least I can start designing a webpage to control the light-switches from.

Comments on how I coded things are welcome. Should you make improvements, please share!

Start the hub: ./hub_plcbus.pl
The client: ./client AB,ON (Switches on A11; Unit-code in HEX)


Download Attachment:
domoticaforum.eu/uploaded/Jfn/200861411 ... bus.pl.txt

Download Attachment:
domoticaforum.eu/uploaded/Jfn/200861411 ... bus.pl.txt

Als het niet gerepareerd kan worden dan is het niet kapot!
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

PLCBUS and Linux

Post by Digit »

Nice work!
This can be a very good starter for others, programming in Perl.
You could consider adding another check to received frames, that is checking on the usercode that it contains. At least, that's what i do, it saves on unnecessary processing of frames that are useless anyway.
xelahome
Starting Member
Starting Member
Posts: 1
Joined: Sun Aug 23, 2009 2:26 pm
Location: France

PLCBUS and Linux

Post by xelahome »

Hi,

I would like to know if there is anything new regarding PLCBUS and Linux since this post ?

Like for example, a xPL-Perl module for PLCBUS based on what Jfn did in june 2008 ?

Thanks
luria
Starting Member
Starting Member
Posts: 36
Joined: Tue Mar 16, 2010 11:51 am

Re: PLCBUS and Linux

Post by luria »

I have been struggling to get this working all day. A very limited knowledge of perl does not help.
All i get is

Code: Select all

Server localhost responded ``ERROR,0,0''
My suspicion is that the creator of the script uses a three-phase setup, but i'm not able to change that.
it may be buried in this codeline ?

Code: Select all

 $plcbus_command = $plcbus_command_to_hex {$params_data[1]} || 0xffff;  
As i understand, my command should be 0x00 i.e. '0000' and 0x02 '0010' in order to turn something on.

Also, changing the 'alarm' timepout to 5 sec makes the client return 'Alarm clock'. A peek at the command sent to the serial interface (dev/ttyUSB3) with 'print' comes up with 'puTTY', which I use to access my server. Beats me.
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: PLCBUS and Linux

Post by Digit »

Hi luria,

I don't know anything about the scripts that jfn created, but as far as i can see your error message is not PLCBUS related.
From what i read you'll probably need Apache, MySQL, PHP and Perl installed. Do you?
Well, i think the best thing to do is wait for jfn to have a look at this; he'll probably be able to give you some tips to get it working.

FWIW, here's the PLCBUS protocol documentation: http://files.domoticaforum.eu/PLCBUS/plcbus-1141.pdf
luria
Starting Member
Starting Member
Posts: 36
Joined: Tue Mar 16, 2010 11:51 am

Re: PLCBUS and Linux

Post by luria »

Thank you for answering. Well, I'm already running a lamp-server (ubuntu 9.10 server), perl (5.10) is apparantly working with the required modules installed and the hub is responding to the messages over udp. I have a lot of other stuff requiring perl, mysql apache and php running, so the environment should be ok. No command or statuspacket are apparently sent or received correctly from the 1141 interface. Looks like this sunday is going to be wasted too :)
waynet
Starting Member
Starting Member
Posts: 5
Joined: Fri Sep 17, 2010 10:52 am

Re: PLCBUS and Linux

Post by waynet »

The problem is definitely from the PLCBUS control, and you are correct that jfn's script is set up for 3 phase (although you were looking at the wrong line).
I have taken jfn's script as a starting point, made a whole bunch of changes, and mixed in a module written by Ron Frazer (http://www.ronfrazier.net/mythtv/0.22/index.html). The net result is a PLCBUS controller that is 100% reliable (at least for me, I have not had a single missed command or reply) that can be controlled from anywhere on a LAN or even through the internet (if you know what you are doing).

I will post it tonight when I get home in case anyone wants to use/improve it. Thanks to jfn for providing the start point!

Cheers
Wayne
waynet
Starting Member
Starting Member
Posts: 5
Joined: Fri Sep 17, 2010 10:52 am

Re: PLCBUS and Linux

Post by waynet »

Sorry folks, tried posting the files but the forum won't let me (won't accept files with .pl or .txt or even without an extension).
Any ideas?
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: PLCBUS and Linux

Post by Digit »

This forum has a file area, provided by snelvuur. Maybe he can help you.
waynet
Starting Member
Starting Member
Posts: 5
Joined: Fri Sep 17, 2010 10:52 am

Re: PLCBUS and Linux

Post by waynet »

Ha ha! snelvuur just sent me a PM but since I am new to the forum I am not authorised to read the message; despite it being sent to me! I imagine it lets me know if/how I can upload the files but since I can't access the PM I'm still stuck.
Maybe we will eventually get there...
User avatar
JohnieBraaf
Starting Member
Starting Member
Posts: 32
Joined: Sat Sep 18, 2010 3:21 am
Location: Amsterdam
Contact:

Re: PLCBUS and Linux

Post by JohnieBraaf »

Hi Wayne!

I would be interested in the script you have adapted...
Would you like to share it?

Regards,

Jan
waynet
Starting Member
Starting Member
Posts: 5
Joined: Fri Sep 17, 2010 10:52 am

Re: PLCBUS and Linux

Post by waynet »

I have tried and failed due to restrictions applied to new members of the forum. :(

I am willing to post the files in my public dropbox, but can not guarantee that I will host them there for ever. Here they are:

Server:
http://dl.dropbox.com/u/11711990/Serial/plcbus.pl

Required Module originally written by Ron Frazer:
dl.dropbox.com/u/11711990/Serial/IOSele ... uffered.pm

1. Save plcbus.pl into an executable directory (I use /usr/local/bin) and make it executable.
2. Modify $serdev on line 11 of plcbus.pl to match your system (i.e. /dev/ttyUSB0). I use a custom udev rule to ensure my device is always /dev/plcbus.
3. Save IOSelectBurrered.pm into a directory called SerialLibs (note the use of uppercase letters) in one of the standard perl module locations (I use /etc/perl/SerialLibs).
4. Run the server in the background

Code: Select all

plcbus.pl &
5. Send commands from any network connect pc using netcat in the following format:

Code: Select all

 echo -e 'a1,preset_dim,64,5\nEXIT\n' | nc -i 1 localhost 5151
where
a1 can be replaced with the appropriate plcbus device
preset_dim can be replaced with the appropriate command or query (see lines 18 to 46 of plcbus.pl for a complete list)
64 can be replaced with an appropriate value (in hex) for the command (ignored if not relevant)
5 can be replaced with an appropriate value (in hex) for the command (ignored if not relevant)
localhost can be replaced by the appropriate hostname or ip address that the server resides upon
-i 1 is only required if you are sending commands from a remote computer and don't seem to be getting a response

6. Sit back and revel in the otherworldly power you now exert over your home appliances!!! :D
7. Read the feedback from the device and confirm that yes, the light is definitely now on...

The example code above turns device a1 (a dimmable light module) on to full brightness (hex 64 = 100) over a period of 5 seconds. The response given is

Code: Select all

PRESET_DIM,100,5
which tells you that the dim level is 100% and the execution time was 5 seconds.

Note: I just tested this by turning on my lounge room light at home from work (to check my memory) and just got a phone call from my wife to ask why the light was switching on and off :lol:
User avatar
JohnieBraaf
Starting Member
Starting Member
Posts: 32
Joined: Sat Sep 18, 2010 3:21 am
Location: Amsterdam
Contact:

Re: PLCBUS and Linux

Post by JohnieBraaf »

Fantastic! I just gave this a whirl and it works as it's supposed to! Many thanks.
user888
Starting Member
Starting Member
Posts: 3
Joined: Sat Jan 22, 2011 11:44 am

Modules don't send ETX

Post by user888 »

Thanks for the script, really helpful to me. I've got the PLCBUS computer-interface (RS-232 version), a 2026G lamp module and a 2027G appliance module.
I've got the script working (had to rewrire parts of my house to go from 3 phase to 1 phase). But, I had to adapt the script because replies from the two modules don't have the ETX bit, but some other value. Behold...

Code: Select all

Sent Packet     = 02 05 ff 10 2c 48 00 03
Received Packet = 02 06 FF 10 2C 48 01 1C 58
Received Packet = 02 06 FF 10 2C 48 01 20 54
Received Packet = 02 06 FF 10 2C 48 01 1C 58
Received Packet = 02 06 FF 10 2C 48 01 20 54
Received Packet = 02 06 FF 10 2C 48 01 1C 58
Received Packet = 02 06 FF 10 2C 48 01 20 54

02 = STX (start header)
06 = Data length
FF = usercode
10 = homeunit
2C = command
48 = value 1
00 = value 2
20/1C = RX_TX_SWITCH?
54/58 = ?
Does anybody know what is causing it?
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: PLCBUS and Linux

Post by Digit »

Yes.
Read http://www.domoticaforum.eu/viewtopic.php?f=38&t=5735, you've probably got a "+" version interface, which works with a checksum.
Post Reply

Return to “PLCBUS Forum”