Spidersbox
Posts: 8
Joined: Thu Sep 10, 2015 5:33 pm

Re: Developing Linux SW for relay cards

Tue Oct 06, 2015 4:40 am

I made a small update to my project.
relay numbering started with he first card found, so if you switch the usb plugs, relay number 1 isn't always relay number one.
Very important if you have your relay cards wired up to things.

I added a simple sort routine that sorts by just the first character of the card ID
now relay #1 stays relay #1 even if you move the cables around - providing you don't have two cards that start with the same first character :)

mikeh49
Posts: 4
Joined: Wed Oct 07, 2015 5:03 pm

Re: Developing Linux SW for relay cards

Wed Oct 07, 2015 7:40 pm

I'm trying to use an USB relay on a PogoPlug Pro on Debian. I've built and installed the hidapi libraries for usb and built and installed ondrej's crelay and spidersbox's relay. Unfortunately, problems with both.

Crelay identifies the relay card but does not return status or appear to control the relay, see below:

Code: Select all

root@PogoPro:~# crelay -i
Detected relay card type is HID API compatible relay card (on 0001:0003:00, 1 channels)
root@PogoPro:~# crelay -i 1
Detected relay card type is HID API compatible relay card (on 0001:0003:00, 1 channels)
Never mind, I got it working. I did not understand the command line format, i.e., don't use the -i parameter when controlling the relay. Works fine with crelay 1 OFF or crelay 1 ON.

I get the Detected relay string regardless of what is on the command line. I can provide more info on the build and install process if needed.

For relay, I get a segmentation fault:

Code: Select all

root@PogoPro:~# relay
Segmentation fault
I can use whichever one of these I get working (I think), so whoever can help would be appreciated.

Thanks.

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Thu Oct 08, 2015 7:31 am

mikeh49 wrote:I'm trying to use an USB relay on a PogoPlug Pro on Debian.
...
Never mind, I got it working. I did not understand the command line format, i.e., don't use the -i parameter when controlling the relay. Works fine with crelay 1 OFF or crelay 1 ON.
Yes, the command line format is:

Code: Select all

crelay -i | [<relay number>] [ON|OFF]
The "|" sign means the "-i" parameter to the left and the other parameters on the right are mutually exclusive. I should probably add some more help text to explain that better. But I'm glad you worked that out anyway and the program is working fine for you. Interesting to know that it runs smooth also on the PogoPlug and not only on the RPi.
Thanks for the feedback
Ondrej
The Telegea.org project: https://www.telegea.org

mikeh49
Posts: 4
Joined: Wed Oct 07, 2015 5:03 pm

Re: Developing Linux SW for relay cards

Thu Oct 08, 2015 3:08 pm

Thanks for the reply. I'm not up to date on the syntax of command lines.

I plan to use the PogoPlug for a simple home automation task. This is the Pogo V3 700 Mhz dual core with 128MB memory, otherwise known as the Oxnas SoC. The kernel is 4.1 from Bohdi on the Jeff Doozan Debian forum which includes the HID features.

I built hidapi and crelay on the Pogo. Mostly went OK. The hidapi build had problems finding the udev library but eventually worked. Seems to be a somewhat common problem. I built crelay without the Sainsmart and Conrad drivers and the make went fine. The make install complained about the missing Sainsmart and Conrad features, but built the binary anyway. Works fine with the single relay USB card I have.

Thanks for the nice program. Now to try the daemon version. I'm pretty new at this, so it goes pretty slow.

Spidersbox
Posts: 8
Joined: Thu Sep 10, 2015 5:33 pm

Re: Developing Linux SW for relay cards

Mon Oct 12, 2015 9:06 pm

mikeh49 wrote:I'm trying to use an USB relay on a PogoPlug Pro on Debian. I've built and installed the hidapi libraries for usb and built and installed ondrej's crelay and spidersbox's relay. Unfortunately, problems with both.

