TristanB
Posts: 4
Joined: Mon Mar 06, 2017 2:41 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Mon Mar 06, 2017 2:49 pm

My question has already been asked in the past, but I am unable to find the answer. So please excuse me for asking again.

I have just set up 'pirelaypro' to work with my google home and IFTTT.
I am using the commands http://your-pi-ip-address/gpio.php?pin=1&status=1 and http://yourpi-ip-address/gpio.php?pin=1&status=0 to switch the relay ON and OFF.

This is fine and after a bit of trial and error is working great.
I now want to control my garage door, which requires a pulse, and not ON or OFF.

So my question is,
What do i need to type into my address bar to get the relay to pulse and not stay on?
Any help would be much appreciated.

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Mon Mar 06, 2017 7:19 pm

TristanB wrote:My question has already been asked in the past, but I am unable to find the answer. So please excuse me for asking again.

I have just set up 'pirelaypro' to work with my google home and IFTTT.
I am using the commands http://your-pi-ip-address/gpio.php?pin=1&status=1 and http://yourpi-ip-address/gpio.php?pin=1&status=0 to switch the relay ON and OFF.

This is fine and after a bit of trial and error is working great.
I now want to control my garage door, which requires a pulse, and not ON or OFF.

So my question is,
What do i need to type into my address bar to get the relay to pulse and not stay on?
Any help would be much appreciated.
Hi there, I've been experimenting with IFTTT too and have found for me the way to do it was this:

If you are using Pin 1 (as in your example) you could try this change your gpio.php file.

Enter the command:

sudo nano /var/www/html/gpio.php

then change your gpio.php file to something like this in the nano editor:

Code: Select all

<!DOCTYPE html>
    <html>
      <body>
         <?php
           $output = shell_exec('gpio mode '.$_GET['pin'].' out');
           $output = shell_exec('gpio write '.$_GET['pin'].' '.$_GET['status']);

           for ($i = 0; $i < 32; $i++){
             $output = shell_exec("gpio read ".$i);
             echo "Relay ".$i.":".$output."<br>";
           }

//if pin 1 is set to 1 then set pin 1 back to 0

//change the 11 to 21 if you want to control pin 2, 31 to control pin 3 etc.. below.
               if ($_GET['pin'].$_GET['status'] = "11") {
//change the 1 0 to 2 0 if you want to control pin 2, 3 0 to control pin 3 etc.. below
                $output = shell_exec('gpio write 1 0');
            }
         ?>
      </body>
    </html>
Exit Nano editor and save changes to your file. Then give it a try by going to http://your-pi-ip-address/gpio.php?pin=1&status=1 in your browser. Pin 1 should then pulse on then off.

It worked for me just now when I tried it on my PiZero. If you find it pulses twice when you open the app and switch it, then you have your active high/active low settings the wrong way around so check that in the relay settings.
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

TristanB
Posts: 4
Joined: Mon Mar 06, 2017 2:41 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Mon Mar 06, 2017 8:58 pm

Awesome. Thank you so much.

I was kind of hoping there was a simple HTTP code I could type in that would do what I needed. But following your instructions worked a treat and has taught me a little more about modifying code.

Thanks again for your help and such a prompt reply.

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Mar 07, 2017 8:39 am

No problem, happy to help where I can. Glad you got it working and learnt something new too. :)
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

TristanB
Posts: 4
Joined: Mon Mar 06, 2017 2:41 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Mar 07, 2017 6:25 pm

Sorry to ask a question again so soon.

