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>
4
  • very broad, not sure where to start asking, can you narrow the scope? Commented Apr 10, 2018 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. Commented Apr 10, 2018 at 21:46
  • html form->storage(file/db) Commented Apr 10, 2018 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 stackoverflow.com/questions/10587323/timeout-a-function-in-php will probably help you along. Commented Apr 10, 2018 at 22:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.