I tried to make a Wi-Fi manager with ble or Bluetooth but ı got a "sketch too big" error. How I solve this issue? My code :
#include <WiFi.h>
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
WiFiClient client;
// The field you wish to read
String ssid_pass;
char *SSID1 = "POCO";
char *PASS = "9004652173";
String ssid;
String pass;
const int LED1 = 12;
const int LED_BT = 13;
const int SW = 14;
bool flag = false;
void setup()
{
pinMode(LED1,OUTPUT);
pinMode(LED_BT,OUTPUT);
pinMode(SW,INPUT_PULLUP);
Serial.begin(115200);
Serial.println();
WiFi.begin(SSID1, PASS); // write wifi name & password
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
if(!SerialBT.begin("ESP32"))
{
Serial.println("An error occurred initializing Bluetooth");
}
}
void loop()
{
digitalWrite(LED_BT, LOW);
int input = digitalRead(SW);
Serial.print("input: ");Serial.println(input);
if(input == 0)
{
delay(50);
flag = true;
digitalWrite(LED_BT, HIGH);
}
while(flag == true)
{
while(SerialBT.available())
{
ssid_pass = SerialBT.readString();
//Serial.write(SerialBT.read());
Serial.println(ssid_pass);
for (int i = 0; i < ssid_pass.length(); i++)
{
if (ssid_pass.substring(i, i+1) == ",")
{
ssid = ssid_pass.substring(0, i);
pass = ssid_pass.substring(i+1);
Serial.print("SSID = ");Serial.println(ssid);
Serial.print("Password = ");Serial.println(pass);
delay(2000);
flag = false;
int n1 = ssid.length();
char char_array1[n1 + 1];
strcpy(char_array1, ssid.c_str());
int n2 = pass.length();
char char_array2[n2 + 1];
strcpy(char_array2, pass.c_str());
WiFi.begin(char_array1, char_array2); // write wifi name & password
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
break;
}
}
}
}
}
Code source : https://www.youtube.com/watch?v=5my1MScDvGE
My error :