{"id":23,"date":"2022-12-11T11:20:16","date_gmt":"2022-12-11T10:20:16","guid":{"rendered":"http:\/\/129.152.21.86\/?p=23"},"modified":"2022-12-11T11:20:16","modified_gmt":"2022-12-11T10:20:16","slug":"raspi-als-ip-power-switch","status":"publish","type":"post","link":"https:\/\/www.kleinladen.at\/?p=23","title":{"rendered":"Raspi als IP-Power-Switch"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Kurzbeschreibung<\/h1>\n\n\n\n<p>L\u00e4uft als PHP-Script unter http:\/\/IP-Adresse\/index.php<\/p>\n\n\n\n<p>Das Script selbst:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;html&gt;\n&lt;head&gt;\n&lt;meta name=\"viewport\" content=\"width=device-width\" \/&gt;\n&lt;title&gt;IP-Switch Raspi Hinteralm&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;p&gt;&lt;h1 align=\"center\"&gt;Welcome,&lt;br \/&gt;... Raspberry als IP-Switch ist bereit! &lt;\/h1&gt;\n&lt;p align=\"center\"&gt; &lt;\/p&gt;\n&lt;br&gt;\n&lt;form method=\"get\" action=\"index.php\"&gt;\nPort 18 - GPIO 24 - SW1 - schalten (&lt;b&gt;10A max&lt;\/b&gt;):\n&lt;br&gt;\nStatus (0=ein, 1=aus):&lt;b&gt;\n&lt;?php\n$val = exec (\"\/usr\/local\/bin\/gpio -g read 24\", $status, $error);\nprint_r ( $val );\n?&gt;&lt;\/b&gt;&lt;br&gt;\n&lt;input type=\"text\" size=\"4\" value=\"\" name=\"t1\"&gt;\n&lt;input type=\"submit\" value=\"SW1 an\" name=\"p1an\"&gt;\n&lt;input type=\"submit\" value=\"SW1 aus\" name=\"p1aus\"&gt;\n&lt;br&gt;&lt;br&gt;\nPort 22 - GPIO 25 - SW2 - schalten (&lt;b&gt;10A max&lt;\/b&gt;):\n&lt;br&gt;\nStatus (0=ein, 1=aus):&lt;b&gt;\n&lt;?php\n$val = exec (\"\/usr\/local\/bin\/gpio -g read 25\", $status, $error);\nprint_r ( $val );\n?&gt;&lt;\/b&gt;&lt;br&gt;\n&lt;input type=\"text\" size=\"4\" value=\"\" name=\"t2\"&gt;\n&lt;input type=\"submit\" value=\"SW2 an\" name=\"p2an\"&gt;\n&lt;input type=\"submit\" value=\"SW2 aus\" name=\"p2aus\"&gt;\n&lt;br&gt;&lt;br&gt;\nPort 24 - GPIO 8 - SW3 - schalten (&lt;b&gt;10A max&lt;\/b&gt;):\n&lt;br&gt;\nStatus (0=ein, 1=aus):&lt;b&gt;\n&lt;?php\n$val = exec (\"\/usr\/local\/bin\/gpio -g read 8\", $status, $error);\nprint_r ( $val );\n?&gt;&lt;\/b&gt;&lt;br&gt;\n&lt;input type=\"text\" size=\"4\" value=\"\" name=\"t3\"&gt;\n&lt;input type=\"submit\" value=\"SW3 an\" name=\"p3an\"&gt;\n&lt;input type=\"submit\" value=\"SW3 aus\" name=\"p3aus\"&gt;\n&lt;br&gt;&lt;br&gt;\nPort 26 - GPIO 7 - SW4 - schalten (&lt;b&gt;10A max&lt;\/b&gt;):\n&lt;br&gt;\nStatus (0=ein, 1=aus):&lt;b&gt;\n&lt;?php\n$val = exec (\"\/usr\/local\/bin\/gpio -g read 7\", $status, $error);\nprint_r ( $val );\n?&gt;&lt;\/b&gt;&lt;br&gt;\n&lt;input type=\"text\" size=\"4\" value=\"\" name=\"t4\"&gt;\n&lt;input type=\"submit\" value=\"SW4 an\" name=\"p4an\"&gt;\n&lt;input type=\"submit\" value=\"SW4 aus\" name=\"p4aus\"&gt;\n&lt;br&gt;&lt;br&gt;\nPort 32 - GPIO 12 - SW5 - schalten (&lt;b&gt;10A max&lt;\/b&gt;):\n&lt;br&gt;\nStatus (0=ein, 1=aus):&lt;b&gt;\n&lt;?php\n$val = exec (\"\/usr\/local\/bin\/gpio -g read 12\", $status, $error);\nprint_r ( $val );\n?&gt;&lt;\/b&gt;&lt;br&gt;\n&lt;input type=\"text\" size=\"4\" value=\"\" name=\"t5\"&gt;\n&lt;input type=\"submit\" value=\"SW5 an\" name=\"p5an\"&gt;\n&lt;input type=\"submit\" value=\"SW5 aus\" name=\"p5aus\"&gt;\n&lt;br&gt;&lt;br&gt;\nPort 36 - GPIO 16 - SW6 -&nbsp; schalten (&lt;b&gt;10A max&lt;\/b&gt;):\n&lt;br&gt;\nStatus (0=ein, 1=aus):&lt;b&gt;\n&lt;?php\n$val = exec (\"\/usr\/local\/bin\/gpio -g read 16\", $status, $error);\nprint_r ( $val );\n?&gt;&lt;\/b&gt;&lt;br&gt;\n&lt;input type=\"text\" size=\"4\" value=\"\" name=\"t6\"&gt;\n&lt;input type=\"submit\" value=\"SW6 an\" name=\"p6an\"&gt;\n&lt;input type=\"submit\" value=\"SW6 aus\" name=\"p6aus\"&gt;\n&lt;br&gt;&lt;br&gt;\nPort 38 - GPIO 20 - SW7 - schalten (&lt;b&gt;10A max&lt;\/b&gt;):\n&lt;br&gt;\nStatus (0=ein, 1=aus):&lt;b&gt;\n&lt;?php\n$val = exec (\"\/usr\/local\/bin\/gpio -g read 20\", $status, $error);\nprint_r ( $val );\n?&gt;&lt;\/b&gt;&lt;br&gt;\n&lt;input type=\"text\" size=\"4\" value=\"\" name=\"t7\"&gt;\n&lt;input type=\"submit\" value=\"SW7 an\" name=\"p7an\"&gt;\n&lt;input type=\"submit\" value=\"SW7 aus\" name=\"p7aus\"&gt;\n&lt;br&gt;&lt;br&gt;\nPort 40 - GPIO 21 - SW8 - schalten (&lt;b&gt;10A max&lt;\/b&gt;):\n&lt;br&gt;\nStatus (0=ein, 1=aus):&lt;b&gt;\n&lt;?php\n$val = exec (\"\/usr\/local\/bin\/gpio -g read 21\", $status, $error);\nprint_r ( $val );\n?&gt;&lt;\/b&gt;&lt;br&gt;\n&lt;input type=\"text\" size=\"4\" value=\"\" name=\"t8\"&gt;\n&lt;input type=\"submit\" value=\"SW8 an\" name=\"p8an\"&gt;\n&lt;input type=\"submit\" value=\"SW8 aus\" name=\"p8aus\"&gt;\n&lt;\/form&gt;\n&lt;?php\nif(isset($_GET[\"p1an\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 24 0\"));\n$t1 = $_GET[\"t1\"];\nif ($t1 &gt; 0) {\nsleep($t1);\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 24 1\"));\n}\n}\nelse if(isset($_GET[\"p1aus\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 24 1\"));\n}\nif(isset($_GET[\"p2an\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 25 0\"));\n$t1 = $_GET[\"t2\"];\nif ($t2 &gt; 0) {\nsleep($t2);\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 25 1\"));\n}\n}\nelse if(isset($_GET[\"p2aus\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 25 1\"));\n}\nif(isset($_GET[\"p3an\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 8 0\"));\n$t1 = $_GET[\"t3\"];\nif ($t3 &gt; 0) {\nsleep($t3);\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 8 1\"));\n}\n}\nelse if(isset($_GET[\"p3aus\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 8 1\"));\n}\nif(isset($_GET[\"p4an\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 7 0\"));\n$t1 = $_GET[\"t4\"];\nif ($t4 &gt; 0) {\nsleep($t4);\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 7 1\"));\n}\n}\nelse if(isset($_GET[\"p4aus\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 7 1\"));\n}\nif(isset($_GET[\"p5an\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 12 0\"));\n$t1 = $_GET[\"t5\"];\nif ($t5 &gt; 0) {\nsleep($t5);\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 12 1\"));\n}\n}\nelse if(isset($_GET[\"p5aus\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 12 1\"));\n}\nif(isset($_GET[\"p6an\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 16 0\"));\n$t1 = $_GET[\"t6\"];\nif ($t6 &gt; 0) {\nsleep($t6);\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 16 1\"));\n}\n}\nelse if(isset($_GET[\"p6aus\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 16 1\"));\n}\nif(isset($_GET[\"p7an\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 20 0\"));\n$t1 = $_GET[\"t7\"];\nif ($t7 &gt; 0) {\nsleep($t7);\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 20 1\"));\n}\n}\nelse if(isset($_GET[\"p7aus\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 20 1\"));\n}\nif(isset($_GET[\"p8an\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 21 0\"));\n$t1 = $_GET[\"t8\"];\nif ($t8 &gt; 0) {\nsleep($t8);\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 21 1\"));\n}\n}\nelse if(isset($_GET[\"p8aus\"])){\n$val = trim(@shell_exec(\"\/usr\/local\/bin\/gpio -g write 21 1\"));\n}\n\n?&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n\n\n\n<p>Die Initialisierung dazu &#8220;startup_server.sh&#8221; (starten beim Hochlauf mit crontab!):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#\n# Port 24\n#\n\/usr\/local\/bin\/gpio -g mode 24 out\n# 0 = einschalten, 1 = ausschalten bei Startup\n\/usr\/local\/bin\/gpio -g write 24 0\n#\n# Port 25\n#\n\/usr\/local\/bin\/gpio -g mode 25 out\n# 0 = einschalten, 1 = ausschalten bei Startup\n\/usr\/local\/bin\/gpio -g write 25 0\n#\n# Port 8\n#\n\/usr\/local\/bin\/gpio -g mode 8 out\n# 0 = einschalten, 1 = ausschalten bei Startup\n\/usr\/local\/bin\/gpio -g write 8 0\n#\n# Port 7\n#\n\/usr\/local\/bin\/gpio -g mode 7 out\n# 0 = einschalten, 1 = ausschalten bei Startup\n\/usr\/local\/bin\/gpio -g write 7 0\n#\n# Port 12\n#\n\/usr\/local\/bin\/gpio -g mode 12 out\n# 0 = einschalten, 1 = ausschalten bei Startup\n\/usr\/local\/bin\/gpio -g write 12 0\n#\n# Port 16\n#\n\/usr\/local\/bin\/gpio -g mode 16 out\n# 0 = einschalten, 1 = ausschalten bei Startup\n\/usr\/local\/bin\/gpio -g write 16 0\n#\n# Port 20\n#\n\/usr\/local\/bin\/gpio -g mode 20 out\n# 0 = einschalten, 1 = ausschalten bei Startup\n\/usr\/local\/bin\/gpio -g write 20 0\n#\n# Port 21\n#\n\/usr\/local\/bin\/gpio -g mode 21 out\n# 0 = einschalten, 1 = ausschalten bei Startup\n\/usr\/local\/bin\/gpio -g write 21 0\n\n# Verzeichnis fuer Webserver anlegen\nif [ ! -d \"\/var\/log\/nginx\" ]; then\n&nbsp; sudo mkdir \/var\/log\/nginx\nfi\n# Webserver starten\nsudo service nginx restart<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.kleinladen.at\/wp-content\/uploads\/2022\/12\/Raspi_SW_Connection.jpg\" alt=\"\" class=\"wp-image-25\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.kleinladen.at\/wp-content\/uploads\/2022\/12\/Relais_SW_Connection-1.jpg\" alt=\"\" class=\"wp-image-26\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Kurzbeschreibung L\u00e4uft als PHP-Script unter http:\/\/IP-Adresse\/index.php Das Script selbst: &lt;html&gt; &lt;head&gt; &lt;meta name=&#8221;viewport&#8221; content=&#8221;width=device-width&#8221; \/&gt; &lt;title&gt;IP-Switch Raspi Hinteralm&lt;\/title&gt; &lt;\/head&gt; &lt;p&gt;&lt;h1 align=&#8221;center&#8221;&gt;Welcome,&lt;br \/&gt;&#8230; Raspberry als IP-Switch ist bereit! &lt;\/h1&gt; &lt;p align=&#8221;center&#8221;&gt; &lt;\/p&gt; &lt;br&gt; &lt;form method=&#8221;get&#8221; action=&#8221;index.php&#8221;&gt; Port 18 &#8211; GPIO 24 &#8211; SW1 &#8211; schalten (&lt;b&gt;10A max&lt;\/b&gt;): &lt;br&gt; Status (0=ein, 1=aus):&lt;b&gt; &lt;?php $val = exec (&#8220;\/usr\/local\/bin\/gpio &hellip; <a href=\"https:\/\/www.kleinladen.at\/?p=23\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Raspi als IP-Power-Switch<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.kleinladen.at\/index.php?rest_route=\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kleinladen.at\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kleinladen.at\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kleinladen.at\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kleinladen.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23"}],"version-history":[{"count":1,"href":"https:\/\/www.kleinladen.at\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":27,"href":"https:\/\/www.kleinladen.at\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions\/27"}],"wp:attachment":[{"href":"https:\/\/www.kleinladen.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kleinladen.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kleinladen.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}