반응형

If the baud rate of ESP01 is not set to 9600, refer to the post below to set it up.

Please refer to the post below for how to connect Arduino and ESP01.

[Arduino] - Setting up Wi-Fi module ESP01 and basic code for Arduino remote control

 

ADUCON application

 

BASIC CONNENTION TEST

Upload the sketches below to Arduino.

 

ARDUINO_ESP01_ADUCON_BASIC.zip

1.ARDUINO_ESP01_HMI_CONTROL.zip
0.01MB

 

- Modify the HTTP response code in loop() function according to the protocol for "TEXT" set in the ADUCON app.

if (gotData) { 
  Data = "%%F4";   // protocol header of text for ADUCON
  Data += "Hello World ";
  Data += random(100,200);
  Data += "%%F1";  // protocol footer of text for ADUCON
  Data += '\n';    // termination character of wifi for ADUCON
  Serial.println(Data); // Output the message to the serial monitor.
  http_response();
  gotData = false;
}

 

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

 

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

- Input the assigned IP address "192.168.1.7" on ADUCON app connected to network of "skynet".

received data of "%%F5" and "%%F8connect"
Respons of HTTP from ESP01

 

Connecting directly to the ESP01 and then connecting the access point

- Connect to ESP01 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" on ADUCON app connected to ESP01.

received data of "%%F5" and "%%F8connect"
Respons of HTTP from ESP01

 

 

Code for remote control with WiFi of ADUCON applications

In order to control Arduino from the app, there are basic Arduino codes for protocol-related functions that allow it to work with the app.

 

Each of these codes has its own functions and you need to understand what these functions do.

 

- wifi_read() function

1. Protocol header definition

ADUCON app's protocol header settings
ADUCON app's protocol header settings

Define the headers for Wifi in the Arduino sketch according to the protocol header settings in the ADUCON app.

#define pinHD F("%%F0")
#define pwmHD F("%%F3")
#define strHD F("%%F4")
#define footHD F("%%F1")
#define echoHD F("%%E1")
#define connectHD F("%%F8")
#define optionHD F("%%F9")
#define checkHD F("%%F5")
#define HDLen 4
#define addHD F("%%")
#define addHDLen 2

 

2. Code to check the connection attempt of ADUCON app

bool appConnection = false;

if (appConnection) { // If app connection is confirmed
  // Execute code after app connection is confirmed
} else { // Before app connection check
  if (income_wifi == checkHD) { // Check if the value is %%F5 and set the initial settings
    setFirstLogin(false); // Uncheck First Web Login (Do not use web login)
    detectLogout(false); // Uncheck Detect Logout (Do not use logout detection)
    showWebView(false); // Uncheck Web View (Do not display web view button)
    appConnection = true; http_response(); // Confirm the connection of ADUCOM
    if (connectionId != 48) { // Initialize ESP01 connection ID when connecting for the first time
      while (connectionId != 48) {
        connectionId--;
        String command = F("AT+CIPCLOSE=");
        command += String(connectionId-48);
        command += F("\r\n");
        esp01.print(command);
        delay(1);
      }
    }
  }
}

 

3. Handling of values according to connection header "connectHD(%%F8)"

%%F8 + connect: Transmit the necessary app settings and current Arduino state values through the iniSet() and sendState() functions

%%F8 + disconnect: Disconnect and change value of appConnection to false

%%F8 + WiFi: change WiFi setting values

if (income_wifi == F("connect")) { iniSet(); sendState(); }
else if (income_wifi == F("disconnect")) appConnection = false;  
else if (income_wifi.startsWith(F("WiFi"))) { sendMessage(F("This funtion is not available."));  }
else Serial.println(income_wifi);

 

4. Handling of values according to option header "optionHD(%%F9)"

void CheckF9(String temp) {
  Serial.println(temp);
  if (temp.startsWith(F("RAD"))) { } // if it starts with "RAD"
  else if (temp.startsWith(F("CKB"))) { } // if it starts with "CKB"
  else if (temp.startsWith(F("CHD"))) { } // if it starts with "CHD"
  else if (temp.startsWith(F("LSD"))) { } // if it starts with "LSD"
  else if (temp.startsWith(F("STR"))) { } // if it starts with "STR"
  else { // if not
    if (temp.length() < 10) Serial.println(F("alarm")); // set the time if the length of the value is less than 10
    else Serial.println(F("date/time")); // current date/time if larger
  }
}

 

5. Handling of values according to button header "pinHD(%%F0)"

// income_wifi: Value + %%F1 (with protocol header %%F0 removed)
ed = income_wifi.lastIndexOf(footHD); // check the index number where footHD(%%F1) starts in the value
if (ed != -1) {                       // if the index number is found in the value
  temp = income_wifi.substring(0, ed);//Extract data up to index number
  uint8_t value = temp.toInt();       // convert to numeric value
  pin_control(value);                 // execute the code corresponding to the value
}

 

6. Handling of values according to SeekBar(slide bar) header "pwmHD(%%F3)"

// income_wifi: %%F3 + Count + %% + Slide Num + Value + %%F1
// Example of 3 values of COLOR PICKER: %%F31%%1255%%F1%%F31%%2133%%F1%%F31%%3123%%F1
ed = income_wifi.indexOf(addHD, HDLen); // Starting index of "%%" after HDLen 4(%%F3)
temp = income_wifi.substring(HDLen, ed); // Extract values from after HDLen 4(%%F3) to before "%%"
int count = temp.toInt(); // convert to numeric value
bool ok = true;
if (count == 0) pwmCount = 0; // If count is 0, reset counter for data verification
if (count < pwmCount) ok = false; // Verify if the data is continuous
else pwmCount = count;
if (ok) { // If data is continuous (unless data is missing due to Wi-Fi connection)
  uint8_t slide = 0; uint16_t value = 0;
  while(income_wifi.indexOf(footHD) != -1) { // Process 3 PWM values of COLOR PICKER
    ed = income_wifi.indexOf(addHD, HDLen)+addHDLen;
    income_wifi. remove(0, ed);
    temp = income_wifi.substring(0, 1);
    slide = temp. toInt();
    ed = income_wifi. indexOf(footHD);
    temp = income_wifi.substring(1, ed);
    value = temp. toInt();
    income_wifi.remove(0, ed+HDLen);
    pwm_control(slide, value);
  }
}

 

Protocol function to send data from Arduino to app

1. Change the state of the button.

void sendPinState(uint8_t pin_val){  
  Data += pinHD;
  Data += pin_val;
  Data += footHD;
  Data += '\n';
}

 

2. Transmits an echo for the received value of the button.

