logo
NodeCloud
NodeCloud

NodeCloud is a working NodeMCU ESP8266 Cloud conecept using the NodeMCU to control a remote NodeMCU
where router port forwarding is not possable and you don't want to use a 3rd party cloud service
In this artical ill be using
an Android App that I am developing
called NodeController, its sends commands to the NodeMCU ESP8266

You could send the command from a Web Browser address bar,
format: ip-address:port/COMMAND ,eg: 10.220.1.22:80/RELAY1ON
would turn Relay 1 ON.

format: ip-address:port/COMMAND ,eg: 10.220.1.22:80/RELAY1OFF
would turn Relay 1 OFF.

Or you could use the App that I have been developing
NodeController for Android you will find a link in the description

How it works
I will asume that you are using NodeClontroller and its been configured to send commands to the NodeMCU Cloud Server unit,
when you press one of the buttons in the App its send a command to the Cloud Server and it will register you request,
then it will add that request to a html page then it will wait until the Slave requests the page from the Cloud Server,
the Slave will read the data on the requested html page and perform the request
the data on the html page is only made up of Ones and Zeros,
One = ON and Zero = OFF

 What you will need,
# Dynamic DNS (No-IP) and client if you dont have a Static Public ip Address
This is a No-IP client I made with a NodeMCU
# You will need to setup Port Forwarding on the Router at the premises of the Cloud Server


PARTS

1 x WeMos D1 USB NodeMcu Lua V3 CH340G ESP8266 Wireless Internet Development 5-9V
or
1 x NodeMCU Lua ESP8266 ESP-12 WeMos D1 Mini WIFI

  7 x LEDS what colours you want
7 x 470 ohm Resistorsor 2

2 x 5v dc Power Supply

Some other components depending how you would like to connect the wires to the PCB, eg pin headers, terminals.











NodeCloud1       

NodeCloud2        nodecontrollermain       


Below I have added a link to download a Ziped file with the Arduino Sketch, Schematic, Readme
Download  Sketch and info

 Now NodeController on Google Play Store

       

NodeCloud NodeMCUs schematic
click picture to enlarge

Below are the Sketches for This Project, you can modify it to suit your own designs, the first Sketch is for the Cloud Server and the second is for the Slave
/*
 MerrittSoft
 Remote Relay Cloud Server
 17/04/2020
 Language: C++/Arduino
 Thank you to those people that made the Libarays in this project posable.
*/

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>


ESP8266WebServer server(80);

char* ssid = "ssid-name";
char* password = "ssid-password";
const int wificonnected = D0;
const int slaveconnected = D2;

String one = "1";
String zero = "0";


String relay1 = "0";
String relay2 = "0";
String relay3 = "0";
String relay4 = "0";
String relay5 = "0";
String relay6 = "0";
String relay7 = "0";
String relay8 = "0";

void setup() {
 pinMode(wificonnected, OUTPUT);
 pinMode(slaveconnected, OUTPUT);
 digitalWrite(wificonnected, LOW);
 digitalWrite(slaveconnected, LOW);

 WiFi.begin(ssid, password);
 WiFi.hostname("RemoteRelayCloudServer");
 WiFi.mode(WIFI_STA);
 Serial.begin(115200);
 while (WiFi.status() != WL_CONNECTED)
 {
   Serial.print(".");
   delay(500);
 }
 digitalWrite(wificonnected, HIGH);
 Serial.println("");
 Serial.print("IP Address: ");
 Serial.println(WiFi.localIP());
 Serial.println();

 server.on("/", []() {
   server.send(200, "text/plain", "RemoteRelayCloudServer");
 });

 server.on("/RELAY1", remote1); // This is where the Slave comes in
 server.on("/RELAY1ON", relay1on); // The rest of them is where the commands come in from
 server.on("/RELAY1OFF", relay1off); // the controller eg: NodeController App
 server.on("/RELAY2ON", relay2on);
 server.on("/RELAY2OFF", relay2off);
 server.on("/RELAY3ON", relay3on);
 server.on("/RELAY3OFF", relay3off);
 server.on("/RELAY4ON", relay4on);
 server.on("/RELAY4OFF", relay4off);
 server.on("/RELAY5ON", relay5on);
 server.on("/RELAY5OFF", relay5off);
 server.on("/RELAY6ON", relay6on);
 server.on("/RELAY6OFF", relay6off);
 server.on("/RELAY7ON", relay7on);
 server.on("/RELAY7OFF", relay7off);
 server.on("/RELAY8ON", relay8on);
 server.on("/RELAY8OFF", relay8off);

 server.begin();
}

void loop() {
 if (WiFi.status() != WL_CONNECTED)
 {
   ESP.reset();
 }
 server.handleClient();
}

void remote1()
{
 Serial.print("reseved request");
 Serial.println();
 digitalWrite(slaveconnected, HIGH);
 delay(1000);
 digitalWrite(slaveconnected, LOW);

 // The next section is where it puts the html page together for the Slave
 server.send(200, "text/plain", relay1 + relay2 + relay3 + relay4 + relay5 + relay6 + relay7 + relay8);
 Serial.println(relay1 + relay2 + relay3 + relay4 + relay5 + relay6 + relay7 + relay8);
 return;
}

void relay1on()
{
 Serial.print("relay1 = 1");
 Serial.println();
 delay(1000);
 relay1 = one;
 server.send(204, "");

 return;
}

void relay1off()
{
 Serial.print("relay1 = 0");
 Serial.println();
 delay(1000);
 relay1 = zero;
 server.send(204, "");

 return;
}

