Chat freely about anything...

User avatar
By rpiloverbd
#94040 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.
User avatar
By Inq720
#94049
Untitled.png
$14

This was a 2 second search on Amazon, using "Wemos Relay". Don't have to dink with pull-ups/down, dc-to-dc converters, regulators or anything else. Solder the headers, snap together. Bam! Program, Bam!
User avatar
By Inq720
#94051 I hope you don't mind... but I saw this as a perfect opportunity to write the program. I can see that it would be useful to turn on/off anything... lights around here... etc. And I wanted to see how small the program would be as that is the goal of the library... making development of this type of program easy.

I have it just turning the WeMos LED on/off. If change the pin to the relay's and setup the home router in question. You'd be able to access the included UI from either your home router network or the ParentsRule network. Obviously once you turn your home router off, you could only use the ParentsRule network to turn it back on. Once your home router is back on, the ESP8266 should reconnect.

Code: Select all#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() { }


Client UI is ugly, but it works. Also, doing this self imposed challenge illustrated a few places I can improve the library. I'll reduce the mess in the next version.

Edit: This has been modified to use version InqPortal 5.2.3 or greater.
Code: Select all<!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>

Untitled.png
Last edited by Inq720 on Wed Mar 23, 2022 9:04 am, edited 1 time in total.
User avatar
By Inq720
#94061 Version 5.2.3 has been published. It should be available on the Arduino IDE Library Manager within an hour (according to Arduino documentation). It now handles HTML checkboxes and radio buttons transparently. So the web page can be simplified to:

Code: Select all<!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>


If you use InqPortal or not, I'd be curious how you flesh out your project... i.e. schedules and such.

VBR,
Inq