void sendPinEcho(uint8_t pin_val){  
  Data += pinHD;
  Data += pin_val;
  Data += echoHD;
  Data += '\n';
}

 

3. Change the slide state of the app.

void sendPwmSlide(uint8_t slide, uint16_t pwm_val) {                      
  Data += pwmHD;
  Data += slide;
  Data += pwm_val;
  Data += footHD;
  Data += '\n';
}

 

4. Transmits the echo for the received value of the PWM.

void sendPwmEcho(uint8_t slide, uint16_t pwm_val) {                          
  Data += pwmHD;
  Data += slide;
  Data += pwm_val;
  Data += echoHD;
  Data += '\n';
}

 

- A code example that reflects the status of the current button and PWM values of Arduino to the app when connected to the ADUCON app

// SEND LOCAL STATE AT PRESENT TO APP
void sendState() { 
  sendPinState(10);
  sendPinState(21);
  sendPinState(30);
  sendPinState(41);
  sendPinState(50);
  sendPinState(61);
  sendPinState(71);
  sendPinState(80);
  sendPinState(91);
  sendPinState(101);
  sendPinState(110);
  sendPinState(121);
  sendPinState(130);
  sendPinState(141);
  sendPinState(150);
  sendPwmSlide(1, 110);
  sendPwmSlide(2, 120);
  sendPwmSlide(3, 210);
}

Screen reflecting initial state and labels when connecting Arduino
Screen reflecting initial state and labels when connecting Arduino

 

5. Send text.

void sendText(String text) {                               
  Data += strHD;
  Data += text;
  Data += footHD;
  Data += '\n';
}

 

6. If web login is implemented using the HTML code in Arduino sketch, set to move to the login page when connecting for the first time.

void setFirstLogin(bool val){ 
  Data += connectHD;
  Data += F("FIR:");
  Data += val;
  Data += '\n';
}

7. If the control authority is released by a new web login, the Logout status is output as a message.

In case of connecting to the ACCESS POINT (ex. 192.168.4.1) - Administrator

When connecting via web login from the internal network through a router - General user

General user can be disengaged (pushed) by Administrator or another General user.

void detectLogout(bool val){ 
  Data += connectHD;
  Data += F("DET:");
  Data += val;
  Data += '\n';
}

 

8. Set to send the date/time of the Android system When connecting, or request the transmission of the date/time if necessary.

void requstDateTime(){ 
  Data += connectHD;
  Data += F("RDT:"); 
  Data += '\n';
}

 

9. Use when you want to acquire control authority by using the ACCESS POINT password of the module in the internal network connection through the router. (without using HTML web login)

It can be changed to any name through definition of the passName and passNameLen for processing the password in the sketch and the app send datas starting with passName as password value. This is to enhance security.

#define passName F("PAS:")
#define passNameLen 4

void requestPass(bool val){ 
  Data += connectHD;
  Data += val;
  Data += passName;
  Data += '\n';
}

Password dialog
Password dialog

 

10. If control authority is given through password confirmation, a cookie value is created and transmitted so that control authority for the data transmitted thereafter can be confirmed.

#define cooLength 5
String cooValue = "u7Dv0";

String makeCooValue() {
  cooValue = "";
  uint8_t temp = 0;
  for (int i = 0; i < cooLength; i++) {
    temp = random(39, 123); //random(39, 123); // 39 ~ 122 pick
    if (temp == 47 || temp == 59 || temp == 60 || temp == 62 || temp == 92 || temp == 94 || temp == 96) temp = 79;
    cooValue += char(temp);
  }
  Serial.print("coo: "); Serial.println(cooValue);
  return cooValue;
}

void responsePass(bool val){ 
  Data += connectHD;
  Data += F("RES:");
  if (val) Data += makeCooValue(); 
  else Data += val;
  Data += '\n';
}

 

11. Sends information about the current Wi-Fi connection so that the user can view and edit information in the app about the Wi-Fi connection.

void sendWifiInfo(){ 
  Data += connectHD;
  Data += F("INF:");
  Data += ssidAP;
  Data += ',';
  Data += passAP;
  Data += ',';
  Data += ap;
  Data += ',';
  Data += wifiRouter;
  Data += ',';
  Data += ssid;
  Data += ',';
  Data += pass;
  Data += ',';
  Data += ip;
  Data += '\n';
}

 

12. Outputs the message in the form of a pop-up.

void sendMessage(String str){ 
  Data += connectHD;
  Data += F("MES:");
  Data += str;
  Data += '\n';
}

 

13. Disable the feature, which is default setting, of automatically resend the value When a button or SeekBar (slide bar) is changed in the app and then if a response failure error occurs.

It is used when the Arduino intentionally does not respond due to the delay that occurs when sending data using the AT command to the ESP01.

void responseFailResend(bool val) {
  Data += connectHD;
  Data += F("RFR:");
  Data += val;
  Data += '\n';
}

 

14. Instruct the app to click the Disconnect Button.

void sendDisconnect(){ 
  Data += connectHD;
  Data += F("DIS");
  Data += '\n';
}

연결 해제 버튼
Disconnect Button for WiFi

 

15. Set the function to continuously transmit the changed value of the SeekBar (slide bar) according to the specified interval.

true: Active Slide Mode

false: Passive Slide Mode (transmits only values when the slide bar is touched up)

void setActiveSlide(bool val){ 
  Data += optionHD;
  Data += F("ACT:");
  Data += val;
  Data += '\n';
}

 

16. Set transmission interval of ACTIVE SLIDE MODE. (Unit: Millisecond)

void setSlideInterval(uint16_t val){ 
  Data += optionHD;
  Data += F("SLI:");
  Data += val;
  Data += '\n';
}

 

17. Activate a timer that sends checkHD(%%F5) at regular time intervals.

Regardless of the app, it is used to reflect independently changed values in the Arduino to the app.

void setRequest(bool val){ 
  Data += optionHD;
  Data += F("REQ:");
  Data += val;
  Data += '\n';
}

 

18. Set the operation interval of the timer sending checkHD(%%F5). (Unit: Millisecond)

void setRequestInterval(uint16_t val){ 
  Data += optionHD;
  Data += F("INT:");
  Data += val;
  Data += '\n';
}

 

19. Set the operation function when clicking the label displaying the current connection status.

0: No function.

1: Show only connection information when it clicked.

2: Show connection information and password when it clicked so that the connection and password can be set.

// 0: not use, 1: show only name, 2: show name & pass // defalult: 2
void setSSIDLabelMode(uint8_t val) { 
  Data += optionHD;
  Data += F("SLM:");
  Data += val;
  Data += '\n';
}

 

20. Display the button to go to the webview page where you can see the HTML Page coded in Arduino.

