#include #include #include #include #include #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif // TODO -- BTC server name #define btcServerName "" // Define the BluetoothSerial BluetoothSerial SerialBT; // Received data String data = ""; // The receivedData function is called when data is available on Bluetooth (see loop function) void receivedData() { // Read the data using the appropriate SerialBT functions // according to the app specifications // The data is terminated by the new line character (\n) while (SerialBT.available()) { data = SerialBT.readStringUntil('\n'); } Serial.println(data); // <-- This is the message sent from the app, according to the specs // Possible steps: // 1. Deserialize data using the ArduinoJson library // 2. Get the action from the JSON object // 3. Check action and perform the corresponding operations // IMPORTANT -- if it is an API project, connect to WiFi when the appropriate action is requested and // make sure to set the http request timeout to 10s or more // IMPORTANT -- If using the ArduinoJson library, use a DynamicJsonDocument with the size of 15000 // 5. Define the response structure, according to the app specifications // (Use JsonArray or JsonObject, depending on the response type) // IMPORTANT -- The cacapcity of the response array/object must not exceed 512B, especially for BLE // 6. Populate the response object according to the app specs // 7. Encode the response object as a JSON string // 8. Write value to the characteristic and notify the app // TODO -- Write your code // Reset the received data string after processing data = ""; } void setup() { Serial.begin(115200); // No need to change the lines below // Initialize BTC SerialBT.begin(btcServerName); //Bluetooth device name Serial.println("The device started, now you can pair it with bluetooth!"); } void loop() { // Check available Bluetooth data and perform read from the app if (SerialBT.available()) { receivedData(); } // possible code to be executed for the actions which run periodically // (possibly conditioned by an interrupt flag) }