반응형

Key code for remote control

- Set WiFi library for ESP32 or ESP8266 NodeMcu

ESP32

#include <WiFi.h>      // wifi library for esp32
#include <WiFiClient.h>// access point library for esp32
#include <WiFiAP.h>    // access point library for esp32

WiFiServer server(80); // set port number 80
WiFiClient client;     // set wifi object

 

ESP8266 NodeMcu

#include <ESP8266WiFi.h> // wifi library for esp8266 with access point & client functions

WiFiServer server(80);   // set port number 80
WiFiClient client;       // set wifi object

 

- ACCESS POINT name and password setting for ESP-01

const char ssidAP[] = "Esp32";   // your network SSID (name)
const char passAP[] = "12345678"; //"1234test";         // your network password

 

- If you want to use the internal network through a router connection, set the name and password of the router that ESP32 or ESP8266 NodeMcu needs to connect to.

const char ssid[] = "skynet";    // "SK_WiFiGIGA40F7" your network SSID (name)
const char pass[] = "skynet00";  // "1712037218" your network password

 

- Function for data transmission via WiFi

void http_response() {
  Serial.println(Data);  // output sending data to serial monitor
  client.print(F("HTTP/1.1 200 OK\r\n\r\n")); // HTTP response Header
  client.println(Data);                // send data
  Data = "";
}

 

- Function to convert ip address to string

String toStringIp(IPAddress ip) {  
  String res = "";
  for (int i = 0; i < 3; i++) res += String((ip >> (8 * i)) & 0xFF) + ".";
  res += String(((ip >> 8 * 3)) & 0xFF);
  return res;
}

 

- setup() function

void setup() {
  Serial.begin(115200); // Set the baud rate for communication with the serial monitor of the Arduino IED to 115200
  if (wifiRouter) WiFi.mode(WIFI_AP_STA); // Access point and router connection mode setup (AP+STA)
  else WiFi.mode(WIFI_AP);                // only Access point mode
  WiFi.softAP(ssidAP, passAP);            // active Access point
  ap = toStringIp(WiFi.softAPIP());       // get ip of the Access point
  Serial.print(F("AP address: "));        // output ip of the Access point to serial monitor
  Serial.println(ap);
  if (wifiRouter) {                       // if use a router connection
    if (pass == "") WiFi.begin(ssid);     // if not set password of the router
    else WiFi.begin(ssid, pass);          // Connect to WPA/WPA2 network of the router
    uint8_t wifi_count = 0;
    while (WiFi.status() != WL_CONNECTED) { // need some time to connect to the router
          delay(200); Serial.print(F("."));
          wifi_count++;
          if (wifi_count == 50) break;
    }
    delay(10);
    ip = toStringIp(WiFi.localIP());      // get assigned IP
    Serial.print(F("IP address: "));      // output assigned IP to serial monitor
    Serial.println(ip);
  }
  server.begin();                         // start HTTP server
}

 

- loop() function to output all data received via WiFi

void loop() {
  client = server.available(); // Whether the server has data to receive and set now client
  String temp = "";
  while (client.connected()) { // Enter an infinite loop first to prevent re-execution of "client = server.available();"
    if(client.available()) {   // If the client has data
      if (client.peek() == '\n') char dump = client.read(); // dump '\n'
      else { 
        temp = client.readStringUntil('\r'); 
        Serial.println(temp);
        if (temp.startsWith(F("GET"))) { // message for response
          Data = "Hello World ";
          Data += random(100,200);
        }
      }
      if (temp.length() == 0) { http_response(); break; } // end of received data
    } else break;
  }
  delay(10); // time for sending data at wifi component of ESP32 
}

 

ESP32_WIFI_BASIC.zip

ESP32_WIFI_BASIC.zip
0.00MB

 

ESP8266_WIFI_BASIC.zip

ESP8266_WIFI_BASIC.zip
0.00MB

 

- Output of Serial Monitor after upload scketch "ESP32_WIFI_BASIC.ino"

 

Connecting directly to the ESP32 or NodeMcu and then connecting the access point

- Connect to ESP32 or NodeMcu on the WiFi Setting of a mobile phone.

- Input the Password for the ACCESS POINT of ESP01.

- Select "Keep WiFi on" if the message output below.

- Input the address "192.168.4.1/hi" on web browser.

received data of "192.168.4.1/hi" and favicon
Respons of HTTP from ESP32

 

Connecting to the assigned IP while ESP01 is connected to the router

- Input the assigned IP address "192.168.1.6" on web browser of PC connected to network of "skynet".

Respons of HTTP from ESP01
received data of "192.168.1.6" and favicon

 

 

 

[Arduino/ADUCON] - ESP32/NodeMcu WiFi remote control with ADUCON

[Arduino/ADUPAD] - ESP32/NodeMcu WiFi remote control with ADUPAD

 

[Arduino/ADUCON] - ADUCON - Arduino wireless remote control application

[Arduino/ADUPAD] - ADUPAD - Arduino wireless remote control PAD application

 

https://play.google.com/store/apps/details?id=com.tistory.postpop.hmi 

 

ADUCON - Google Play 앱

무선(WiFi/Bluetooth/BLE)을 통한 Arduino 원격 제어 앱

play.google.com

 

https://play.google.com/store/apps/details?id=io.kodular.skyship72.pad01 

 

ADUPAD - Google Play 앱

무선(WiFi/Bluetooth/BLE)을 통한 Arduino 원격 제어 PAD

play.google.com

 

+ Recent posts