Week 11: Networking & Communication

Group Assignment


Individual Assignment

For this assignment, I tried different types of networking and communication protocols including Bluetooth, Wi-Fi.

I will try this protocols to choose the best one for my final project.

PCB

I used the PCB I designed and cut in week 8 for testing the different communication protocols here is week8 documentation.

PCB

Slot Sample

I will also use a slot sample that I cut in week 9. Here is the week 9 documentation.

Slot Sample

Testing Communication Protocols

I will test the different communication protocols to determine the most suitable one for my project by integrating them with the circuit that I built in week 9. Here is the full week 9 documentation.

I will send the slot status updates to another device to determine whether there is an item in the slot or not.

💡 Note: Xiao Seeed ESP32C3 has an antenna to enable wireless communication. Don't forget to connect it antenna

Bluetooth

For Bluetooth testing, I first learned about how to use Bluetooth with the Xiao Seeed ESP32C3.

Here is my conversation with Gemini to learn more about Bluetooth in Xiao Seeed ESP32C3: Gemini.

💡 Note: I discovered that the Xiao Seeed ESP32C3 uses BLE (Bluetooth Low Energy), not the classic one. Here is good documentation to understand BLE: BLE Documentation.
Basic Bluetooth Connection

To start I follow the documentation and examples provided by the seeed studio.

                #include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/

#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"


class MyCallbacks: public BLECharacteristicCallbacks {
    void onWrite(BLECharacteristic *pCharacteristic) {
      std::string value = pCharacteristic->getValue();

      if (value.length() > 0) {
        Serial.println("*********");
        Serial.print("New value: ");
        for (int i = 0; i < value.length(); i++)
          Serial.print(value[i]);

        Serial.println();
        Serial.println("*********");
      }
    }
};

void setup() {
  Serial.begin(115200);

  BLEDevice::init("MyESP32");
  BLEServer *pServer = BLEDevice::createServer();

  BLEService *pService = pServer->createService(SERVICE_UUID);

  BLECharacteristic *pCharacteristic = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );

  pCharacteristic->setCallbacks(new MyCallbacks());

  pCharacteristic->setValue("Hello World");
  pService->start();

  BLEAdvertising *pAdvertising = pServer->getAdvertising();
  pAdvertising->start();
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
}
              

You can download the code from here.

💡 Note: I first tried to use the Bluelight app as shown in the documentation, but it didn't work, so I had to download nRF Connect.
Setup App
bnrfconnect app

To test the Bluetooth connection, I used the nRF Connect app on my Tablet, which allows you to connect to BLE devices and read/write characteristics.

Here are the steps to use the nRF Connect app:

  1. Open the nRF Connect app and scan for devices. You should see your ESP32 device listed (in my case, it is named "MyESP32").
  2. nrf connect scan
  3. Tap on your device to connect to it. Once connected, you will see the services and characteristics that your ESP32 is advertising.
  4. Find the characteristic with the UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8". This is the characteristic that we set up in our code to read and write data.
  5. Here is a video that shows how to send data
Results

After sending data from the nRF Connect app, I can see the new value printed in the Serial Monitor of the Arduino IDE, which confirms that the Bluetooth communication is working correctly.