For relay, I get a segmentation fault:

Code: Select all

root@PogoPro:~# relay
Segmentation fault
I can use whichever one of these I get working (I think), so whoever can help would be appreciated.

Thanks.
segmentation fault usually happens when a program tries to write to a read only memory address, a nonexistent one, or to an address used by the system. I tested (and am using) relay on ubuntu on a pc and on a banana-PI and haven't had that error, so I can't help you much here. I might just have to setup a Debian box and see what happens.

mikeh49
Posts: 4
Joined: Wed Oct 07, 2015 5:03 pm

Re: Developing Linux SW for relay cards

Sun Oct 18, 2015 5:55 pm

Thanks for the info. I got crelay working so not a problem for my current project. Might be nice to access the additional features in your program on a plug computer with Debian.

Spidersbox
Posts: 8
Joined: Thu Sep 10, 2015 5:33 pm

Re: Developing Linux SW for relay cards

Sun Oct 18, 2015 6:21 pm

mikeh49 wrote:Thanks for the info. I got crelay working so not a problem for my current project. Might be nice to access the additional features in your program on a plug computer with Debian.
It would be nice to know what went wrong :)
This project is my first on linux, so I'm sure I missed something. One of the reasons I hadn't planned on putting it out there for the public - but what the heck.

harwoodr
Posts: 19
Joined: Sat Jun 02, 2012 6:20 am
Location: Colchester. Essex.UK

Re: Developing Linux SW for relay cards

Mon Oct 19, 2015 4:48 pm

I found a good suite of perl programs that allow full control of rapids 'Blueberry multi controller board' which has 3 relays (mains rated) adc, logic level converter, power supply etc.gsm module onboard, perl is my weapon of choice because its so accomodating and modules exist for just about every scenario, but i still have to program my 868 MHz radio board (atmega328p) with C so i wish there was a common lanuage that would bridge both camps
you are only as good as you strive to be ! no pain -no gain

fritzfrosch
Posts: 1
Joined: Sat Mar 05, 2016 11:53 am

Re: Developing Linux SW for relay cards

Sat Mar 05, 2016 11:56 am

Thanks Ondrej,

crelay works like a charm. Although it was the first time ever I had to compile C :-)

Cheers,
Frosch

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Mon Apr 11, 2016 3:22 pm

Hi all,

I just released the new version 0.10 of crelay. Get it on GitHub as usual:
https://github.com/ondrej1024/crelay/releases/tag/V0.10

New is the support for the SainSmart 16 Channel USB HID Control Relay Module (thanks to Kevin Hilman).

Next to come is the multiple cards support. That means you can connect more than one card of the same or different type at the same time and control all of the available relays on these cards. If you are interested you can already test the command line multiple card control by building crelay from its multiplecards_experimental branch.
I would be greateful for your feedback.
The Telegea.org project: https://www.telegea.org

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Tue Aug 30, 2016 7:48 am

Hi all,

while there has been no progress on multiple cards support (lack of time) here is a bugfix release of crelay:
https://github.com/ondrej1024/crelay/re ... ag/V0.10.1

As always: feedbacks welcome.
Ondrej
The Telegea.org project: https://www.telegea.org

Vox45
Posts: 1
Joined: Wed Oct 05, 2016 2:00 pm

Re: Developing Linux SW for relay cards

Wed Oct 05, 2016 2:18 pm

Hello

I've been looking for a solution to manage my GPIO relay card with a RPI3. I was able to install your software and connect to the web interface. There is not a lot of info beside how to install, not much on configuration.

(1) I copied the crelay.conf in /etc/ but when I run

crelay -d [<relay1_label> [<relay2_label> [<relay3_label> [<relay4_label>]]]]

I get

:~$ -bash: relay1_label: No such file or directory

Could you give a sample of how I need to modify the conf file to get it to work with a RPI and GPIO ? I am a newcomer to linux so not used to interpreting the conf file ...

