My text input is not respond.what should i do

Hello.I try to used text input for my String but it all way empty i try every thing i could but notthing work.This is my code.

#include <Arduino.h>
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT
#include "BluetoothSerial.h"
#include <BlynkSimpleEsp32_BT.h>
#include "EEPROM.h"

BluetoothSerial ESP_BT;
int Relay = 12;
String code = "xxxxx";
char auth[] = "Bs87he1Gwwq2FfsNxAvheGX99kWOYg8h";
String Passcode;
String UserID;
String Password;

void writeStringToEEPROM(int addrOffset, const String &strToWrite)
{
  byte len = strToWrite.length();
  EEPROM.write(addrOffset, len);

  for (int i = 0; i < len; i++)
  {
    EEPROM.write(addrOffset + 1 + i, strToWrite[i]);
  }
}
String readStringFromEEPROM(int addrOffset)
{
  int newStrLen = EEPROM.read(addrOffset);
  char data[newStrLen + 1];

  for (int i = 0; i < newStrLen; i++)
  {
    data[i] = EEPROM.read(addrOffset + 1 + i);
  }
  data[newStrLen] = '\0';

  return String(data);
}
void setup() {
  Serial.begin(9600);
  Serial.println("Waiting for connections...");
  Blynk.setDeviceName("kit blynk");
  pinMode(Relay, OUTPUT);
  Blynk.begin(auth);
  Blynk.connect();

}
BLYNK_CONNECTED() {
  Serial.println("App Blynk ทำงาน!");
}
BLYNK_WRITE(V1) {
  String Passcode = param.asStr();
  if (Passcode.startsWith(" ")) {
    Passcode.remove(0, 1);
  }
  if (Passcode.endsWith(" ..")) {
    Passcode.replace(" ..", "\n");
    Blynk.virtualWrite(V1, " ");
  }
  Blynk.virtualWrite(V0, Passcode);
  Serial.println(Passcode);
}
BLYNK_WRITE(V2) {
  String UserID = param.asStr();
  if (UserID.startsWith(" ")) {
    UserID.remove(0, 1);
  }
  if (UserID.endsWith(" ..")) {
    UserID.replace(" ..", "\n");
    Blynk.virtualWrite(V2, " ");

  } Blynk.virtualWrite(V0, UserID);
  Serial.println(UserID);
}
BLYNK_WRITE(V3) {
  String Password = param.asStr();
  if (Password.startsWith(" ")) {
    Password.remove(0, 1);
  }
  if (Password.endsWith(" ..")) {
    Password.replace(" ..", "\n");
    Blynk.virtualWrite(V3, " ");

  } Blynk.virtualWrite(V0, Password);
  Serial.println(Password);
}
BLYNK_WRITE(V0) {
  String ID = readStringFromEEPROM(1);
  String passWord = readStringFromEEPROM(32);

  if (param.asInt() == 1) {
    if (Passcode == code) {
      writeStringToEEPROM(1, UserID);
      writeStringToEEPROM(32, Password);
      Serial.println("log in succeed.1");
    }
    else if ((UserID == ID) && (Password == passWord)) {
      Serial.println("log in succeed.2");
      digitalWrite(Relay, HIGH);
      delay(5000);
    }
    else {
      Serial.println("log in fale.");
    }
    Serial.println(ID);
    Serial.println(passWord);
    Serial.println(UserID);
    Serial.println(Password);
  }
}
void loop() {
  Blynk.run();

}

@Atithep_Jarungsathit please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly. Triple backticks look like this:
```

Pete.

Thank you .

@Atithep_Jarungsathit you’ve edited your post but despite me giving you triple backticks that you can copy and paste, you’ve used other characters instead.
Please re-edit your post, and this time use the correct triple backtick characters.

Pete.

My apologise.Is this correct one?

Yes,

Your problem is that you are declaring global variables for Passcode, UserID and Password at the top of your sketch…

then re-declaring these variables locally within the corresponding BLYNK_WRITE(vPin) functions like this…

You need to remove the String declaration from the front of these variable names in the `BLYNK_WRITE(vPin) functions.

Pete.

1 Like

It still not working.

Lets see your updated code, proper serial output (not a screenshot) and details of exactly what you are inputting into your widgets.

Pete.

1 Like

I’m try to get text fromV1 to compare with “code” for activate function that create “UserID” and “Password” then turn on my Relay ,V2 V3 to compare with “UserID” and “Password” with out "code"to turn on my Relay or else end process.this is an update.Thank-you.

#include <Arduino.h>
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT
#include "BluetoothSerial.h"
#include <BlynkSimpleEsp32_BT.h>
#include "EEPROM.h"

BluetoothSerial ESP_BT;
int Relay = 12;
String code = "xxxxx";
char auth[] = "Bs87he1Gwwq2FfsNxAvheGX99kWOYg8h";
String Passcode;
String UserID;
String Password;

