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

pete_c

Guru
Yes; here like the weather stuff and related. 
 
Once you have been bitten by the automation bug; it'll be a continous automation project that just blends one project to another and another.
 

pete_c

Guru
Got the Arduino today and loaded up the software. 
 
Configuring the Arduino serial TTL stuff out to a serial port.
 
This is my first time playing with an arduino.  Plug n play so far.
 
arduinouno.jpgusbttl.jpgrs232-ttl.jpg
 
Found a picture of the Arduino Nano inside of the TP-Link microuter this morning.
 
arduinonanotplink.jpg
 
Here noticed that the RX/TX TTL pins share the micro USB connection on the Nano.  Basically then I guess I would just power the Nano via the microrouter and use only the RX/TX pins for my serial connection.
 
 
 

ubergeek

Member
Tigers, first let me say thanks for suggesting openHAB and MQTT when I came here a year ago looking for info on controlling LED light strips via OPII and possibly the arduino. I would say I have made great strides in understanding since then and have fully embraced openHAB as my top level controller in a few installations including my house with the OPII. Here is a link to a write up on the lights I got working last year that I thought I would share.
 
Back to this topic now...I had been wondering recently about utilizing an old OmniLT I have on the shelf. I have dismissed in the past due to lack of ethernet but your code certainly could be one method of extending the functionality, but if there was a way to link to an openHAB instance it would really open the doors for a very "cheap" capable controller with the issue of limited connectivity made less significant. I was thinking about using the serial binding possibly or MQTT with your arduino code.
 
Will this code work for an OmniLT ? 
 

tigers

Active Member
As I see from the HAI docs the omni lt has a serial port on board and it supports the omni link protocol. Everything should be exactly the same so the code should work as it is with no modifications. It may lack certain advanced commands of the protocol, but I didn't use any of them.
Go ahead and try!
 

pete_c

Guru
Thank you tigers for providing the code.
 
Just made and tested the correct serial cable using your drawing.  I had the correct HAI connector that I am already using for something else so decided just to make another on.
 
You mentioned that the Arduino Nano only has one UART with one serial port.  So here going to give a try using the software serial stuff and a couple of pins over to the second TTL to serial that I purchased.
 
I am guessing that I just put this code on top of your code for my software serial port eh?
 
Do you think that it will slow down the Nano too much with the software serial port add?
 
Going to try with A6, A7 (20,21)
 