(2) I am only using the GPIO so can I remove all the other drivers like this make [DRV_CONRAD=n] [DRV_SAINSMART=n] [DRV_HIDAPI=n]

I made a mistake of launching make without parameters and by doing so, from what I understand, I included ALL the drivers... I thought I was doing the opposite ;)

mutley
Posts: 61
Joined: Sat Jan 02, 2016 8:06 pm

Re: Developing Linux SW for relay cards

Wed Oct 05, 2016 10:58 pm

Vox45 wrote:Hello

I've been looking for a solution to manage my GPIO relay card with a RPI3.
I don't think it will, I took a very quick look at the source code and it looks like it will only work with USB relay boards, not GPIO.

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Thu Oct 06, 2016 11:37 am

Vox45 wrote:Hello
Hi Vox45,
if you don't use any USB relay cards you can exclude their drivers from the build as follows:

Code: Select all

make DRV_CONRAD=n DRV_SAINSMART=n DRV_HIDAPI=n DRV_SAINSMART16=n 
This will include only the GPIO driver.

But the GPIO driver needs to be configured in the [GPIO drv] section of the config file:

Code: Select all

# GPIO driver parameters
################################################
[GPIO drv]
#num_relays = 8    # Number of GPIOs connected to relays (1 to 8)
#relay1_gpio_pin = 17   # GPIO pin for relay 1 (17 for RPi GPIO0)
#relay2_gpio_pin = 18   # GPIO pin for relay 2 (18 for RPi GPIO1)
#relay3_gpio_pin = 27   # GPIO pin for relay 3 (27 for RPi GPIO2)
#relay4_gpio_pin = 22   # GPIO pin for relay 4 (22 for RPi GPIO3)
#relay5_gpio_pin = 23   # GPIO pin for relay 5 (23 for RPi GPIO4)
#relay6_gpio_pin = 24   # GPIO pin for relay 6 (24 for RPi GPIO5)
#relay7_gpio_pin = 25   # GPIO pin for relay 7 (25 for RPi GPIO6)
#relay8_gpio_pin = 4    # GPIO pin for relay 8 ( 4 for RPi GPIO7)
Uncomment (remove the # sign) from the lines which specify your relays and change the pin numbers as needed.
Don't forget to uncomment and specify the number of relays you have (num_relays).

If you want to assign labels to the relays you can do this in the [HTTP server] section of the config file.

Place the config file crelay.conf in /etc/ and start crelay in daemon mode:

Code: Select all

sudo crelay -d 
Now you can control your GpIO relays via the crelay web interface.
The Telegea.org project: https://www.telegea.org

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Thu Oct 06, 2016 11:41 am

mutley wrote:
Vox45 wrote:Hello

I've been looking for a solution to manage my GPIO relay card with a RPI3.
I don't think it will, I took a very quick look at the source code and it looks like it will only work with USB relay boards, not GPIO.
Then you should have another look ;)
The source code file relay_drv_gpio.c implements (as the name suggests) the GPIO driver for crelay.
The Telegea.org project: https://www.telegea.org

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Sat Dec 31, 2016 9:38 am

I wanted to get this out before the end of the year, so here it goes: the most requested feature, multiple cards support has just been officially released with version 0.11of crelay.

Simultaneous control of multiple cards is supported from the command line only. WebGui support will be added in the next release.

Please test and report any issues you might have.

Ondrej
The Telegea.org project: https://www.telegea.org

gordon77
Posts: 5283
Joined: Sun Aug 05, 2012 3:12 pm

Re: Developing Linux SW for relay cards

Sun Jul 01, 2018 10:40 am

on the hope that ondrej1024 is still around on here..

I have installed crelay and it detects the sainsmart usb relay card but I can't control it, can you advise what's wrong ?

Thanks

Code: Select all

pi@raspberrypi:~/crelay/src $ sudo crelay -i