void writeStringToEEPROM(int addrOffset, const String &strToWrite)
{
  byte len = strToWrite.length();
  EEPROM.write(addrOffset, len);

  for (int i = 0; i < len; i++)
  {
    EEPROM.write(addrOffset + 1 + i, strToWrite[i]);
  }
}
String readStringFromEEPROM(int addrOffset)
{
  int newStrLen = EEPROM.read(addrOffset);
  char data[newStrLen + 1];

  for (int i = 0; i < newStrLen; i++)
  {
    data[i] = EEPROM.read(addrOffset + 1 + i);
  }
  data[newStrLen] = '\0';

  return String(data);
}
void setup() {
  Serial.begin(9600);
  Serial.println("Waiting for connections...");
  Blynk.setDeviceName("kit blynk");
  pinMode(Relay, OUTPUT);
  Blynk.begin(auth);
  Blynk.connect();


}
BLYNK_CONNECTED() {
  Serial.println("App Blynk ทำงาน!");
}
BLYNK_WRITE(V1) {
  Passcode = param.asStr();
  if (Passcode.startsWith(" ")) {
    Passcode.remove(0, 1);
  }
  if (Passcode.endsWith(" ..")) {
    Passcode.replace(" ..", "\n");
    Blynk.virtualWrite(V1, " ");
  }
  Blynk.virtualWrite(V0, Passcode);
  Serial.println(Passcode);
}
BLYNK_WRITE(V2) {
  UserID = param.asStr();
  if (UserID.startsWith(" ")) {
    UserID.remove(0, 1);
  }
  if (UserID.endsWith(" ..")) {
    UserID.replace(" ..", "\n");
    Blynk.virtualWrite(V2, " ");

  } Blynk.virtualWrite(V0, UserID);
  Serial.println(UserID);
}
BLYNK_WRITE(V3) {
  Password = param.asStr();
  if (Password.startsWith(" ")) {
    Password.remove(0, 1);
  }
  if (Password.endsWith(" ..")) {
    Password.replace(" ..", "\n");
    Blynk.virtualWrite(V3, " ");

  } Blynk.virtualWrite(V0, Password);
  Serial.println(Password);
}
BLYNK_WRITE(V0) {
  String ID = readStringFromEEPROM(1);
  String passWord = readStringFromEEPROM(32);

  if (param.asInt() == 1) {
    if (Passcode == code) {
      writeStringToEEPROM(1, UserID);
      writeStringToEEPROM(32, Password);
      Serial.println("log in succeed.1");
    }
    else if ((UserID == ID) && (Password == passWord)) {
      Serial.println("log in succeed.2");
      digitalWrite(Relay, HIGH);
      delay(5000);
    }
    else {
      Serial.println("log in fale.");
    }
    Serial.println("ID ==");
    Serial.println(ID);
    Serial.println("passWord ==");
    Serial.println(passWord);
    Serial.println("UserID ==");
    Serial.println(UserID);
    Serial.println("Password ==");
    Serial.println(Password);
  }
}
void loop() {
  Blynk.run();

}

???

Pete.

Do you meen this one?

No.

You posted a screenshot of your serial outpit, but I don’t want a screenshot, I want the data from the serial monitor copied and pasted, between triple backticks.

I also want to know exactly what characters you typed into the three fields in the app, so that I can make sense of the data that appears in the serial monitor.

It would also be useful to know which virtual pin your ‘login’ button widget is attached to, as its not obviously from the code.

Isn’t this how you would approach the task of debugging this code?

Pete.

so sorry.Do you meen this section?

BLYNK_WRITE(V1) {
  Passcode = param.asStr();
  if (Passcode.startsWith(" ")) {
    Passcode.remove(0, 1);
  }
  if (Passcode.endsWith(" ..")) {
    Passcode.replace(" ..", "\n");
    Blynk.virtualWrite(V1, " ");
  }
  Blynk.virtualWrite(V0, Passcode);
  Serial.println(Passcode);
}
BLYNK_WRITE(V2) {
  UserID = param.asStr();
  if (UserID.startsWith(" ")) {
    UserID.remove(0, 1);
  }
  if (UserID.endsWith(" ..")) {
    UserID.replace(" ..", "\n");
    Blynk.virtualWrite(V2, " ");

  } Blynk.virtualWrite(V0, UserID);
  Serial.println(UserID);
}
BLYNK_WRITE(V3) {
  Password = param.asStr();
  if (Password.startsWith(" ")) {
    Password.remove(0, 1);
  }
  if (Password.endsWith(" ..")) {
    Password.replace(" ..", "\n");
    Blynk.virtualWrite(V3, " ");

  } Blynk.virtualWrite(V0, Password);
  Serial.println(Password);
}
BLYNK_WRITE(V0) {
  String ID = readStringFromEEPROM(1);
  String passWord = readStringFromEEPROM(32);

  if (param.asInt() == 1) {
    if (Passcode == code) {
      writeStringToEEPROM(1, UserID);
      writeStringToEEPROM(32, Password);
      Serial.println("log in succeed.1");
    }
    else if ((UserID == ID) && (Password == passWord)) {
      Serial.println("log in succeed.2");
      digitalWrite(Relay, HIGH);
      delay(5000);
    }
    else {
      Serial.println("log in fale.");
    }
    Serial.println("ID ==");
    Serial.println(ID);
    Serial.println("passWord ==");
    Serial.println(passWord);
    Serial.println("UserID ==");
    Serial.println(UserID);
    Serial.println("Password ==");
    Serial.println(Password);
  }

I’m not asking for code, you’ve already provided that.

I’d suggest that you re-read what I wrote.

Pete.

Do you meen character that i put in “code ,UserID,Password”?

Yes, along with what appears in your serial monitor when you do this, plus info on what pin your switch is attached to.

Pete.

@⸎!:P⸎⸎⸎p⸎%⸎K⸎Waiting for connections...
[9] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.1 on ESP32

[8052] BT connect
[11061] BT disconnect
[11061] Disconnected
[22786] BT connect
[22798] Ready
App Blynk ทำงาน!
[36871] BT disconnect
[36871] Disconnected
[51946] BT connect
[54963] Ready
App Blynk ทำงาน!
log in succeed.2
ID ==  //characters in eeprom that user create

passWord ==   //characters in eeprom that user create

UserID ==  //in put is "myID123" on pin  V2

Password ==  //in put is "12345" on pin  V3

Passcode ==   //in put is "xxxxx" same ask "code" on pin  V1


Okay, I give up!

Good luck with your project.

Pete.

So sorry.