void showWebView(bool val){ 
  Data += optionHD;
  Data += F("SWV:"); 
  Data += val;
  Data += '\n';
}

 

21. Display additional push buttons in the main menu area. (it is possible to control only at Arduino)

void showDialogMenu(bool val){ 
  Data += optionHD;
  Data += F("SDM:"); 
  Data += val;
  Data += '\n';
}

 

22. Change the main screen to Color Picker / Pwm Nob screen from Arduino. (generally set in the options of the app)

uint8_t: list below

0: Display buttons and SeekBar (slide bar) on the main screen

1: Display Color_Picker on the main screen.

2: Display Color_Picker and Group 2 on the main screen.

3: Display PWM Nob on the main screen.

4: Display PWM Nob and Group 2 on the main screen.

String: name of the group

bool: Sets whether to display the SeekBar (slide bar) when the main screen buttons are displayed.

* true: SeekBar (slide bar) is also displayed when button is displayed or Pwm Nob is displayed

* false: SeekBar (slide bar) is not displayed when button is displayed and SeekBar (slide bar) is displayed only when Pwm Nob is displayed

//0: not use 1:color picke 2:color picker+add group 3: pwm nob 4: pwm nob+add group, group1 & group2 Label
void setColorNob(uint8_t val, String group1, String group2, bool pwmDPMain) { 
  Data += optionHD;
  Data += F("CNB:");
  Data += String(val); Data += ','; 
  Data += group1; Data += ','; 
  Data += group2; Data += ','; 
  Data += pwmDPMain;
  Data += '\n';
}

 

23. Set the main screen display of the app.

Set to 0 or 1 in order depending on whether buttons 1 to 15, SeekBar (slide bar) 1 to 6, text input, and floating buttons are displayed.

0: hidden 1: visible

///////////////////////// SET MAIN DISPLAY 0:hide 1:display
//F("111111111111111"  // button 1 ~ 15
//  "111111"           // slider 1 ~ 6
//  "11")              // Text Input/Floating Button
void setDisplay(String str){ 
  Data += optionHD;
  Data += F("SDP:");
  Data += str;
  Data += '\n';
}

 

24. Set labels for buttons and SeekBar.

Label buttons 1 to 15 and SeekBar (slide bar) 1 to 6 in order using ',' as a separator.

//F("BT1,BT2,BT3,BT4,BT5,BT6,BT7,BT8,BT9,BT10,BT11,BT12,BT13,BT14,BT15," // button 1 ~ 15
//  "PW1,PW2,PW3,PW4,PW5,PW6") // slider 1 ~ 6
void setButtonLabel(String str){ 
  Data += optionHD;
  Data += F("ABL:");
  Data += str;
  Data += '\n';
}

 

25. Set the button's toggle/push properties.

Set the button properties to 0 or 1 in order of buttons 1 to 15.

0: Push 1: Toggle

//F("111111111111111") // button 1 ~ 15, 0:push 1:toggle 
void setButtonToggle(String str){ 
  Data += optionHD;
  Data += F("BTG:");
  Data += str;  
  Data += '\n';
}

 

26. Set the maximum/minimum values of the SeekBar (slide bar).

SeekBar (slide bar) Specifies the maximum/minimum values from 1 to 6 in order using ',' as a separator.

//F("0,255,0,255,0,255,0,255,0,255,0,255")
void setMinMax(String str){ 
  Data += optionHD;
  Data += F("MNM:");
  Data += str;
  Data += '\n';
}

 

27. Set the title of the Arduino sketch.

//title: Test Mode
//text: Arduino<br/>- WiFi Controler<br/><br/>Manual<br/><a href='https://postpop.tistory.com/8'>https://postpop.tistory.com/8</a>
void setAppTitleMessage(String title, String text){
  Data += optionHD;
  Data += F("ATM:"); 
  Data += title; Data += ','; 
  Data += text; 
  Data += '\n';
}

 

28. Dialog Message: radio button

// option = "A,B,C" -> selection index = 1(A) ~ 3(C)
void dialogRadio(uint8_t id, String title, String option, uint8_t selection){ 
  Data += optionHD;
  Data += F("RAD:"); 
  Data += String(id); Data += ':';
  Data += title; Data += ':';
  Data += option; Data += ':';
  Data += String(selection);
  Data += '\n';
} // Return -> RAD:0:1(index) , RAD:id:option index

 

29. Dialog Message: Checkbox

// option = "A,B,C"
void dialogCheckbox(uint8_t id, String title, String option){ 
  Data += optionHD;
  Data += F("CKB:"); 
  Data += String(id); Data += ':';
  Data += title; Data += ':';
  Data += option; 
  Data += '\n';
} // Return -> CKB:0:1,3(index) , CKB:id:option index

 

30. Dialog Message: Select button

// option = "A,B"
void dialogChoose(uint8_t id, String message, String option){ 
  Data += optionHD;
  Data += F("CHD:"); 
  Data += String(id); Data += ':'; 
  Data += message; Data += ':'; 
  Data += option; 
  Data += '\n';
} // Return -> CHD:0:B , CHD:id:option str

 

31. Dialog Message: List Window

// option = "A,B,C,D,E,F,G,H"
void dialogList(uint8_t id, String title, String option){ 
  Data += optionHD;
  Data += F("LSD:"); 
  Data += String(id); Data += ':';
  Data += title; Data += ':'; 
  Data += option; 
  Data += '\n';
} // Return -> LSD:0:F , LSD:id:option str

 

32. Dialog Message: Input text

void dialogInput(uint8_t id, String title){ 
  Data += optionHD;
  Data += F("STR:"); 
  Data += String(id); Data += ':'; 
  Data += title; 
  Data += '\n';
} // Return -> STR:0:str , STR:id:str

 

1.ARDUINO_ESP01_HMI_CONTROL.zip

1.ARDUINO_ESP01_HMI_CONTROL.zip
0.01MB

https://youtu.be/Sn46at1o7_U

 

Main sketch

더보기
#include <SoftwareSerial.h>
#define rxPin 3 
#define txPin 2 
SoftwareSerial esp01(txPin, rxPin); // SoftwareSerial NAME(RX, TX);

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

bool wifiRouter = true;          // Whether or not there is a router connection
const char ssid[] = "skynet";    // "SK_WiFiGIGA40F7" your network SSID (name)
const char pass[] = "skynet00";  // "1712037218" your network password 

String ap = "";
String ip = "";

String Data = "";
#include "protocol.h"

#define ledPin 13