Detected relay cards:
  #1	Sainsmart USB 4/8-channel relay card (serial A4002EIm)
  
pi@raspberrypi:~/crelay/src $ sudo crelay [1] [ON]
unable to continue, not an R-type chip
No compatible device detected.

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Mon Jul 02, 2018 10:43 am

@gordon77:
Correct syntax for switching the first relay on is

Code: Select all

sudo crelay 1 ON
(without brackets). Does this work?

Are you able to read the relay state with

Code: Select all

sudo crelay 1 

Ondrej
The Telegea.org project: https://www.telegea.org

gordon77
Posts: 5283
Joined: Sun Aug 05, 2012 3:12 pm

Re: Developing Linux SW for relay cards

Mon Jul 02, 2018 5:05 pm

Still doesn't work, same with sudo...

Code: Select all

pi@raspberrypi:~ $ crelay 1 ON
unable to continue, not an R-type chip
No compatible device detected.

Warning: this program is currently not running with root privileges !
Therefore it might not be able to access your relay card communication port.
Consider invoking the program from the root account or use "sudo ..."

Code: Select all

pi@raspberrypi:~ $ crelay 1 
unable to continue, not an R-type chip
No compatible device detected.

Warning: this program is currently not running with root privileges !
Therefore it might not be able to access your relay card communication port.
Consider invoking the program from the root account or use "sudo ..."

Code: Select all

pi@raspberrypi:~ $ sudo crelay 1 ON
unable to continue, not an R-type chip
No compatible device detected.

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Tue Jul 03, 2018 8:39 am

I think this is actually in incompatibility, as the error message suggests. In the Sainsmart driver source code relay_drv_sainsmart.c there is a check for the R-type of the FTDI chip. You could try to comment out these lines and check if it works:

Code: Select all

   /* Check if this is an R type chip */
   if (ftdi->type != TYPE_R)
   {
      fprintf(stderr, "unable to continue, not an R-type chip\n");
      ftdi_free(ftdi);
      return -1;
   }
The Telegea.org project: https://www.telegea.org

gordon77
Posts: 5283
Joined: Sun Aug 05, 2012 3:12 pm

Re: Developing Linux SW for relay cards

Tue Jul 03, 2018 2:32 pm

I am bit confused..

I have edited /home/pi/crelay/scr/relay_drv_sainsmart.c

Code: Select all

   /* Check if this is an R type chip */
   /*if (ftdi->type != TYPE_R)
   /*{
   /*   fprintf(stderr, "unable to continue, not an R-type chip\n");
   /*   ftdi_free(ftdi);
   /*   return -1;
   /*}
BUT the same TYPE_R error still occurs !!, is this the correct file or have I editted it wrong ?

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Tue Jul 03, 2018 3:05 pm

Yes, the source file is correct but maybe you are still executing the old binary :?
Also it looks you never closed the comment with */
The Telegea.org project: https://www.telegea.org

gordon77
Posts: 5283
Joined: Sun Aug 05, 2012 3:12 pm

Re: Developing Linux SW for relay cards

Wed Jul 04, 2018 10:53 am

Thankyou :D

Now works and I can control the relays !

(I just needed a 'sudo make install ' again)

Gordon.

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Wed Jul 04, 2018 10:57 am

Good to hear. I should probably disable the check for the R-TYPE in the next release as it seems to be useless and only causes trouble with certain relay cards.
Cheers, Ondrej
The Telegea.org project: https://www.telegea.org

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Developing Linux SW for relay cards

Mon Jan 14, 2019 10:29 pm

The new release 0.14 of crelay is out.

Multiple relay card support has been improved by adding the possibility to specify the serial number in the API request. Also the WebGUI was updated with a more modern look and feel.

https://github.com/ondrej1024/crelay/releases

Ondrej
The Telegea.org project: https://www.telegea.org

Return to “Automation, sensing and robotics”