Control relay via ethernet to tcp/ip

I have a relay board hooked up now using my GPIO pins and wanted to add a 8 channel relay board but use a sainsmart Ethernet controller. It is hooked up to the pins on the relay and is turned on using an http ip address, port and a number to turn it on and off.

Is this possible to do now or can it be added in the future?

Or do I have to connect to relays using gpio pins only?

Can you post a link to the device you are using? If it supports MQTT it will work.

https://www.sainsmart.com/sainsmart-ethernet-control-module-lan-wan-web-server-control-with-rj45-port.html

https://www.sainsmart.com/sainsmart-8-channels-wifi-network-i-o-controller-for-arduino-relay-android-ios.html

Hi Thanks tad.dvor, It is the first link posted on above post but I don’t see anything about MQTT on it anywhere.

Definitely possible, however it will require quite a bit of custom code. Are you using a Pi or Arduino?

Hi,

I am using a pi. It would be awesome to make a call to http work as well as gpio pins. The you can use a wired or wireless relay board and control it.

Joe

So, looking a bit more at the module and knowing you have a Pi that leaves us with the MQTT API. You can do everything in python fairly easily. Here are some ideas for you:

For the sainsmart side of things you will need a web requests library urllib
For the Cayenne side, you will need the MQTT API library

Set up a generic digital output on the dashboard and in the callback in the python code set off a web request for the corresponding relay.

Let me know how you make out with that or if you need any help!

Hi Adam,

So are you saying that on the sainsmart side the urllib? Is that running on the pi or am I setting it up on the sainsmart board?

Joe

You can do all the programming on the Pi in Python. According to what I read you can enable/disable the relays with web requests like:

http://192.168.1.4/30000/00 : Relay-01 OFF
http://192.168.1.4/30000/01 : Relay-01 ON

So you can use the urllib to make the requests and MQTT to communicate with Cayenne.