void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  Serial.begin(9600);
  esp01.begin(9600); // your esp's baud rate might be different
  sendData(F("RST")); 
  unsigned long int time = millis();
  String temp = "";
  while (time+20000 > millis()) {
    temp = esp01.readStringUntil('\n');
    if (temp.indexOf(F("ready")) != -1) { Serial.println(F("Set")); break; }
  }
  if (wifiRouter) sendData(F("CWMODE=3")); // configure as access point (working mode: AP+STA)
  else sendData(F("CWMODE=2"));
  if (wifiRouter) sendData(F("CWDHCP=1,1"));
  sendData(addID(F("CWSAP="),ssidAP,passAP)+','+String(10)+','+String(3)); 
  sendData(F("CIPMUX=1")); // configure for multiple connections
  sendData(F("CIPSERVER=1,80")); // turn on server on port 80
  if (wifiRouter) {
    retry = 1;
    while(retry) { 
      sendData(addID(F("CWJAP="),ssid,pass)); 
      if (retry > 1) { Serial.print(F("Retrying to connect: ")); Serial.println(retry-1); }
      if (retry > 4) { Serial.println(F("connection failed")); retry = 0; }
    }
  }
  ipCheck(sendData(F("CIFSR"))); // get ip address
}

void pin_control(uint8_t value) {
  if (value != 0) {
    switch (value) {
      case 11: Serial.println(F("button 1 : on"));
               digitalWrite(ledPin, HIGH); 
               sendPinEcho(value);
               sendText(F("1: ON"));  
                  break;
      case 10: Serial.println(F("button 1 : off"));
               digitalWrite(ledPin, LOW); 
               sendText(F("1: OFF")); 
               sendPinEcho(value);
                  break;
      case 21: Serial.println(F("button 2 : on"));
                  break;
      case 20: Serial.println(F("button 2 : off"));
                  break;
      case 31: Serial.println(F("button 3 : on"));
                  break;
      case 30: Serial.println(F("button 3 : off"));
                  break;
      case 41: Serial.println(F("button 4 : on"));
                  break;
      case 40: Serial.println(F("button 4 : off"));
                  break;
      case 51: Serial.println(F("button 5 : on"));
                  break;
      case 50: Serial.println(F("button 5 : off"));
                  break;
      case 61: Serial.println(F("button 6 : on"));
                  break;
      case 60: Serial.println(F("button 6 : off"));
                  break;
      case 71: Serial.println(F("button 7 : on"));
                  break;
      case 70: Serial.println(F("button 7 : off"));
                  break;
      case 81: Serial.println(F("button 8 : on"));
                  break;
      case 80: Serial.println(F("button 8 : off"));
                  break;
      case 91: Serial.println(F("button 9 : on"));
                  break;
      case 90: Serial.println(F("button 9 : off"));
                  break;  
      case 101: Serial.println(F("button 10 : on"));
                  break;
      case 100: Serial.println(F("button 10 : off"));
                  break;  
      case 111: Serial.println(F("button 11 : on"));
                  break;
      case 110: Serial.println(F("button 11 : off"));
                  break;  
      case 121: Serial.println(F("button 12 : on"));
                  break;
      case 120: Serial.println(F("button 12 : off"));
                  break;                  
      case 131: Serial.println(F("button 13 : on"));
                  break;  
      case 130: Serial.println(F("button 13 : off"));
                  break;  
      case 141: Serial.println(F("button 14 : on"));
                  break;  
      case 140: Serial.println(F("button 14 : off"));
                  break;  
      case 151: Serial.println(F("button 15 : on"));
                  break;  
      case 150: Serial.println(F("button 15 : off"));
                  break;         
      case 161: Serial.println(F("button 16 : click"));
                  break; 
      case 171: Serial.println(F("button 17 : click"));
                  break;
      case 181: Serial.println(F("button 18 : click"));
                  break;  
      case 191: Serial.println(F("button 19 : click"));
                  break;  
      case 201: Serial.println(F("button 20 : click"));
                  break;         
    }
  }
}

void pwm_control(uint8_t num, uint16_t value) {
  if (num == 1) {  // SeekBar (slide bar) 1
    sendText(String(value));  
    sendPwmEcho(num, value); // ESP01: recommend at passive slide mode
    Serial.print(F("pwm1: ")); Serial.println(value);
  } else if (num == 2) {  // SeekBar (slide bar) 2
    sendPwmEcho(num, value); // ESP01: recommend at passive slide mode
    Serial.print(F("pwm2: ")); Serial.println(value);
  } else if (num == 3) {  // SeekBar (slide bar) 3
    sendPwmEcho(num, value); // ESP01: recommend at passive slide mode
    Serial.print(F("pwm3: ")); Serial.println(value);
  } else if (num == 4) {  // SeekBar (slide bar) 4
    Serial.print(F("pwm4: ")); Serial.println(value);
  } else if (num == 5) {  // SeekBar (slide bar) 5
    Serial.print(F("pwm5: ")); Serial.println(value);
  } else if (num == 6) {  // SeekBar (slide bar) 6
    Serial.print(F("pwm6: ")); Serial.println(value);
  }
}

bool appConnection = false;
String income_wifi = ""; // storage variable for received string with WiFi
uint16_t pwmCount = 2;