The relay and door are working fine. But.
The relay appears to be on all the time. (except on first power up when it's in a floating state)
When triggered from the app, it goes off and then back on.
This pulse is fine for operating the door, but I have an additional normally open push button mounted in the garage, for when my phone is not to hand. The PB is wired is parallel with the normally open contacts on the relay. Because the relay is on all the time, this push button no longer works. I have followed what you said with regards to active high and active low and this has stopped the double trigger like you said it would.
I don't want to use normally closed contacts, because I believe this will cause the door to open after a power cut. Not a good idea.
Any suggestions to make the relay turn on and off. and not off and on ?
I hope that makes sense.
Tristan

jazzler
Posts: 31
Joined: Mon Nov 04, 2013 7:43 am

Re: Control Relay Switches via Android using a Raspberry Pi

Wed Mar 08, 2017 8:39 pm

TristanB wrote:Sorry to ask a question again so soon.

The relay and door are working fine. But.
The relay appears to be on all the time. (except on first power up when it's in a floating state)
When triggered from the app, it goes off and then back on.
This pulse is fine for operating the door, but I have an additional normally open push button mounted in the garage, for when my phone is not to hand. The PB is wired is parallel with the normally open contacts on the relay. Because the relay is on all the time, this push button no longer works. I have followed what you said with regards to active high and active low and this has stopped the double trigger like you said it would.
I don't want to use normally closed contacts, because I believe this will cause the door to open after a power cut. Not a good idea.
Any suggestions to make the relay turn on and off. and not off and on ?
I hope that makes sense.
Tristan
Hi Tristan

I don't have a chance to try it myself just now, but it sounds like you just need to switch around your active high/low setting in the gpio.php file. You may then also need to change the active high/low setting again in the relay settings in PiRelay app to match it to stop you getting the double pulse again too.

Can you give this a try and let me know if it works for you:

Code: Select all

<!DOCTYPE html>
    <html>
      <body>
         <?php
           $output = shell_exec('gpio mode '.$_GET['pin'].' out');
           $output = shell_exec('gpio write '.$_GET['pin'].' '.$_GET['status']);

           for ($i = 0; $i < 32; $i++){
             $output = shell_exec("gpio read ".$i);
             echo "Relay ".$i.":".$output."<br>";
           }

//if pin 1 is set to 0 then set pin 1 back to 1

//change the 10 to 20 if you want to control pin 2, 30 to control pin 3 etc.. below.
               if ($_GET['pin'].$_GET['status'] = "10") {
//change the 1 1 to 2 1 if you want to control pin 2, 3 1 to control pin 3 etc.. below
                $output = shell_exec('gpio write 1 1');
            }
         ?>
      </body>
    </html>
PiRelay Project : http://bit.ly/pirelay
PiRelay Play Store App : http://bit.ly/PiRelayApp

TristanB
Posts: 4
Joined: Mon Mar 06, 2017 2:41 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Thu Mar 09, 2017 11:20 pm

Only managed to try it quickly tonight. But it appears to do exactly what I want. Thank you so much. When I have more time I'll try it on the garage door. I'll also sit down with the three PHP files and see if I can work out what's going on and how they differ from each other.

Thanks again for helping me out with this.
Tristan

RichHaynes
Posts: 44
Joined: Sat Jul 16, 2016 12:23 pm
Location: Stoke-On-Trent

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Mar 14, 2017 7:26 pm

Hi jazzler,

Straight off, I like your app and what it allows users to do :) I have a web interface to my home automation but I have always wanted to build an app for it!
jazzler wrote:Hi All

Sorry I've been quiet for so long, lots of changes in my life over the past couple of years meant that I haven't had time to work on developing this for a while. I wont have time to answer everyone's questions but will try to drop in from time to time help where I can.

At this point in time I don't have an android phone to test and develop on. I'm working on that and saving to get an android phone soon, at which time I plan to pick up the development of this again to improve it.

Great to see so many people using the app, and initially there are a few things I want to address:

Security - Those who want to make their Pi accessible from outside their network and are concerned about security, my advise is to setup a VPN (Perhaps setup open vpn on your Pi) and use that instead of making Apache on your Pi externally accessible. That's what I do when i need to access my Pi and it works great.

Multi Pi Support - I intend to start developing the app again once I get myself an android phone, when I do I plan to add support for controlling multiple Pi's.

Development Timescales - Please bare with me, I cannot commit to any development timescales for new features as it will rely on 1, me getting an android phone and 2, me having free time to spend after work, in evenings and weekends to develop and test new functionality. Please do not message me asking when new functionality will be added or when to expect updates.

App Testers - If anyone is interested in being a tester and running a dev build of the app to help me test and iron out any bugs that come out of the new functionality, please PM me. There will inevitably be bugs in the dev version that need finding and fixing, so please do not request to become a tester if you cannot deal with this. You have been warned...

Support for more than 8 relays - I originally limited this to 8 relays for 2 reasons, 1 - a typical relay board available at the time of developing it had 8 relays or less. 2 - I was aware that like me many people would be powering their relay board directly from the Pi and I was concerned that if I developed the app to allow people to use more than 8 relays, the power drain from the relay board on the Pi might cause issues or damage which I did not want to be blamed for. That said, there appears to be a great demand for this so I plan to include support for any/all available GPIO pins. I ask that those who intend to use this feature please consider powering your relay board directly from its own power source and not from the Pi iteself. I do not accept any responsibility for any damage or harm you cause using PiRelay, so please use it responsibly and manage your power requirements yourself.

Today I have created a new SD Card Image, based on the latest Raspian Jessie Lite. I have built it on a 2GB SD card and made it available to download from here: http://bit.ly/raspbian-jessie-lite-pirelay. This much smaller package should allow you to make use of PiRelay using smaller capacity SD Cards from 2GB upwards, although I recommend using 4GB or larger (Is it just me or do we all have lots of old low capacity SD cards laying around that would be handy to revive and put to good use?)

Anyway, that's all for now, thanks for your support so far and a big thanks to those of you that have been helping out others by replying to peoples questions in this thread.
I quoted the above post as I think you should look at a few considerable changes to take it further. Please take this as constructive criticism.

Firstly, I think even the most basic of authentication will be a big improvement for your app. Even it compares the incoming credentials to a file on the RPi, it will secure the app better than it is right now.

Second, you are basically using the gpio.php file as an API. But sending an update using GET parameters should be discouraged. You should change this to use REST principals as a GET to /api/pin/1 should return the pin state and a POST to /api/pin/1 with either 1 or 0 or a PWM value will change the pin state. Using Apache rewrites can make /api/pin/1 translate to what the gpio.php file expects in the short term.

Thirdly, consider switching from Apache and PHP to nodeJS. A node server is a lot more lightweight and you can package the server app in a node package and users can use npm to install it & update it regularly instead of maintaining an SD card image.

My current web interface is actually two separate entities. The website is a single page app using AngularJS that talks to the server app through an API. Any Android (or iCrap) app I write can use exactly the same API to change GPIO states. The server side uses a node package called Express to create and expose the API and I am now looking at how to use Linux Pluggable Authentication Modules and node to make a secure login using the user accounts on the RPi itself.

I should also add that the node server is not on the same RPi that I wish to change GPIO states. I have two RPi's, one is my home automation server with all the GPIO circuits set up. The other is my web server (all served using node). When an API request comes in, the node server talks to the home auto RPi over the network to change its GPIO states. It does this by sending specially crafted commands to pigpiod. Sending the JSON {state:0} to the url /api/pin/1 is essentially the same as writing "gpio write 1 0" on the commane line on the other RPi. There is no reason why you cant run them on the same RPi though by setting node to connect to the local pigpiod. I just like to have separation of concerns :)

If you wish to have more info on this then feel free to contact me :)
Main Computer: RPi3
BOINC Server: RPi2
Torrent Box: RPi2 + 2TB WD Green HDD via USB Dock
Web + Email Server: RPi2
Home Automation Server: RPi2 + Edimax EW-7811Un
Decomissioned: 2 x RPi Model B

