Arduino and Omni PRO II via serial - first working code.

cestor

Active Member
Managed to get this working (Thanks!!!) 
However, I see that it is a master-slave configuration with the HAI controller being the slave. If I want an external device attached to the Arduino to run on a button press, do I have to get the Arduino to poll flags every second, or is there a better way to do this?
 

tigers

Active Member
Hi, glad you did it. Of course there's a better way, using the serial message capability of the OMNI II: you can send any of the messages that can be displayed over one of the serial port on board, then you can have the Arduino monitor that serial port and behave accordingly.
The only downside is that you'll need 2 serial ports both on the console and the Arduino; all OMNI PRO consoles come with 2 or 3 serials, so if you haven't any third party device using the ports you should be fine, for Arduino you must use a MEGA, that has 3 serial on board, maybe a Leonardo that has 2, or simply use a SoftSerial library, that should be fast enough.
 
That being said you must first set the serial on the console to the PRO-LINK protocol via PC-ACCESS.
Then program the console so that when your trigger activates, it sends a message to SERIALX (where X is the serial port you're using) - check out the pro link protocol on HAI documentation.
On Arduino side, my code goes like this:
some notes:
  • The messages I send are in the form HAI1, HAI2, HAI3, etc., but they could be anything; as a matter of fact they are parsed only partially, when it gets an "H" it jumps to the number at the end;
  • I use the messages to trigger a function that pushes messages on my mobile devices when certain situations happen, but you could do anything you want;

//HAI PRO-link protocol data arrays
byte byteReadPro;
byte HAI_PRO_messageID; //6 chars at max for Hai triggers: HAIXXX, but can be longer if sending HAI console messages

[...]

if (Serial2.available()>0){
Serial.println("Data available on Serial2");
if (readProLink()>0){ //the function returns the HAI message number

//PARSE the HAI Message and do things
switch (HAI_PRO_messageID){
case 1:
sendToPushingBox(DEVID1);
break;
case 2:
sendToPushingBox(DEVID2);
break;
case 3:
sendToPushingBox(DEVID3);
break;
case 4:
sendToPushingBox(DEVID4);
case 5:
sendToPushingBox(DEVID5);
break;
}//END switch

}//END if parseProLink
}//END if Serial2.avaliable


byte readProLink() {//gets the command form Serial2 coming in the form HAIXXX (in fact it reads any message like HwhateverXXX)
//static byte dataBufferIndex2=0;
static byte messageSize2=DATABUFFERSIZE; //length of the message, at the beginning it can be the maximum value
static boolean storeVal2=false; //flag to define if the incomingbyte has to be put in the array
static boolean ended2 = false; //flag for end of message
char incomingChar;

while(Serial2.available()>0){
//Serial.print("Receiving data on Serial2 Prolink: ");//DEBUG
//Serial.println(dataBufferIndex2);
incomingChar = Serial2.read();//put data in incomingbyte variable
Serial.print("Data received: ");
Serial2.println(incomingChar);
if(incomingChar=='H' ){//if it's H it should be the beginning of the HAIXXX command
HAI_PRO_messageID = Serial2.parseInt();
Serial.println();
Serial.print("HAI PRO Message received: ");
Serial.println(HAI_PRO_messageID);
return HAI_PRO_messageID;
}//END if
}//END while Serial2.available

return 0;

}//END readProLink()


I also have to mention the "easier" way, that is having the HAI to activate a relais connected with one of the Arduino inputs, but I prefer the serial solution, that also requires less space.
 

cestor

Active Member
Nice. I don't really want to use another serial port on the OP2 though as I want to keep it for future expansion. What I'm thinking is that maybe using a single port  which runs the readProLink function in the loop() function and which on demand closes it, runs the login, some action and then again closes the serial may be the way to go. What do you think? 
 

tigers

Active Member
I never thought of that since I always kept them separated (and also my OPII has 3 serial on board so I still have one free to use), on Arduino side it's certainly doable, but you can't do that on OPII side, since the serial port must be set to PRO LINK via PC ACCESS, and this won't allow comunication to the Arduino.
 
I believe that your first idea of polling a flag from Arduino via the HAI protocol is the best way to go, it's not complex to do and quite reliable (that's the way third party front-ends do). If I recall correctly there's also a "list changes from last request" function that returns all the state changes from the previous call of the function - but can't remember if that is just for the LAN protocol or also for serial.
 

cestor

Active Member
The reason why I was slightly concerned about the polling is whether it would be too much traffic, hammering the OP2 and potentially causing an impact. It is definitely the easiest way though. A pity that there is no way to programmatically change the protocol from Omni-link to Pro-link and back as needed...
 

JonW