void wifi_read() {
  while (esp01.available()) { 
    income_wifi = esp01.readStringUntil('\n');
    if (income_wifi.startsWith(F("+IPD"))) {
      income_wifi.remove(0,5);
      connectionId = income_wifi.charAt(0);
      int st = income_wifi.indexOf(F("GET /"))+5;
      income_wifi.remove(0,st);
      if (!income_wifi.startsWith(F("fav"))) { // it pass favicon.ico
        int ed = income_wifi.lastIndexOf(F("HTTP/1.1"));
        income_wifi.remove(ed-1);
        if (appConnection) { 
          String temp = income_wifi.substring(0, HDLen);
          uint8_t order = 0;
          if (temp == checkHD) order = 1;
          else if (temp == pwmHD) order = 2;
          else if (temp == pinHD) order = 3;
          else if (temp == connectHD) order = 4;
          else if (temp == optionHD) order = 5; 
          if (order > 2) income_wifi.remove(0, HDLen); // Remove protocol header
          if (order == 1) { // %%F5
            
          } else if (order == 2) { // %%F3
            ed = income_wifi.indexOf(addHD, HDLen);
            temp = income_wifi.substring(HDLen, ed);
            int count = temp.toInt();
            bool ok = true;
            if (count == 0) pwmCount = 0;
            if (count < pwmCount) ok = false;
            else pwmCount = count;
            if (ok) {
              uint8_t slide = 0; uint16_t value = 0;
              while(income_wifi.indexOf(footHD) != -1) {
                ed = income_wifi.indexOf(addHD, HDLen)+addHDLen;
                income_wifi.remove(0, ed);
                temp = income_wifi.substring(0, 1);
                slide = temp.toInt();
                ed = income_wifi.indexOf(footHD);
                temp = income_wifi.substring(1, ed);
                value = temp.toInt();
                income_wifi.remove(0, ed+HDLen);
                pwm_control(slide, value);
              }
            } 
          } else if (order == 3) { // %%F0
            ed = income_wifi.lastIndexOf(footHD);
            if (ed != -1) {
              temp = income_wifi.substring(0, ed);
              uint8_t value = temp.toInt();
              pin_control(value);
            }
          } else if (order == 4) { // %%F8
            if (income_wifi == F("connect")) { iniSet(); sendState(); }
            else if (income_wifi == F("disconnect")) appConnection = false;  
            else if (income_wifi.startsWith(F("WiFi"))) { sendMessage(F("This funtion is not available."));  }
            else Serial.println(income_wifi);
          } else if (order == 5) { // %%F9
            income_wifi.replace(F("%20"), F(" ")); // URL Encoding space character change
            CheckF9(income_wifi);
          } else { // order == 0
            income_wifi.replace(F("%20"), F(" ")); // URL Encoding space character change
            Serial.println(income_wifi);
          }
          http_response();
        } else {
          if (income_wifi == checkHD) { 
            setFirstLogin(false); detectLogout(false); showWebView(false); 
            appConnection = true; http_response(); 
            if (connectionId != 48) {
              while (connectionId != 48) { 
                connectionId--;
                String command = F("AT+CIPCLOSE=");
                command += String(connectionId-48);
                command += F("\r\n");
                esp01.print(command);
                delay(1);
              } 
            }
          }
        }
      }
      income_wifi = "";
    }
  }      
}     
 
void loop() {
  wifi_read();
  if(Serial.available() > 0){ // if there is data in the serial buffer
    String temp = Serial.readStringUntil('\n');
    Serial.println(temp);
    if (temp.startsWith(F("AT"))) {
      temp.remove(0,3);
      Serial.println(temp);
      sendData(temp);
    } else if (temp == F("1")) {
      
    } else if (temp == F("2")) {
      
    } 
  }
}

 

Protocol sketch

더보기
//////////////////////////////////////////////////////////// COMMON
///////////////////////////////////////// ESSENTIAL 
#define pinHD F("%%F0")
#define pwmHD F("%%F3")
#define strHD F("%%F4")
#define footHD F("%%F1")
#define echoHD F("%%E1")
#define connectHD F("%%F8")
#define optionHD F("%%F9")
#define checkHD F("%%F5")
#define HDLen 4
#define addHD F("%%")
#define addHDLen 2

// SEND PIN VALUE
void sendPinState(uint8_t pin_val){  
  Data += pinHD;
  Data += pin_val;
  Data += footHD;
  Data += '\n';
}

// SEND PIN ECHO
void sendPinEcho(uint8_t pin_val){  
  Data += pinHD;
  Data += pin_val;
  Data += echoHD;
  Data += '\n';
}

// SEND SLIDE VALUE - USE AT PASSIVE SLIDE MODE
void sendPwmSlide(uint8_t slide, uint16_t pwm_val) {                      
  Data += pwmHD;
  Data += slide;
  Data += pwm_val;
  Data += footHD;
  Data += '\n';
}

// SEND SLIDE ECHO - ESP01: USE AT PASSIVE SLIDE MODE
void sendPwmEcho(uint8_t slide, uint16_t pwm_val) {                          
  Data += pwmHD;
  Data += slide;
  Data += pwm_val;
  Data += echoHD;
  Data += '\n';
}

// SEND TEXT
void sendText(String text) {                               
  Data += strHD;
  Data += text;
  Data += footHD;
  Data += '\n';
}

///////////////////////////////////////// CONNECTION 
void setFirstLogin(bool val){ 
  Data += connectHD;
  Data += F("FIR:");
  Data += val;
  Data += '\n';
}

void detectLogout(bool val){ 
  Data += connectHD;
  Data += F("DET:");
  Data += val;
  Data += '\n';
}

void requstDateTime(){ 
  Data += connectHD;
  Data += F("RDT:"); 
  Data += '\n';
}

//#define passName F("PAS:")
//#define passNameLen 4
//
//void requestPass(bool val){ 
//  Data += connectHD;
//  Data += val;
//  Data += passName;
//  Data += '\n';
//}
//
//#define cooLength 5
//String cooValue = "u7Dv0";
//
//String makeCooValue() {
//  cooValue = "";
//  uint8_t temp = 0;
//  for (int i = 0; i < cooLength; i++) {
//    temp = random(39, 123); //random(39, 123); // 39 ~ 122 pick
//    if (temp == 47 || temp == 59 || temp == 60 || temp == 62 || temp == 92 || temp == 94 || temp == 96) temp = 79;
//    cooValue += char(temp);
//  }
//  Serial.print("coo: "); Serial.println(cooValue);
//  return cooValue;
//}
//
//void responsePass(bool val){ 
//  Data += connectHD;
//  Data += F("RES:");
//  if (val) Data += makeCooValue(); 
//  else Data += val;
//  Data += '\n';
//}

void sendWifiInfo(){ 
  Data += connectHD;
  Data += F("INF:");
  Data += ssidAP;
  Data += ',';
  Data += passAP;
  Data += ',';
  Data += ap;
  Data += ',';
  Data += wifiRouter;
  Data += ',';
  Data += ssid;
  Data += ',';
  Data += pass;
  Data += ',';
  Data += ip;
  Data += '\n';
}

void sendMessage(String str){ 
  Data += connectHD;
  Data += F("MES:");
  Data += str;
  Data += '\n';
}

// defalt: true
void responseFailResend(bool val) {
  Data += connectHD;
  Data += F("RFR:");
  Data += val;
  Data += '\n';
}

void sendDisconnect(){ 
  Data += connectHD;
  Data += F("DIS");
  Data += '\n';
}

///////////////////////////////////////// OPTION
///////////////////////// SET FUNCION
void setActiveSlide(bool val){ 
  Data += optionHD;
  Data += F("ACT:");
  Data += val;
  Data += '\n';
}

void setSlideInterval(uint16_t val){ 
  Data += optionHD;
  Data += F("SLI:");
  Data += val;
  Data += '\n';
}

void setRequest(bool val){ 
  Data += optionHD;
  Data += F("REQ:");
  Data += val;
  Data += '\n';
}

void setRequestInterval(uint16_t val){ 
  Data += optionHD;
  Data += F("INT:");
  Data += val;
  Data += '\n';
}

