0

So I'm creating a system that turns a motor for about 5 seconds and then turns off, but I want the user to be able to input what times they want the system to go off at ideally. I was thinking of having 3 inputs that the user can enter the desired time into and then press submit and have them get set. I'm not sure how I can do this because I'm using a Pi Zero W hosting Apache web server on it and its in access point mode so that it doesn't need to be connected to internet to work. However, I'm not sure how to set all this up in PHP and HTML.

Due to not being connected to the internet, I don't think I can use times, so I was thinking of letting the user choose how long from now they want it to be activated - e.g. 6 hours from now, 12 hours and 18 hours. I have used hostapd, dnsmasq apache2 and php7 on my Pi to get this far, and everything is working correctly except this is the last bit I need. I've managed to access both index.html and index.php files from another device that's connected to the Pi's access point.

Security and validation isn't a concern because I just need to get the concept working and that will be fine, however I have no clue how to go about doing this without connecting to the internet. Any help would be incredibly helpful - Thank you!!!

This is the code I'm using at the moment, however this just turns the motor on and off, but I'm just using it as testing to see if the motor would turn of via this method (index.php):

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Motor Control</title>
</head>
        <body>
        Motor Control:
        <form method="get" action="index.php">
                <input type="submit" value="ON" name="on">
                <input type="submit" value="OFF" name="off">
        </form>
        <?php
        $setmode23 = shell_exec("/usr/local/bin/gpio -g mode 23 out");
        if(isset($_GET['on'])){
                $gpio_on = shell_exec("/usr/local/bin/gpio -g write 23 1");
                echo "Motor is on";
        }
        else if(isset($_GET['off'])){
                $gpio_off = shell_exec("/usr/local/bin/gpio -g write 23 0");
                echo "Motor is off";
        }
        ?>
        </body>
</html>
Pang
  • 9,564
  • 146
  • 81
  • 122
Bradderz
  • 21
  • 8
  • very broad, not sure where to start asking, can you narrow the scope? –  Apr 10 '18 at 21:37
  • I just need to accept 3 times from a user (e.g. 6 hours from now) and then when the user hits submit on the web page, the pi sets a timer that, in 6 hours, will activate a gpio pin for about 5 seconds then turn it off again. But I need 3 of these inputs and need to be able to modify them. – Bradderz Apr 10 '18 at 21:46
  • html form->storage(file/db) –  Apr 10 '18 at 22:19
  • I would opt to launch a sort of Timer function in php that uses the user input time to perform the desired action action. This link https://stackoverflow.com/questions/10587323/timeout-a-function-in-php will probably help you along. – C. van Dorsten Apr 10 '18 at 22:43

0 Answers0