RPI2 chatting to OmniPro 2

pete_c

Guru
Started a new post here relating to BobS0327's code to speak to the OmniPro 2 via the RPi2
 
Going baby steps here and have made a couple of changes to the original C that Bob has provided.
 
Note I have linked the starting files here.
 
There are four files zipped and attached.
 
1 - hai.h
2 - hai.c
3 - aes.h
4 - aes.c
 
Goofing around and not touching the original stuff tried:
 
gcc hai.c -o hai
hai.c: In function 'main':
hai.c:40:3: warning: incompatible implicit declaration of built-in function 'printf' [enabled by default]

 
editing the hai.c so that it reads:
 
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>

#include "hai.h"
#include "aes.h"
#include <errno.h>

works such that:

 
 gcc hai.c -o hai
/tmp/ccfKwd09.o: In function `hai_net_send_msg':
hai.c:(.text+0x960): undefined reference to `MakeKey'
hai.c:(.text+0x9a0): undefined reference to `Encrypt'
/tmp/ccfKwd09.o: In function `hai_net_recv_msg':
hai.c:(.text+0xb6c): undefined reference to `MakeKey'
hai.c:(.text+0xbac): undefined reference to `Decrypt'
collect2: ld returned 1 exit status

 
changing the keys in the hai.h file then doing ....
 
gcc hai.c aes.c -o hai
 
complies the file fine.
 
The following code is in the hai.c file.
 
if ((err = omni_command(&id, CMD_ON, 60, 14)) != 0)
        printf("Failed to turn lights on\n");
    else printf("Turned lights on successfully\n");

 
Running the default code should display the type of controller I am using and turn unit 14 on for 60 seconds.
 
Stuck here as I do not see anything when running the code.
 
View attachment hai-aes.zip
 
if ((err = omni_command(&id, CMD_ON, 60, 14)) != 0)
        printf("Failed to turn lights on\n");
    else printf("Turned lights on successfully\n");

 
Running the default code should display the type of controller I am using and turn unit 14 on for 60 seconds.
 
Stuck here as I do not see anything when running the code.
 
Pete,
 
You should see some messages when you execute the binary.  They are either "success" or "failure" messages.
 
For example, if you successfully compiled the code and the IP address and private key were entered correctly, you should see the following  "successful" messages:
 
Controller acknowledges new session
Controller acknowledges secure connection
OMNIPRO2
Turned lights on successfully
Network connection closed
 
If anything failed, the appropriate "failure message will appear.  But one way or another, you should see messages since the app will keep you informed at each step of the process.
 
Please note that the app identified the controller as OMNIPRO2
 
I don't see any problems in the code you posted.  Appears to be the stock code that I initially posted.
 
 
 
 
 
Thank you Bob.
 
Yup trying ...on an RPi2 here.  Is there anything other than the compiler that needs to be installed?
 
root@ICS-Cumulus:/hai-test# ls
aes.c  aes.h  hai  hai.c  hai.exe  hai.h  hello  main.c  old
root@ICS-Cumulus:/hai-test# ./hai

Unable to connect to server
error opening hai network connection

 
Will reconfigure keys for another OPII and try again.
 
 
Also, you're correctly compiling the code as indicated below..
 
yes.
 
Just setting up for test OPII....
 
Trying this one...
 
#define HAI_PORT 1234
#define HAI_IP_ADDRESS "192.168.101.254"

unsigned char private_key[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

int err;
 
Get the same error.
 
Just a thought.  But are you making the IP, private key changes to the hai.h file AND then compiling the code.  All changes to source code etc must be made prior to compiling the code. the hai.h file isn't a configuration file, it's a C header file.  Thus, it needs to be compiled.  It is listed at the top of the hai.c file which causes it to be compiled.
 
Please post the complete error.
 
Here is the top to the hai.h file.
 
#define HAI_PORT 1234
#define HAI_IP_ADDRESS "192.168.101.254"
unsigned char private_key[16] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

int err;

typedef enum {
        /** Message type to request a new session */
        CLIENT_REQUEST_NEW_SESSION = 1,
        /** Message type to acknowledge a new session */
        CONTROLLER_ACKNOWLEDGE_NEW_SESSION = 2,
        /** Message type to request a secure connection */
        CLIENT_REQUEST_SECURE_CONNECTION = 3,
        /** Message type to acknowledge a secure connection */
        CONTROLLER_ACKNOWLEDGE_SECURE_CONNECTION = 4,
        /** Message type to terminate a session */
        CLIENT_SESSION_TERMINATED = 5,
        /** Message type to indicate the controller terminated the session */
        CONTROLLER_SESSION_TERMINATED = 6,
        /** Message type to indicate an error creating a new session */
        CONTROLLER_CANNOT_START_NEW_SESSION = 7,
#ifdef USE_TCP
        /** Message type to indicate an Omni-Link II message */
        OMNI_LINK_MESSAGE = 32
#else
        /** Message type to indicate an Omni-Link message */
        OMNI_LINK_MESSAGE = 16,
#endif
} hai_msg_type;

 
/home/pete/Desktop/hai-test# gcc aes.c hai.c -o hai
 
no errors at this point.
 
/home/pete/Desktop/hai-test# ./hai
Unable to connect to server
error opening hai network connection
 
takes a while to get the error messages.
 
Pete,
 
My bad.  I think I found the problem.  In the code that I initially posted, I had hard coded the local IP address of my controller.  This has to be changed to the #define statement
 
Check line # 122 in the HAI.C file.  it looks as follows:
 

bzero((char *) &id->omni, sizeof(id->omni));
    id->omni.sin_family = AF_INET;
    id->omni.sin_addr.s_addr = inet_addr("192.168.1.250");
    id->omni.sin_port = htons(HAI_PORT);
 
Change the "192.168.1.250" to HAI_IP_ADDRESS.  Don't put any parenthesis around it.  Compile code and run it.
 
The HAI_IP_ADDRESS should be defined in the HAI.H file with the IP address of your controller.
 
 
 
Thank you Bob.  Will update OP zip file.
 
Works great.
 
hai-test# ./hai
Controller acknowledges new session
Controller acknowledges secure connection
OMNIPRO2
Turned lights on successfully
Network connection closed

 
 
Back
Top