// 0: not use, 1: show only name, 2: show name & pass // defalult: 2
void setSSIDLabelMode(uint8_t val) { 
  Data += optionHD;
  Data += F("SLM:");
  Data += val;
  Data += '\n';
}

void showWebView(bool val){ 
  Data += optionHD;
  Data += F("SWV:"); 
  Data += val;
  Data += '\n';
}

void showDialogMenu(bool val){ 
  Data += optionHD;
  Data += F("SDM:"); 
  Data += val;
  Data += '\n';
}

//0: not use 1:color picke 2:color picker+add group 3: pwm nob 4: pwm nob+add group, group1 & group2 Label
void setColorNob(uint8_t val, String group1, String group2, bool pwmDPMain) { 
  Data += optionHD;
  Data += F("CNB:");
  Data += String(val); Data += ','; 
  Data += group1; Data += ','; 
  Data += group2; Data += ','; 
  Data += pwmDPMain;
  Data += '\n';
}

///////////////////////// SET MAIN DISPLAY
//F("111111111111111"  // button 1 ~ 15, 0:hide 1:display
//  "111111"           // slider 1 ~ 6
//  "11")              // Text Input/Floating Button
void setDisplay(String str){ // must after setLeftPadMode(uint8_t val)
  Data += optionHD;
  Data += F("SDP:");
  Data += str;
  Data += '\n';
}

//F("BT1,BT2,BT3,BT4,BT5,BT6,BT7,BT8,BT9,BT10,BT11,BT12,BT13,BT14,BT15," // button 1 ~ 15
//  "PW1,PW2,PW3,PW4,PW5,PW6") // slider 1 ~ 6
void setButtonLabel(String str){ 
  Data += optionHD;
  Data += F("ABL:");
  Data += str;
  Data += '\n';
}

//F("111111111111111") // button 1 ~ 15, 0:push 1:toggle 
void setButtonToggle(String str){ 
  Data += optionHD;
  Data += F("BTG:");
  Data += str;  
  Data += '\n';
}

//F("0,255,0,255,0,255,0,255,0,255,0,255")
void setMinMax(String str){ 
  Data += optionHD;
  Data += F("MNM:");
  Data += str;
  Data += '\n';
}

void setAppTitleMessage(String title, String text){
  Data += optionHD;
  Data += F("ATM:"); 
  Data += title; Data += ','; 
  Data += text; 
  Data += '\n';
}

///////////////////////// PERFORM DIALOG
// option = "A,B,C" -> index = 1(A) ~ 3(C)
void dialogRadio(uint8_t id, String title, String option, uint8_t selection){ 
  Data += optionHD;
  Data += F("RAD:"); 
  Data += String(id); Data += ':';
  Data += title; Data += ':';
  Data += option; Data += ':';
  Data += String(selection);
  Data += '\n';
} // Return -> RAD:0:1(index) , RAD:id:option index

// option = "A,B,C"
void dialogCheckbox(uint8_t id, String title, String option){ 
  Data += optionHD;
  Data += F("CKB:"); 
  Data += String(id); Data += ':';
  Data += title; Data += ':';
  Data += option; 
  Data += '\n';
} // Return -> CKB:0:1,3(index) , CKB:id:option index

// option = "A,B"
void dialogChoose(uint8_t id, String message, String option){ 
  Data += optionHD;
  Data += F("CHD:"); 
  Data += String(id); Data += ':'; 
  Data += message; Data += ':'; 
  Data += option; 
  Data += '\n';
} // Return -> CHD:0:B , CHD:id:option str

// option = "A,B,C,D,E,F,G,H"
void dialogList(uint8_t id, String title, String option){ 
  Data += optionHD;
  Data += F("LSD:"); 
  Data += String(id); Data += ':';
  Data += title; Data += ':'; 
  Data += option; 
  Data += '\n';
} // Return -> LSD:0:F , LSD:id:option str 

void dialogInput(uint8_t id, String title){ 
  Data += optionHD;
  Data += F("STR:"); 
  Data += String(id); Data += ':'; 
  Data += title; 
  Data += '\n';
} // Return -> STR:0:str , STR:id:str

//////////////////////////////////////////////////////////// INDIVIDUAL
void iniSet() {
  setButtonLabel(F("BT1,BT2,BT3,BT4,BT5,BT6,BT7,BT8,BT9,BT10,BT11,"
                   "BT12,BT13,BT14,BT15,PW1,PW2,PW3,PW4,PW5,PW6"));
  setButtonToggle(F("111111111111111")); // button 1 ~ 15, 0:push 1:toggle    
  setRequest(false); //setRequestInterval(2000);
  setActiveSlide(false); //setSlideInterval(100);
}

// SEND LOCAL STATE AT PRESENT TO APP
void sendState() { 
  sendPinState(10);
  sendPinState(21);
  sendPinState(30);
  sendPinState(41);
  sendPinState(50);
  sendPinState(61);
  sendPinState(71);
  sendPinState(80);
  sendPinState(91);
  sendPinState(101);
  sendPinState(110);
  sendPinState(121);
  sendPinState(130);
  sendPinState(141);
  sendPinState(150);
  sendPwmSlide(1, 110);
  sendPwmSlide(2, 120);
  sendPwmSlide(3, 210);
}

void ipCheck(String response) {
  int st, ed;
  if (response.indexOf(F("PIP")) != -1) {
    st = response.indexOf(F("PIP"))+5;
    ed = response.indexOf('"', st+1);
    ap = response.substring(st, ed);
    response.remove(0, ed+1);
    Serial.print(F("ap: ")); Serial.println(ap);
  }
  if (response.indexOf(F("AIP")) != -1) {
    st = response.indexOf(F("AIP"))+5;
    ed = response.indexOf('"', st+1);
    ip = response.substring(st, ed);
    Serial.print(F("ip: ")); Serial.println(ip);
  }
}

uint8_t retry = 1;

String sendData(String order) {
  String command = F("AT+");
  command += order;
  command += F("\r\n");
  esp01.print(command); // send the read character to the esp01
  long int time = millis();
  String response = "";
  while( (time+20000) > millis()) {
    while(esp01.available()) {  // The esp has data so display its output to the serial window
      char c = esp01.read(); // read the next character.
      response+=c;
    }
    if (response.indexOf(F("OK")) != -1) { retry = 0; Serial.println(F("OK")); break; } 
    else if (response.indexOf(F("FAIL")) != -1 || response.indexOf(F("ERROR")) != -1) { 
      if (response.indexOf(F("FAIL")) != -1) retry++;
      else if (response.indexOf(F("ERROR")) != -1) { Serial.println(F("ERROR")); break; } 
      Serial.print(command); Serial.println(F("Failed")); break; 
    }
  }
  return response;
}

