Explain how to use low level C API

Discussions about RaZberry - Z-Wave board for Raspberry computer
Lorenzo
Posts: 8
Joined: 05 Oct 2014 09:28

Explain how to use low level C API

Post by Lorenzo »

Hello,
until now, I was using Python to interface with zway, through http ... but, it's too slow and not efficient
I would like to use C. I've my Razberry with gcc. As I'm not an expert at all, would you mind to explain exactly how to compile and run the z-way-test project available at http://razberry.z-wave.me/index.php?id=30
Many thanks in advance,
Lorenzo
misha_shch
Posts: 7
Joined: 07 Oct 2015 11:15

Re: Explain how to use low level C API

Post by misha_shch »

Hi Lorenzo,

I'm on the same way as you are, so here are my tips that I've collected digging this topic:
1. First of all you should install and configure NetBeans (there are some other IDEs but NetBeans is recommended one). You will find detailed instructions on it with the following link
http://www.raspberry-projects.com/pi/ca ... ns-windows

2. Create a project with main.c from z-way-test in NetBeans and add ZWay libraries to linker. Again detailed instruction is available with already mentioned link. The only thing that was not obviuos for me is that fro example libzway.so library must be written as just "zway" in linker switches ("lib" part should be removed from the name). Don't forget to provide the path to these libraries.
Also I found that some other libraries are required to run the application (there in no word about it in documentation). In my case I've added following switches:
-L/usr/lib/libzway/ -lzway -lzcommons -L/usr/lib/arm-linux-gnueabihf/ -lpthread -lxml2 -lz -lm -lcrypto -larchive

3. Put propper device name in initialisation string. In my case it was /dev/ttyAMA0 but not /dev/ttyUSB0.

4. Provide absolute paths to configuration files in zway_init(). By default they are NULL. These are paths to zway server programm subdirectories.

5. Check that original z-way server is not running.

6. After that you should be able to compile and run the application. Ignore SIGILL error message in GDB. Details can be found here
viewtopic.php?f=3422&t=22163

Hopefully this will help. It took me quite a while to get this result. But it was fun and I guess more fun is comming :)

BR,
Mike
Lorenzo
Posts: 8
Joined: 05 Oct 2014 09:28

Re: Explain how to use low level C API

Post by Lorenzo »

Hi Mike,
thanks a lot to share all these details.
I'll invest some time installing and trying NetBeans, and let you know if everything went well ...
BR,
Lorenzo
Lorenzo
Posts: 8
Joined: 05 Oct 2014 09:28

Re: Explain how to use low level C API

Post by Lorenzo »

Hi Mike,
I've installed and started NETBEANS, connected to my Raspberry, without too much difficulties for a simple program, thanks to your tips. I also recommend NETBEANS, I'm enthusiastic !

Now, with the z-way-test project (http://razberry.z-wave.me/index.php?id=30), I'm encounting several things :

1) the compilation fails, as ZWayLib.h is not found, even if I add the correct libraries/path to the linker. There is a containment if you put the full path in the main.c (#include "/opt/z-way-server/LibZway/ZwayLib.h")

2) the switch '-larchive' is needed, but the compiler doesn't find this library on the Raspberry

3) you told me to provide absolute paths to configuration files in zway_init(&zway, ZSTR("/dev/ttyUSB0"), NULL, NULL, NULL, NULL, Debug) : can you detail what to put exactly ?

best regards,
Lorenzo
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Explain how to use low level C API

Post by PoltoS »

1) add -I/opt/z-way-server/LibZway to CFLAGS
2) install libarchive and libarchive-dev via apt-get
3) if NULL is used, paths should be located in current folder. Otherwise replace NULL by "/opt/z-way-server/config" and similar (for ZDDX and translations too)
Lorenzo
Posts: 8
Joined: 05 Oct 2014 09:28

Re: Explain how to use low level C API

Post by Lorenzo »

Thanks a lot.
Now, my NETBEANS environment is working fine, compiling and executing.
I have modified the example under http://razberry.z-wave.me/index.php?id=30, and it's working fine.
Lorenzo
Bergman
Posts: 10
Joined: 17 Feb 2016 16:26

Re: Explain how to use low level C API

Post by Bergman »

Hello, I am trying to follow these steps to use the C API.

"Create a project with main.c from z-way-test in NetBeans and add ZWay libraries to linker. ". Where can I find the ZWay libraries? I try to Google for it but find nothing.

Best regards,
Anton
Lorenzo
Posts: 8
Joined: 05 Oct 2014 09:28

Re: Explain how to use low level C API

Post by Lorenzo »

Hi Anton,
sorry, I should have answered to you soon.
The sentence means that you have to tell the linker where to find the libraries
Right click your project's name > Properties > Build > Linker > In the 'Libraries' section press the '…' button > Add Option… > Other Option > Enter your libraries options
The following list works for me to run the zwave.me example :
-L/opt/z-way-server/libs
-L/usr/lib/libzway/
-L/lib/arm-linux-gnueabihf
-L/usr/lib/arm-linux-gnueabihf/
-lzway -lzcommons
-lpthread
-lxml2
-lcrypto
-larchive
-lwiringPi
Hope it helps, best regards,
Lorenzo
tromper
Posts: 5
Joined: 11 Oct 2017 20:38

Re: Explain how to use low level C API

Post by tromper »

Hello,

How do i add -I/opt/z-way-server/LibZway to CFLAGS?? i have the same problem, it is telling me that the file zwaylib.h can not be found.

Thanks, Tromper
lrfeliciano
Posts: 1
Joined: 26 Mar 2019 05:30

Re: Explain how to use low level C API

Post by lrfeliciano »

Hi guys,

Just new in this things.

I have still problem regarding the NetBeans still looking for the library of zwave, I already follow all the instruction above and still fail to compile on my netbeans.

thanks,
Lorenz
Post Reply