prosise
Posts: 1
Joined: Tue Mar 28, 2017 6:41 pm

Pi zero W

Tue Mar 28, 2017 6:54 pm

Disclaimer: Total noob, learning with Pi1, and a zeroW.

Had a terrible time setting up wifi on the newer Pi zero W and ended up copying a image from a Pi1. Could not get signals on Pi Zero pinout to show any activity. I checked the pins on the Zero using the Pi1 diagram and it matches. Just curious how I could setup the Zero to utilize all the pins on the Zero as they should be setup? Or should I leave well enough alone? Great app..

Thx

mikev
Posts: 2
Joined: Sun May 21, 2017 9:36 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Sun May 21, 2017 9:54 pm

I have everything set up (or thought I did). The app is saying "Pi not detected on network".

I am just using the IP address of my Pi 192.168.1.133. In the "Server Settings" "Pi URL Addresses" dialog I have assigned http://192.168.1.133 to Pi 1 (also tried http://192.168.1.133/), but can't seem to get connected to the app.

192.168.1.133 brings up the apache default page if accessed from a browser (including chrome on the same phone I am running PiRelay on).

What am I missing?

Thanks in advance for the help.

mikev
Posts: 2
Joined: Sun May 21, 2017 9:36 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Fri May 26, 2017 8:18 pm

Solved! Problem was with a competing web server I didn't realize was running, so Apache was not serving the site.

ItsME2
Posts: 1
Joined: Fri Jul 14, 2017 11:35 am

Alexa?

Fri Jul 14, 2017 11:39 am

Hi!

I have set up pirelay (pro) and it works like a charm. Now I would like to try to use Alexa in addition to the app. Has someone tried anything like this before? As far as I understand it shouldn't be too hard to write a skill for that myself but I have zero experience doing anything like that.

Would be happy about any input and ideas from you guys.

Kevin

francoisk
Posts: 2
Joined: Fri Aug 04, 2017 2:00 am

Re: Control Relay Switches via Android using a Raspberry Pi

Fri Aug 04, 2017 2:02 am

The link https://pinout.xyz/pinout/wiringpi on your page no longer works. Would you kindly update or provide an alternate?
Thank you

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 10864
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Control Relay Switches via Android using a Raspberry Pi