void relay2on()
{
 Serial.print("relay2 = 1");
 Serial.println();
 delay(1000);
 relay2 = one;
 server.send(204, "");

 return;
}

void relay2off()
{
 Serial.print("relay2 = 0");
 Serial.println();
 delay(1000);
 relay2 = zero;
 server.send(204, "");

 return;
}

void relay3on()
{
 Serial.print("relay3 = 1");
 Serial.println();
 delay(1000);
 relay3 = one;
 server.send(204, "");

 return;
}

void relay3off()
{
 Serial.print("relay3 = 0");
 Serial.println();
 delay(1000);
 relay3 = zero;
 server.send(204, "");

 return;
}

void relay4on()
{
 Serial.print("relay4 = 1");
 Serial.println();
 delay(1000);
 relay4 = one;
 server.send(204, "");

 return;
}

void relay4off()
{
 Serial.print("relay4 = 0");
 Serial.println();
 delay(1000);
 relay4 = zero;
 server.send(204, "");

 return;
}

void relay5on()
{
 Serial.print("relay5 = 1");
 Serial.println();
 delay(1000);
 relay5 = one;
 server.send(204, "");

 return;
}

void relay5off()
{
 Serial.print("relay5 = 0");
 Serial.println();
 delay(1000);
 relay5 = zero;
 server.send(204, "");

 return;
}

void relay6on()
{
 Serial.print("relay6 = 1");
 Serial.println();
 delay(1000);
 relay6 = one;
 server.send(204, "");

 return;
}

void relay6off()
{
 Serial.print("relay6 = 0");
 Serial.println();
 delay(1000);
 relay6 = zero;
 server.send(204, "");

 return;
}

void relay7on()
{
 Serial.print("relay7 = 1");
 Serial.println();
 delay(1000);
 relay7 = one;
 server.send(204, "");

 return;
}

void relay7off()
{
 Serial.print("relay7 = 0");
 Serial.println();
 delay(1000);
 relay7 = zero;
 server.send(204, "");

 return;
}

void relay8on()
{
 Serial.print("relay8 = 1");
 Serial.println();
 delay(1000);
 relay8 = one;
 server.send(204, "");

 return;
}

void relay8off()
{
 Serial.print("relay8 = 0");
 Serial.println();
 delay(1000);
 relay8 = zero;
 server.send(204, "");

 return;
}



//******************************************************************************************


/*
 MerrittSoft
 Remote Relay Slave
 //****for 4 outputs only but could be 8****
 17/04/2020
 Language: C++/Arduino
 Thank you to those people that made the Libarays in this project posable.
*/


#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>

String load;

const int wificonnected = D0;
const int output1 = D2;
const int output2 = D4;
const int output3 = D5;
const int output4 = D7;

String payload = "0";

void setup() {
 pinMode(wificonnected, OUTPUT);
 pinMode(output1, OUTPUT);
 pinMode(output2, OUTPUT);
 pinMode(output3, OUTPUT);
 pinMode(output4, OUTPUT);
 digitalWrite(wificonnected, LOW);
 digitalWrite(output1, LOW);
 digitalWrite(output2, LOW);
 digitalWrite(output3, LOW);
 digitalWrite(output4, LOW);
 Serial.begin(115200);

 WiFiManager wifiManager;

 wifiManager.setConfigPortalTimeout(120);
 wifiManager.setTimeout(120);

 wifiManager.autoConnect("RelaySlave");

 digitalWrite(wificonnected, HIGH);
 Serial.println(WiFi.localIP()); // Print the IP address
}

void loop() {

 if (WiFi.status() != WL_CONNECTED)
 {
   ESP.reset();
 }
 delay(3000);

 WiFiClient client;
 HTTPClient http;    //Declare object of class HTTPClient


 //**** Below is where you add the URL or IP Address of the Server that you have setup at your premises,
 //**** and the Port you have setup in the Router for Port Forwarding at the Server premises.
 http.begin(client, "URL or IP Address:port/RELAY1");

 int httpCode = http.GET();
 Serial.println(" ");
 Serial.println(httpCode);
 if (httpCode > 0) {
   if (httpCode == HTTP_CODE_OK) {
     digitalWrite(wificonnected, LOW);
     delay(500);
     digitalWrite(wificonnected, HIGH);
     payload = http.getString();

     Serial.println("payload");
     Serial.println(payload);

     Serial.println("payload-changed");

     //****for 4 outputs only 0-3 but could be 8 0-7****

     for (int a = 0; a <= 3 ; a++) {
       Serial.print(payload.charAt(a));
       load = (payload.charAt(a));
       delay(10);

       if ( a == 0) {
         slaverelay1();
       }
       else if ( a == 1) {
         slaverelay2();
       }
       else if ( a == 2) {
         slaverelay3();
       }
       else if ( a == 3) {
         slaverelay4();
       }
       else {
         Serial.println("Bad Payload");
       }


     }


   }
 } else {
   http.end();
   Serial.println(" ");
   Serial.println("Not Connected to Server");
 }
}



void slaverelay1()
{
 if (load == "0") {
   digitalWrite(output1, LOW);
 } else {
   digitalWrite(output1, HIGH);
 }

 return;
}

void slaverelay2()
{
 if (load == "0") {
   digitalWrite(output2, LOW);
 } else {
   digitalWrite(output2, HIGH);
 }

 return;
}

void slaverelay3()
{
 if (load == "0") {
   digitalWrite(output3, LOW);
 } else {
   digitalWrite(output3, HIGH);
 }

 return;
}

void slaverelay4()
{
 if (load == "0") {
   digitalWrite(output4, LOW);
 } else {
   digitalWrite(output4, HIGH);
 }

 return;
}