Magic Switch IOT Project

Thread Starter


Joined Oct 17, 2018
I'm working on an IOT project, based on a html switch that is able to pay my far away sister's unpaid bills just a "pressing on" action.
Indeed,it sends a HTTP POST request to a server (established on nodemcu board) in order to make a SIM800 to execute some USSD codes (that are determined to pay the bills).
The HTML switch is supposed to be on a linux hosting (permanently accessible with a public domain).
I remember there was a signal called "magic packet" for ethernet ports of old motherboard's that could wake them up ,so i called it "magic switch".
the first part is main switch's html code by sending HTTP POST request (as a client) via javascript:

<div class="switch demo">
                    <input type="checkbox" name="dark_light" onchange="loadDoc()">
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML = this.responseText;
  };"POST", "", true);

  xhttp.send("hello buddy");

For the above part , I'm still looking for a fancy css code for the "switch demo" class...

the next part is Arduino code for Nodemce 12E, that makes the board listen to http requests through a DDNS configured with a static IP on my DSL modem via an opened port :

t #include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <EasyDDNS.h>
ESP8266WebServer server(8888);

const char* ssid = "SSID";
const char* password =  "PASS";

void setup() {

    IPAddress ip(192,168,1,20);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
IPAddress primaryDNS(8, 8, 8, 8);
WiFi.config(ip, gateway, subnet,primaryDNS);
    WiFi.begin(ssid, password);  //Connect to the WiFi network

    while (WiFi.status() != WL_CONNECTED) {  //Wait for connection

        Serial.println("Waiting to connect...");


    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());  //Print the local IP

    server.on("/body", handleBody); //Associate the handler function to the path

    server.begin(); //Start the server
    Serial.println("Server listening");
    EasyDDNS.service("duckdns");    // Enter your DDNS Service Name - "duckdns" / "noip"
EasyDDNS.client("","token");    // Enter ddns Domain & Token | Example - "","1234567"
Serial.println("DNS Initiated...");


void loop() {

    server.handleClient(); //Handling of incoming requests


void handleBody() { //Handler for the body path

      if (server.hasArg("plain")== false){ //Check if body received

            server.send(200, "text/plain", "Body not received");


      String message = "Body received:\n";
             message += server.arg("plain");
             message += "\n";

      server.send(200, "text/plain", message);
      if (server.arg("plain")=="hello buddy")

it brings up the board waiting for a default string "hello buddy" as signal and then print it on serial output.
I didn't use nodemcu as switch's host,due to security ,easy access and keeping the switch permanently available to send other possible requests in the future.
For the next part, I still doubt about the version of SIM800 module to be compatible with Nodemcu's 3.3v serial interface and a proper library for it?!
thanks for help.
Last edited: