OpenWrt Forum Archive

Topic: OpenWRT router controlling relays via USB

The content of this topic has been archived on 12 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello,

I have bought a USB relay controller in ebay and it works nice in windows PC.

It seems someone have put it working in raspberry PI and generic linux, so I was wondering if it could also be done for OpenWRT.

It seems it needs some libraries: hidapi and hidapi-devel

Any idea if this could ever work in OpenWrt?

Cheers,
Jabss

(Last edited by jabss on 18 May 2014, 23:52)

Don't know if this would help, but packages include kmod-hid and kmod-usb-hid.

In that case it should be just a matter of compiling the USBRelay code.

# gcc -o usbrelay usbrelay.c -lhidapi-hidraw

Since its very small, can't I compile it in the router? Looked in the available packages and couldn't find gcc...

Should it be other complier?

Thanks,
Jabss

From looking at package/feeds/packages/gcc/Makefile, gcc is only built as a package for x86 architectures. I think you will have to cross compile. Set up buildroot, then run make menuconfig, select your platform and profile, then run:

make tools/install && make toolchain/install

Which will build and set up the toolchain for your platform, without wasting time building an image you aren't going to use. Then you can follow the cross compile instructions.

Hello,

Unfortunately my knowledge compiling is somewhat limited  and I'm having some difficulties cross-compiling this.
I though since I'm cross-compiling in other machine, why shouldn't I do it directly for the code I need (instead of cross-compiling  gcc, put it in the router and then compile the code I need...).

I have built the buildroot environment and prepared the tools and toolchain. Just gave a try.

Preparing Environment variables:

PATH=$PATH:/mnt/storage/usbrelay-openwrt/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/
export PATH
STAGING_DIR=/mnt/storage/usbrelay-openwrt/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2
export STAGING_DIR

According to the usbrelay site, the compiling should eb something like:

# gcc -o usbrelay usbrelay.c -lhidapi-hidraw

so I tryied

/mnt/storage/usbrelay-openwrt/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-gcc -o usbrelay usbrelay.c -lhidapi-hidraw
/mnt/storage/usbrelay-openwrt/openwrt/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.8.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lhidapi-hidraw
collect2: error: ld returned 1 exit status

OK, it seems the HIDAPI library is missing so I git-cloned it from https://github.com/signal11/hidapi and tried to build it. However it has its own way of building:

./bootstrap
    ./configure
    make
    make install     <----- as root, or using sudo 

I'm lost... How can I cross compile this?

Any suggestion?
Thanks
Jabss

Hello again,

Assuming that kmod-hid and kmod-usb-hid meet all the needs of USBRelay (hidapi and hidapi-devel), I assume I don't need hidapi libs to compile the usbrelay code.

Having this in mind, how can I (cross)-compile it?

I'm sorry to ask basic questions, but I've seen the wikis for "building a package" and "porting a package" and I admit it may be too much technical to me... sad

Anyone willing to help?

Thanks,
Jabss

Anyone?

Meanwhile I was able to compile the USBRelay2 for Raspberry PI, but I'm still far from having it working in OpenWRT.

Cheers,
Jabss

I'm not good in C

Do you have any documentation about that device ?

There is a chance that this device can be controlled using simple Python script

Sincerely
-bino-

I"d really like to get this relay working on my openwrt router as well.. Were you able to get this working?

I've cross compiled usbrelay.c for ar71xx hardware it works on my tl1043 (v1.1) with that red 2 channel usb relay off ebay, should work with 4 channel I guess.
libusb should be installed and as for kernel modules , I don't really know which are needed.


usbrelay

(Last edited by dnkn on 20 Oct 2014, 22:16)

makro wrote:

From looking at package/feeds/packages/gcc/Makefile, gcc is only built as a package for x86 architectures.

It looks to me that is just a GCC without uClibc and/or libc include headers and libraries files. In other words, source code can only be compiled to a .o object file. Hope someone can prove me wrong. wink

dnkn wrote:

I've cross compiled usbrelay.c for ar71xx hardware it works on my tl1043 (v1.1) with that red 2 channel usb relay off ebay, should work with 4 channel I guess.
libusb should be installed and as for kernel modules , I don't really know which are needed.


usbrelay

Could you share how you did it?

Thanks,
Jabss

Anyone? smile

Hi again,

I have my own, strong and personal principle of not executing code that I don't know, because nobody never knows what it really does. It is a huge security risk!

Its a bit frustrating to have so near the supposed executable that does what is needed, and being unable to try it.

I mean, my OpenWRT router is the door between my Home LAN and the Internet. I don't want to risk having my Home LAN hacked just because I irresponsibly ran some executable that I don't know how it was done...

Don't get me wrong, I'm not saying the executable in the other post is malicious. I'm just saying I don't execute code in my router that I don't know where it comes from. I'm sure we all agree the best security rule is to always suspect from everything and everywhere.

So, since I couldn't get any help compiling the code for USBRelay, I decided to purchase another USB relay device, this one with a serial-over-usb port.
It is still on its way, so I haven't tried it, but I expect to easily control it with a serial console program like minicom. This device in ebay costs around $6 USD with shipping to EU, so its far less that I would spend with the hassle of being attacked in my Home LAN.

The best I can do is to suggest the OpenWRT community to adopt a conscientious  behavior and avoid running code we don't know where it comes from.

Cheers,
Jabss

I simplified the code for the relay into one file. It works under Ubuntu (just run "make").
http://xerostomus.sweb.cz/usbrelay/usb_ … ter_jk.zip
Is there anybody who can cross compile just this one file for OpenWrt?
Thank you for help. :-)

Dear all,
I recently bought an usb relay (ICSE013A) for less than 5 USD on ebay.
This one has a pl2303 usb to serial converter and works fine, the kernel driver is kmod-usb-serial-pl2303.

You can find out more here : http://randomreaper.blogspot.ch/2016/08 … 3a_22.html

The discussion might have continued from here.