SoftwareSerial mySerial(20, 21); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(96600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

 
Connected the serial port to a serial ethernet server to test on the network.
 

tigers

Active Member
The declaration part is OK (and you can use A6 and A7 directly in the code to name the pins, it' more easy to understand), but I don't get what you want to do with the loop() part. I guess you just want to echo the messages to see if it works, but why echo back to the same port? I did something similar as a test echoing the incoming message on one port out to the other.

Also, I won't directly echo a serial message without using a buffer (not sure it'd actually work as you coded it). There's plenty of examples on how to do that.
 
Note an error on serial.begin that should be 9600 and don't try to push too hard on software serial. 9600 is fine, 11500 would be bad.
 

pete_c

Guru
Thank you Davide.
 
I just uploaded the Arduino programming example of the software I got to test its functionality.  Worked first
time.
 
serial2testing.jpg
 
I have no idea what I am doing yet.
 
I also modded your code a bit to working with the Nano and tested that piece.
 
just changed all references to serial1 to serial ==>
  • Serial1.write(HAI_send); //to HAI
    [*]Serial.write(HAI_send); //to HAI

Not really sure if I did that right though. 
 
nano.jpg
 
I just plugged it into the OpenWrt router and just play a bit with minicom.
 
Found a little issue unrelated to the Nano endeavor.    I had set the new microrouter next to my Ooma VOIP box and had utilized the USB port to provide power to it.
 
Well the Ooma box created a device out of the microrouter called the Ooma Linx.  For whatever reason it voip worked fine but it changed (?) my base on the microrouter such that I have to redo it.
 
It also changed my configuration on the Ooma router using the microuter (even though it continued to work fine); such that I had to reconfigure the Ooma router.  It is not being used as a firewall today and it just internal to the firewall.
 
but why echo back to the same port? I did something similar as a test echoing the incoming message on one port out to the other.
 
That is what I am looking at doing.  Later on I want to connect the Nano serial port TTL directly to the Openwrt TTL and chat to the Nano connected to the OPII serial port.
 
So I got two variables; one called serial and another called myserial.  Is that the way they should be referenced?
 
So I define the software serial port on the top of your code then change your code such that it talks to the softwareserial port and I can get to it via the UART serial port. 
 
I have gone back to using my desktop with the virtual serial port connection to the OPII (it is two levels down and easier to play with remotely for the time bean).
 

#include <SoftwareSerial.h>

SoftwareSerial mySerial(20, 21); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Software Serial port 2 testing!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world Serial port 2 testing?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

 
So I would put the above here?

//======MAIN PROGRAM==================================
    void setup() {                
    // Turn the Serial Protocol ON
      Serial.begin(9600); //for debug
      Serial1.begin(9600); //for communications with HAI panel
      
      while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only
      }
     
#include <SoftwareSerial.h>

SoftwareSerial mySerial(20, 21); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

      delay(2000);

z
 

BobS0327

Active Member
ubergeek said:
I have been watching this thread for months hoping someone would take this a bit further...I think it would be HUGE to get the Arduinos communicating via ethernet vs. serial! I know it is more work with the encryption but please if anyone with the ability is listening, help get this started! With ethernet, we could drive many arduinos controlling many things from coffeemakers to LED pwm, etc.
 
This would really help get the "Internet Of Things" tied in with a panel that is the heart of our homes...
 
Perhaps it would be easier to script through HailkuHelper instead to communicate with Arduino? I really wish I was a little stronger on the programming end...oh the possibilities! I guess I can dream....
 
Well, the Arduino is challenging to work with.  First of all, the sketches only work with a limited subset of the C programming language.  Secondly, working with a large program with the limited memory capacity of a Arduino Mega AT 2560 is extremely challenging.  Thirdly, trying to compile a large native C application on an Arduino is just about impossible because of the previously mentioned memory constraints.  Not to mention that there are no native C libraries such as the networking library installed on the Arduino. Lastly, the Rijndael (AES) encrption has proven to be exceptionally challenging to implement on the Arduino.
 
With all that said, I decided to port the four Windows files that I previously posted as a POC example for accessing the OP II controller to Raspberry Pi 2 B+ with the Raspian OS installed.  The four files have been successfully compiled with the gcc compiler and executed on the RP2.
 
So, if anyone is interested in the RPI 2 TCP/IP flavor, please PM me.   I will send you the four files. The files are just too large to post on the forum.
 

BobS0327

Active Member
If you're frustrated using Arduino 1.6.6 IDE for developing large projects, then check out this Visual Studio extension... http://www.visualmicro.com/page/Arduino-Visual-Studio-Downloads.aspx
 
I've just started using this extension with VS 2015 and so far it appears to be working without any issues.  Using the basic Arduino IDE was just a lesson in futility for me. Give the extension a try for those large projects.  I think you'll like it.
 

pete_c

Guru
Thank you Bob.
 
I have never played with an Arduino before.  I have though played a bit with the RPi's.
 

BobS0327

Active Member
Pete,
 
FYI
 
Just an update on the use of the Visual Micro extension with VS2015.  I just realized I was using the FREE version.  The free version doesn't have the features that I need.  For instance, it doesn't have the ability to set a breakpoint, single step thru code or to watch a variable.  These are debugging features that I would need to determine how to build the packets being sent to the controller.  A malformed packet sent to the controller will cause it to do nothing.   Also, the serial monitor of the Arduino doesn't do me much good.  It outputs everything in text mode which makes everything look like jibberish.
 
Unfortunately, these debugging features are only found in the personal PAID version.  Not sure I want to buy the personal version just to convert the Omni code to Arduino.
 

tigers

Active Member
Sorry if I'm late to the topic, but I think some things should be clarified.
1. You can't compare an arduino with a raspberry pi: one is a simple chip, the other a much much powerful, complex and expensive system. You can still do wonderful things with an arduino, in a rock solid stable environment once you have properly setup and debugged everything. Of course it may feel limited for somebody but I find it perfect for the job. It's also a nice mixture of easyness of use and powerful capabilities. If you tried to program some other microchip you should know what I mean...
2. I don't see the huge limit in not having the TCP/IP connection: you can have the arduino connected to your lan and access it via your wi fi or cabled lan while it talks to the OPII via serial. What would the TCP do that the "normal" arduino can't?
3. If you send a wrong message to the OPII you DO get a response in the form of an acknowledge not OK message in return so you can debug the connection with the arduino serial even if it's text only (I did it myself). Of course it's still much harder than a step by step debug in visual studio, but not that much if we think of the serial communication.
 

BobS0327

Active Member
Tigers,
Wasn't my intention to belittle the Arduino.  I've used the Arduino for another fairly complex project.  This is evidenced by my post in the general automation section on the Arduino Lawn irrigation project.  You're right, just can't compare the two.  It's like comparing apples and oranges. 
2. I don't see the huge limit in not having the TCP/IP connection: you can have the arduino connected to your lan and access it via your wi fi or cabled lan while it talks to the OPII via serial. What would the TCP do that the "normal" arduino can't?
There's absolutely nothing wrong with that configuration.  Few years back, I wrote a commercial app called Fidoh.  This app had one variation where it installed a TCP/IP server on a laptop which was connected serially to a non ethernet enabled controller such as the Omni.  Thus, allowing anyone to remotely connect to any non ethernet enabled controller.  This variation is written entirely in native C. I will be glad to give you  or anyone else all the source code to this variation for whatever use.
3. If you send a wrong message to the OPII you DO get a response in the form of an acknowledge not OK message in return so you can debug the connection with the arduino serial even if it's text only (I did it myself). Of course it's still much harder than a step by step debug in visual studio, but not that much if we think of the serial communication.
Well, again, I think we're comparing apples to oranges.  I believe you're using the serial protocol which is the Omni Link Protocol which is indicated by your using header byte value 0x5A.  Whereas I am using the TCP/IP protocol which is the Omni Link II Protocol.  This is evidenced by my using a header byte 0x21.  In your case , you would either receive an ACKNOWLEDGE message or a NEGATIVE ACKNOWLEDGE message.  In my case, I would either receive an ACKNOWLEDGE or nothing at all.  This only occurs when initially establishing an new open session and the next step when attempting to establish a secure connection.  Once a secure connection is established, I then get either an ACKNOWLEDGE or NEGATIVE_ACKNOWLEDGE
 
 
A quote from the Omni Link II Protocol document...
 
PROTOCOL RULES
If the controller receives a packet that is not a valid Omni-Link II application-level packet (i.e., missing or invalid
“message type”), the controller quietly discards the packet without a reply.
 
I presume the controller does this to prevent an outside hacker from discovering that the controller is at the other end of the link.  If the hacker gets a bad packet response, then the hacker knows (s)he has connected to a device.  Without a response, the hacker would probably assume that nothing is connected at the other end and move onto another target.  In your case, a serial hardwired connection does not pose this problem.
 
i'm trying to listen with arduino one the OMNI2e central by serial port number 3 (velocity 9600, PROLINK).
  • this is the hardware:
313rjoy.jpg

 
the serial cable between omni2 central and the rs232 board has joined only TX, RX and GND wire
 
  • in pc access ther is this command ():
1. OGNI 5 SECONDI
ALLORA INVIA Prova SULLA SERIALE 3
(the central sends every 5 seconds the message prova by serial 3)
  • this is the test arduino uno sketch:
 
#include <SoftwareSerial.h>
SoftwareSerial portOne(2,3);
 
void setup()
{
  Serial.begin(9600);
  portOne.begin(9600);
  Serial.println("Serial Ready!");
}
 
void loop()
{
  portOne.listen();
  while (portOne.available() > 0) {
    Serial.println("test!");
   }
}
 
arduino serial monitor prints only Serial Ready!
So i suppose that arduino can't read the OMNI2e central serial....
 
can you help to find the error?
 

tigers

Active Member
I sent you a private message but I'll start by debugging the hardware part first, even just using the arduino serial monitor: just connect the HAI serial out to a com port on the pc. Then in the arduino ide start the serial monitor after selecting the com port you connected the HAI serial to. Don't worry if there's no arduino connected, the serial messages would come in just fine.
If this test is OK, we'll start to talk about the rest.
 
Top