Fri Aug 04, 2017 11:09 am

francoisk wrote:
Fri Aug 04, 2017 2:02 am
The link https://pinout.xyz/pinout/wiringpi on your page no longer works. Would you kindly update or provide an alternate?
Thank you
it works fine, please don't hijack a thread!

gwdarko
Posts: 1
Joined: Fri Sep 08, 2017 12:14 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Fri Sep 08, 2017 12:20 pm

Hi,

first of all - thank you for this great project! I have a question : well if I have door and want to know status of this door(garage door, switch is toogle and status of relay is irelevant or always is off).
If this is posible.

Thanks.

steegs8319
Posts: 1
Joined: Fri Oct 06, 2017 1:31 am

Re: Control Relay Switches via Android using a Raspberry Pi

Fri Oct 06, 2017 11:05 am

mikev wrote:
Sun May 21, 2017 9:54 pm
I have everything set up (or thought I did). The app is saying "Pi not detected on network".

I am just using the IP address of my Pi 192.168.1.133. In the "Server Settings" "Pi URL Addresses" dialog I have assigned http://192.168.1.133 to Pi 1 (also tried http://192.168.1.133/), but can't seem to get connected to the app.

192.168.1.133 brings up the apache default page if accessed from a browser (including chrome on the same phone I am running PiRelay on).

What am I missing?