Senior Member
I know you've stated that you're pretty well set on using the Arduino, but you really should think about whether it is the right tool for the job.  With a $35 Pi, you could utilize the HAI OmniPro SDK (via Ethernet) and quickly build an app that receives all real-time notifications of OPII events without any polling.  Yes, it uses a Windows DLL file, but it runs just fine on the Pi.
 

tigers

Active Member
cestor said:
The reason why I was slightly concerned about the polling is whether it would be too much traffic, hammering the OP2 and potentially causing an impact. It is definitely the easiest way though. A pity that there is no way to programmatically change the protocol from Omni-link to Pro-link and back as needed...
Serial communication is very very slow compared to the speed of even not very performing CPUs like the ones of Arduino and OPII, so there's no way you can choke them with serial requests.
 

tigers

Active Member
JonW said:
I know you've stated that you're pretty well set on using the Arduino, but you really should think about whether it is the right tool for the job.  With a $35 Pi, you could utilize the HAI OmniPro SDK (via Ethernet) and quickly build an app that receives all real-time notifications of OPII events without any polling.  Yes, it uses a Windows DLL file, but it runs just fine on the Pi.
I think Arduino suits well the job, but I'd be quite interested in the RasPi solution, problem is I know absolutely nothing about RaspPi or Unix and I couldn't find a step by step guide to help me setting everything up.
 

tigers

Active Member
I'm interested in setting up openHAB, and I'd really appreciate if I could exchange some experience with someone who did it.
 

JonW

Senior Member
tigers said:
I think Arduino suits well the job, but I'd be quite interested in the RasPi solution, problem is I know absolutely nothing about RaspPi or Unix and I couldn't find a step by step guide to help me setting everything up.
There's a good Linux install for the Pi called NOOBS that has step-by-step for setting it up:  https://www.raspberrypi.org/downloads/noobs/
 
You can use a Windows PC to download the image, write it to a micro-SD card, then pop it into the Pi and boot it up.
 
For development, you can use Visual Studio and C# or VB.net to make apps to run on it.  You need to install the MONO library modules to enable .NET on Linux, but that's easy too.  You can then develop the program with VS on the PC and copy it over to the Pi to run it.  That's how I do it - all dev is in Windows on the PC and I only run the apps on the Pi.
 

cestor

Active Member
Re arduino - you can also put an ethernet shield on an arduino and use that interface instead of serial. Has anyone tried this?
 

tigers

Active Member
It's much harder since wi fi protocol in encypted, and Arduino don't have enough power to do the encrypt/decrypt process.
 

pete_c

Guru
I went to playing with a micro router here and modding it hardware wise to include an RTC / battery with both serial and Ethernet connectivity.  With OpenWRT it just using LUA (which is being utilized today with the Securifi Almond +'s that I play with.).
 
It is a bit slow though running at 400Mhz and it doesn't have much play space.  That and I connected a Zigbee ZIM to my OP2 panel.
 
I am out of ports now unless I do temporary changes and my panel today has a bit of a Frankenstein (stuff is leaking out) look to it.   I did get to a point of connecting on HAI serial port to a Quatech serial server and working on this stuff on my office home desktop which worked for me using the Arduino stuff.
 
Here installed first generation Openhab (~1.7) with the HAI plugin and it worked fine on a Linux base.  I am impressed with it. 
 
Openhab ran better for me on Linux.  I tried to tighten it up for the RPi2 but it was a bit slow for me. 
 
I helped the original Openhab writer some way back.  That said the original plugin author sold his home with the OmniPro2 panel and for a bit didn't do much relating to the second version of OpenHab / HAI.  It would be difficult I guess to test with no hardware.
 
He has posted on the OpenHab forum relating to this and future support. 
 
Basically the installation of OpenHab / HAI is simple and it just relates to unzipping the Openhab directory to the /opt directory, installing your specific plugin (HAI) and running it.
 
I will install it in the next few days on one RPi2 and document it here.  It really only takes 10 minutes to do.  You can edit files via SSH and nano or remotely using Webmin or via Wintel using WinSCP.  I am Pete on the OpenHab forum and will document it there too doing a copy and paste from here.
 
As JonW mentions above you can go the dot net  / mono way to do this.  I utilize Homeseer today on a RPi2 with a plugin (beta still) that communicates just fine with the OmniPro2 panel.  It is fast here and I am only testing it on the RPi2 versus another running set up I have using Ubuntu 14.04 64 bit (more of a LAMP server there).
 

cestor

Active Member
So I did the polling and after lots of troubleshooting it is all working - one thing to be aware of is that when you send something down the serial port, it is non-blocking and the program will continue executing, sending the bits using interrupts. So in the send_hai function you need to do a Serial1.flush() so that execution halts until everything has been sent. 
 
Top