Re: ESP8266 as switch
Posted: Tue Mar 22, 2022 12:46 am
If you're planning to switch off the router after a definite time, you will need a relay. You can switch on/off the relay with ESP8266 or Arduino.
-->
Open Community Forum for ESP8266, Come share Arduino and IoT (Internet of Things)
https://www.esp8266.com/
#include <InqPortal.h>
#define ADULT_SSID "ParentsRule" // ESP8266 Direct SSID
#define ADULT_PW "passW0rd" // ESP8266 Direct PW
#define ALL_SSID "YourSSID" // Home SSID
#define ALL_PW "YourPW" // Home PW
#define RELAY_PIN LED_BUILTIN // Change LED_BUILTIN to pin used by relay.
InqPortal svr;
void setup()
{
svr.publishRW("PT", NULL, "Play time on/off",
[]()->u8 { return !digitalRead(RELAY_PIN); }, // <-- might remove !
[](u8 sw) { digitalWrite(RELAY_PIN, !sw); }); // <-- might remove !
svr.begin(ADULT_SSID, ADULT_PW, ALL_SSID, ALL_PW);
pinMode(RELAY_PIN, OUTPUT);
}
void loop() { }
<!DOCTYPE html>
<html>
<head>
<title>Parents Rule</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script src='InqPortal.js'></script>
<link rel='stylesheet' type='text/css' href='InqStyle.css'>
</head>
<body class='space'>
<h1 class='space'>
<input id='PT' type='checkbox' style='height:1em;width:1em;'
onclick='set();' >
<label for='PT'>Play Time</label>
</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Parents Rule</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script src='InqPortal.js'></script>
<link rel='stylesheet' type='text/css' href='InqStyle.css'>
</head>
<body class='space'>
<h1 class='space'>
<input id='PT' type='checkbox' style='height:1em;width:1em;'
onclick='set();' >
<label for='PT'>Play Time</label>
</h1>
</body>
</html>