I trying to learn how to write arduino code for an ESP32 WROOM 32. I want my esp32 to make an http request to a RESTFUL API i've set up. Thus, my esp32 will need wifi access. I was planning to use Bluetooth to tell my esp32 what wifi connection details to use and the specific address of the RESTFUL API end point. I read some documenation online and people suggested that I would need BluetoothSerial.h for bluetooth connection, <WiFi.h> for wifi connection and <HTTPClient.h> for make HTTP requests.
But the moment I include all 3 packages and initialize a few variables and try to compile, my Arduino IDE gives me the following error:
text section exceeds available space in boardSketch uses 1428393 bytes (108%) of program storage space. Maximum is 1310720 bytes.
Global variables use 55740 bytes (17%) of dynamic memory, leaving 271940 bytes for local variables. Maximum is 327680 bytes.
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
Error compiling for board ESP32-WROOM-DA Module.
This is the code that caused the error:
#include "BluetoothSerial.h"
#include <WiFi.h>
#include <HTTPClient.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run make menuconfig to and enable it
#endif
BluetoothSerial SerialBT;
const char* ssid = "";
const char* pass = "";
String apiUrl = "";
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA); //Optional
WiFi.begin(ssid, pass);
while(WiFi.status() != WL_CONNECTED){
delay(100);
}
SerialBT.begin("ESP32test"); //Bluetooth device name
}
void loop() {
delay(20);
}
As you can see, I haven't even begun any real coding and I already get an error that suggest my ESP32 doesn't have necessary resources.
Did I do something wrong? What else should I consider?
UPDATES
@jsotola
When I comment out the lines BluetoothSerial SerialBT; and SerialBT.begin("ESP32test");, then the program compiles and I see this message:
Wrote 726112 bytes (464336 compressed) at 0x00010000 in 7.0 seconds (effective 828.6 kbit/s)...
Hash of data verified.
So does that mean just those two lines of bluetooth related code takes up about 700kb?
@hcheung - If I change the Tools > Partition Scheme from Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) to 8MB with spiffs (3MB APP/1.5MB SPIFFS), then Arduino IDE compiles and writes the code to my ESP32. However, when I try to use my Android phones Serial Bluetooth app to try to connect to the ESP32, I get the error Connection failed: read failed, socket might closed or timeout, read ret:-1. So it seems the partition scheme affects bluetooth functionality.
I also tried changing the Tools > Flash Size from 4MB to 8MB. And I get the same behaviour - 4MB doesn't compile. But 8MB does compile. But after it compiles my phone can't connect via bluetooth.
And just to be sure, the following code below from File > Examples > BluetoothSerial > SerialtoSerialBT only works with Flash Size 4MB and Default Partition Scheme of Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run make menuconfig to and enable it
#endif
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(20);
}