String addID(String order, String ssid_AP, String pass_AP) {
  String temp = order+'"'+ssid_AP+'"'+','+'"'+pass_AP+'"';
  return temp;
}

uint8_t connectionId = 48; // storage variable for connection ID 

void http_response() {
  String cip = F("AT+CIPSEND=");
  cip += connectionId-48;
  cip += ',';
  cip += Data.length()+19;
  cip += F("\r\n");
  esp01.print(cip);
  unsigned long int time = millis();
  while (time+2000 > millis()) {
    cip = esp01.readStringUntil('\n');
    if (cip.indexOf(F("OK")) != -1) { break; }
  }
  esp01.print(F("HTTP/1.1 200 OK\r\n\r\n")); // +19
  esp01.print(Data);
  time = millis();
  while (time+2000 > millis()) {
    cip = esp01.readStringUntil('\n');
    if (cip.indexOf(F("OK")) != -1) { break; }
  }
  Data = "";
  String command = F("AT+CIPCLOSE=");
  command += String(connectionId-48);
  command += F("\r\n");
  esp01.print(command);
}

void CheckF9(String temp) {
  Serial.println(temp);
  if (temp.startsWith(F("RAD"))) {  }
  else if (temp.startsWith(F("CKB"))) {  }
  else if (temp.startsWith(F("CHD"))) {  }
  else if (temp.startsWith(F("LSD"))) {  }
  else if (temp.startsWith(F("STR"))) {  }
  else {  
    if (temp.length() < 10) Serial.println(F("alarm"));
    else Serial.println(F("date/time"));
  }
}

 

Example of using Protocol to set ADUCON app

- ADUCON app settings: label/toggle properties, use of the timer for checkHD(%%F5), Slide Mode settings, etc.

void iniSet() {
  setDisplay(F("111111111111111" // button 1 ~ 15, 0:hide 1:display
               "111111"          // slider 1 ~ 6
               "11"));           // Text Input/Floating Button
  setColorNob(0, F("GR1"), F("GR2"), false); // Set Color Picker and Pwm Nob
  setButtonLabel(F("BT1,BT2,BT3,BT4,BT5,BT6,BT7,BT8,BT9,BT10,BT11," // set labels
                   "BT12,BT13,BT14,BT15,PW1,PW2,PW3,PW4,PW5,PW6"));
  setButtonToggle(F("111111111111111")); // button 1 ~ 15, toggle setting, 0:push 1:toggle
  setMinMax(F("0,255,0,255,0,255,0,255,0,255,0,255")); // slider 1 to 6
  setAppTitleMessage(F("Test Mode"), // Change title for Arduino code on the app
  F("Arduino<br/>- WiFi Controler<br/><br/>Manual<br/>" //Message
    "<a href='https://postpop.tistory.com/8'>"
    "https://postpop.tistory.com/8</a>"));
  setRequest(false); //setRequestInterval(2000); // Disable timer for check(%%F5)
  setActiveSlide(false); //setSlideInterval(100); // Passive Slide Mode
  setSSIDLabelMode(0);   // Set the function of the label displaying Wi-Fi connection
  showDialogMenu(true);  // show menu button
}

 

- Example of code processing for each function of a button that changes according to the screen number (pageId).

void pin_control(uint8_t value) {
  if (value != 0) {
    switch (value) {
      case 11: if (pageId == 4) Serial.println(F("powor : on"));
               else Serial.println(F("button 1 : on"));
                  break;
      case 10: if (pageId == 4) Serial.println(F("powor : off"));
               else Serial.println(F("button 1 : off"));
                  break;
      case 21: if (pageId == 4) { 
                 Serial.println(F("motor1 : on")); 
                 sendPinState(30); 
               } else Serial.println(F("button 2 : on"));
                  break;
      case 20: if (pageId == 4) Serial.println(F("motor1 : off"));
               else Serial.println(F("button 2 : off"));
                  break;
      case 31: if (pageId == 4) { 
                 Serial.println(F("motor2 : on")); 
                 sendPinState(20); 
               } else Serial.println(F("button 3 : on"));
                  break;
      case 30: if (pageId == 4) Serial.println(F("motor2 : off"));
               else Serial.println(F("button 3 : off"));
                  break;
      case 201: Serial.println(F("button 20 : click"));
                dialogList(0, F("MENU"), F("select,Dial_Nob,Color_Picker,Key_Pad,Arrow_Pad,Main")); // dialog message
                  break;           
    }
  }
}

 

- Example of modifying the function "CheckF9()" that handles dialog messages.

uint8_t pageId = 0;  // screen number

void CheckF9(String temp) {
  Serial.println(temp);
  if (temp.startsWith(F("RAD"))) {  }         // radio button
  else if (temp.startsWith(F("CKB"))) {  }    // Checkbox
  else if (temp.startsWith(F("CHD"))) {  }    // Select button
  else if (temp.startsWith(F("LSD"))) {       // List Window
    int ed = temp.indexOf(':');
    temp.remove(0, ed+1);
    ed = temp.indexOf(':');
    String ID = temp.substring(0, ed);
    uint8_t id = ID.toInt();
    temp.remove(0, ed+1);
    if (id == 0) {
      if (temp.startsWith(F("Dial"))) {           // Dial Nob screen 
        setDisplay(F("11111111111111111111110")); // hide floating button
        setColorNob(4, F("GR1"), F("GR2"), false); pageId = 1; 
      } else if (temp.startsWith(F("Color"))) {   // Color Picker screen
        setDisplay(F("11111111111111111111110")); // hide floating button
        setColorNob(2, F("GR1"), F("GR2"), false); pageId = 2; 
      } else if (temp.startsWith(F("Key"))) {     // Key Pad screen
        if (pageId <= 2) setColorNob(0, F("GR1"), F("GR2"), false);
        setDisplay(F("11111111111100011111110")); 
        setButtonToggle(F("000000000000111"));
        setButtonLabel(F("1,2,3,4,5,6,7,8,9,*,0,#"));
        pageId = 3;
      } else if (temp.startsWith(F("Arrow"))) {   // Arrow Pad screen
        if (pageId <= 2) setColorNob(0, F("GR1"), F("GR2"), false);
        setDisplay(F("11111101010101011111110")); 
        setButtonToggle(F("111111000000000"));
        setButtonLabel(F("Power,Motor1,Moror2,BT4,BT5,BT6,7,Up,9,Left,0,Right,0,Down"));
        pageId = 4;
      } else {                                    // Main screen
        if (pageId <= 2) { setColorNob(0, F("GR1"), F("GR2"), false); pageId = 0; }
        setDisplay(F("11111111111111111111111"));
        setButtonToggle(F("111111111111111"));
        setButtonLabel(F("BT1,BT2,BT3,BT4,BT5,BT6,BT7,BT8,BT9,BT10,BT11,BT12,BT13,BT14,BT15"));
        send_State();
        pageId = 0;
      }
    }
  }
  else if (temp.startsWith(F("STR"))) {  }       // Input text
  else {  
    if (temp.length() < 6) Serial.println(F("alarm"));
    else Serial.println(F("date/time"));
  }
}