Thanks in advance for the help.
Hi! Great app, however I seem to be having the same issue, & cannot for the life of me figure out how to resolve it :(
Any suggestions would be great!
Based on mikev's 2nd post I've been trying to determine if there may be another Apache server running, but not having much luck, nor in changing the port settings

citizeneraser
Posts: 1
Joined: Tue Oct 31, 2017 12:27 am

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Oct 31, 2017 12:56 am

Thanks for a great app and walkthrough! Total noob but I got it working. I'm using it to trigger a Halloween prop for the front yard that will violently shake a skeleton, activate a strobe light, and I'm hoping play a scream .mp3 or .wav file all at the same time.

Is there a simple (remember, noob here) way to add in code that will play the short audio file from the Raspberry Pi that I can send to a speaker with an aux cable?

It seems like it should be easy but I'm not finding much and I don't want to screw up what I finally got working. Let me know what you all think.

Thanks!

User avatar
jadro
Posts: 323
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: Control Relay Switches via Android using a Raspberry Pi

Wed Nov 15, 2017 10:52 am

Hi, is there maybe a way to implement IR transceiver for remotely controlled devices? I have an air conditioner and the switch is not there and the cables are in the wall. How you remotely control your air conditioner?
Thanx in advance,
Jadro
Oracle back-end database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

Flash216
Posts: 1
Joined: Fri Dec 01, 2017 2:38 am

Re: Control Relay Switches via Android using a Raspberry Pi

Fri Dec 01, 2017 2:42 am

Hello, I wanted to thank you for such a good project, I'm trying it, it works without problems,
There is the possibility of having more than 5 urls.
Maybe you could be an option of the pro version.

Many, thank you very much

Greetings from Uruguay

:D :D :D :D :D :D :D :D

poumpouris
Posts: 1
Joined: Fri Dec 08, 2017 9:07 am

Re: Control Relay Switches via Android using a Raspberry Pi

Fri Dec 08, 2017 9:21 am

Hey, im in the process of setting PiRelay up (waiting for the relay to ship) and this is an awesome way to control the relays!
Thank you for developing this in a friendly to use interface as in my implementation i will have others who are not so tech savvy using it.
@jazzler I know this question has been asked before but i could not find an answer to it, so sorry for asking again.
Is there any chance that a timer can be applied for the relays? Say for example i want to turn on relay 1 for 30 minutes or something.
I understand that you might not have the time to do that but if you could share the source code for the app, i think i could check it and see if i can do it by my self.

Thank you in advance.

kevinV
Posts: 1
Joined: Tue Jun 05, 2018 7:04 am

Re: Control Relay Switches via Android using a Raspberry Pi

Tue Jun 05, 2018 7:08 am

Hi,

Thx for this great project. Working like a charm!
But I have one question: I used the image on your website for my Raspberry. But when I want to access it through ssh it says 'connection refused'.
Is ssh connection disabled by default?

Thx, & grtz Kevin.

hectorvz
Posts: 1
Joined: Wed Jun 13, 2018 2:40 pm

Re: Control Relay Switches via Android using a Raspberry Pi

Wed Jun 13, 2018 3:05 pm

Hi.
Firstly, thanks for an excellent app, never had issue with Pi2/3 on which it was tested for use on Pi Zero-W.
On Pi Zero on/off functions fine, but the pulse varies between 1 and 4 pulses.
I used the card from the Pi3, then clean installl on 2nd card, results stay the same.
All other possible variables the same (Wifi signal, power etc).

Greatings from the Banana Republic.

kssrinivasan
Posts: 1
Joined: Thu Jun 14, 2018 10:03 am

Re: Control Relay Switches via Android using a Raspberry Pi

Fri Jun 15, 2018 6:31 pm

It's working great.I had connected 16 channels relay board with pi1.(option 12v or 5v)
I will post video later.
I have a doubt in app how can I connect server mode.
WiFi connection working is fine.

l'electrique
Posts: 6
Joined: Fri Aug 03, 2018 1:23 am
Location: Saint Paul, MN
Contact: Website

Re: Control Relay Switches via Android using a Raspberry Pi

Fri Aug 03, 2018 1:53 am

Hoagie wrote:
Tue Nov 05, 2013 1:08 pm
If you have Apache installed, can;t you do this as a web page. That way any device with a browser can control it. I control my TV with an iPhone or android tablet using the page in the attached picture.
remote.jpg
Greetings,
I see you are still active on this Raspberry Forum (I joined today) I need to control my relays a better way. [https://tutorials-raspberrypi.com/setup ... rol-gpios/] With this the interface times out and stops working. I love PIRELAY and having working with an Android App, but I am curious what I have to do to control the relays as a web page so as to integrate into my website.
Thanks
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
08-12-18 09:35 am
I made some headway on my own (basically finding some code I could integrate with PiRelay). The problem is that the [on] button summons the [on] page and changes the relay, BUT the [off] button does not summon the [off] page. I know the [off] page works because the [on] button will summon it if I set it up as I did the [on] page. This is new to me and I concede that I need help. Calling all coders is the alert I am sending out. Please contact me if you need more information from me. [email protected]

Code: Select all

[<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <meta name="generator" content="openElement (1.57.9)" />
  <title>tie in</title>
  <link id="openElement" rel="stylesheet" type="text/css" href="WEFiles/Css/v02/openElement.css?v=50491101600" />
  <link id="OEBase" rel="stylesheet" type="text/css" href="tie%20in.css?v=50491101600" />
  <!--[if lte IE 7]>
  <link rel="stylesheet" type="text/css" href="WEFiles/Css/ie7.css?v=50491101600" />
  <![endif]-->
  <script type="text/javascript">
   var WEInfoPage = {"PHPVersion":"phpOK","OEVersion":"1-57-9","PagePath":"tie in","Culture":"DEFAULT","LanguageCode":"EN","RelativePath":"","RenderMode":"Export","PageAssociatePath":"tie in","EditorTexts":null};
  </script>
  <script type="text/javascript" src="WEFiles/Client/jQuery/1.10.2.js?v=50491101600"></script>
  <script type="text/javascript" src="WEFiles/Client/jQuery/migrate.js?v=50491101600"></script>
  <script type="text/javascript" src="WEFiles/Client/Common/oe.min.js?v=50491101600"></script>
 </head>
 <body class="" data-gl="{&quot;KeywordsHomeNotInherits&quot;:false}">
  <form id="XForm" method="post" action="#"></form>
  <html>
  
   
  
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  
  <script type="text/javascript">// <![CDATA[
  
  $(document).ready(function() {
  
  $('#on').click(function(){
  
  var a= new XMLHttpRequest();
  
  a.open("GET", "on.php"); a.onreadystatechange=function(){
  
  if(a.readyState==4){ if(a.status ==200){
  
   } else alert ("http error"); } }
  
  a.send();
  
  });
  
  });
  
  $(document).ready(function()
  
  { $('#Off').click(function(){
  
  var a= new XMLHttpRequest();
  
  a.open("GET", "off.php");
  
  a.onreadystatechange=function(){
  
  if(a.readyState==4){
  
  if(a.status ==200){
  
   } else alert ("http error"); } }
  
  a.send();
  
  });
  
  });
  
  </script>
  
  <button id="on" type="button"> Switch Lights On </button>
  
  <button id="off" type="button"> Switch Lights Off </button>
  <div id="XBody" class="BaseDiv RWidth OEPageXbody OESK_XBody_Default" style="z-index:0">
   <div class="OESZ OESZ_DivContent OESZG_XBody">
    <div class="OESZ OESZ_XBodyContent OESZG_XBody OECT OECT_Content OECTAbs"></div>
    <div class="OESZ OESZ_XBodyFooter OESZG_XBody OECT OECT_Footer OECTAbs"></div>
   </div>
  </div>
 </body>
</html>]

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: Google [Bot] and 7 guests