If you touch the push button quickly on the Key Pad screen, it takes about 1 second to process the response using the AT Command, so the number touched in the middle may be missing or the order of the numbers may be mixed up. In order to prevent this, you need to make a touch every second or use "responseFailResend(flase);", so that it does not respond.

 

1-1.ARDUINO_ESP01_HMI_CONTROL_MENU.zip

1-1.ARDUINO_ESP01_HMI_CONTROL_MENU.zip
0.01MB

https://youtu.be/3ruyhd2yhBo

 

 

Example of using responseFailResend() function

Coding in order not to respond for values that are quickly touched and transmitted on the keypad screen.

 

- Example of code processing for each function of a button that changes according to the screen number (pageId)

bool pin_control(uint8_t value) {
  bool response = true;
  .
  .
  .
  if (pageId == 3) { if (value < 130) response = false; }       // KEY PAD
  return response; // no response when push button.
}

 

- Example of code processing for each function of a button that changes according to the screen number (pageId)

uint8_t pageId = 0;
bool idClose = false;

void CheckF9(String temp) {
  Serial.println(temp);
  if (temp.startsWith(F("RAD"))) {  }
  else if (temp.startsWith(F("CKB"))) {  }
  else if (temp.startsWith(F("CHD"))) {  }
  else if (temp.startsWith(F("LSD"))) {  
    int ed = temp.indexOf(':');
    temp.remove(0, ed+1);
    ed = temp.indexOf(':');
    String ID = temp.substring(0, ed);
    uint8_t id = ID.toInt();
    temp.remove(0, ed+1);
    if (id == 0) {
      .
      .
      .
      if (pageId == 3) responseFailResend(false); // If the key pad screen
      else responseFailResend(true);              // if the rest of the screen
    }
  }
  else if (temp.startsWith(F("STR"))) {  }
  else {  
    if (temp.length() < 6) Serial.println(F("alarm"));
    else Serial.println(F("date/time"));
  }
}

*** If you want to apply it to the push button of "Arrow Pad" screen, you could add the code below to the function-specific code processing of the button and to the CheckF9() function.

if (pageId == 4) {
  uint8_t va = value / 10;
  if (va == 8 || va == 10 || va == 12 || va == 14) response = false; // ARROW KEY
} else if (pageId == 3) { if (value < 130) response = false; }       // KEY PAD
if (pageId == 3 || pageId == 4) responseFailResend(false); 
else responseFailResend(true);

 

- Example of modifying the wifi_read() function

if (appConnection) { 
  bool response = true; // add
  if (order == 1) {  }
  else if (order == 2) {  }
  else if (order == 3) {
    response = pin_control(value); // edit
  } 
  else if (order == 4) {  }
  else {  }
  if (response) http_response(); // edit
  else {  }
}

 

1-2.ARDUINO_ESP01_HMI_CONTROL_MENU_PUSH_NORESPONSE.zip

1-2.ARDUINO_ESP01_HMI_CONTROL_MENU_PUSH_NORESPONSE.zip
0.01MB

https://youtu.be/4WE27s7Ovqc

 

 

Web Manager

You can change the ID and password for access point and router connection using HTML coded in Arduino.

- Changed the variable type from const char to char so that the SSID and password for connecting to the router can be changed in the loop() function.

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

- EEPROM Setting

void loadConfig() {  // Read ID and Password
  wifiRouter = EEPROM.read(980); // read whether router is in use
  for (int i = 0; i < 21; i++) ssid[i] = EEPROM.read(981 + i); // read SSID
  for (int i = 0; i < 21; i++) pass[i] = EEPROM.read(1002 + i);// read password
}

void saveConfig() { // Write ID and Password
  EEPROM.write(980, wifiRouter); // Save whether or not the router is used
  for (int i = 0; i < 21; i++) EEPROM.write(981 + i, ssid[i]); // save SSID
  for (int i = 0; i < 21; i++) EEPROM.write(1002 + i, pass[i]);// Save password
}

// After uploading the sketch to the Arduino, write it once to the EEPROM or read the values stored in the EEPROM when booting.
void setup() {
  if(EEPROM.read(1023) != 1) { 
    for (int i = 0 ; i < EEPROM.length() ; i++) EEPROM.write(i, 0); // EEPROM Clear
    EEPROM.write(1023, 1);  // flag for status of saving
    saveConfig();       // Write ID and Password at initialization
  } else loadConfig();  // Read saved ID and Password when Arduino is rebooting
}

// EEPROM initialization code at serial monitor
void loop() {
  if(Serial.available() > 0){ // Serial monitor code
    String temp = Serial.readStringUntil('\n');
    Serial.println(temp);
    if (temp == F("1")) {
      EEPROM.write(1023, 0);
      Serial.println("EEPROM INI");
    }
  }
}

 

2.ARDUINO_ESP01_HMI_WEB_MANAGER.zip

2.ARDUINO_ESP01_HMI_WEB_MANAGER.zip
0.01MB

- ARDUINO_EEPROM_INI.zip

ARDUINO_EEPROM_INI.zip
0.00MB

* Change all data to 0 in EEPROM

 

https://youtu.be/cazJ1JhffXU

 

 

Web Login

When connecting through a router, obtain control authority using the name and password of the access point.

Login Page
Web Manager with Login

 

3.ARDUINO_ESP01_HMI_WEB_LOGIN.zip

3.ARDUINO_ESP01_HMI_WEB_LOGIN.zip
0.01MB

 

https://youtu.be/RIBYkVFOk2s

 

 

App Wifi Manager

You can change the ID and password for connecting to access points and a router without using HTML code.

 

4.ARDUINO_ESP01_HMI_NAME.zip

4.ARDUINO_ESP01_HMI_NAME.zip
0.01MB

 

https://youtu.be/Wi9NfuZULsU

 

 

App Login

When connecting through a router, obtain control authority using password of the access point.

 

5.ARDUINO_ESP01_HMI_PASS.zip

5.ARDUINO_ESP01_HMI_PASS.zip
0.01MB

 

https://youtu.be/-p7PWt7pfTM

 

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

 

 

 

 

 

+ Recent posts