Configure WIFI with Sending SSID and PASS From BLE I have to configure my own name and UUID

#define UART_SERVICE_UUID "ff3d0000703e4c.."
#define CHARACTERISTIC_UUID_RX "ff3d0000703e4..."
#define CHARACTERISTIC_UUID_TX "ff3d0000703e4.."

#define STRING_BUF_SIZE 100


BLEService UartService(UART_SERVICE_UUID);
BLECharacteristic Rx(CHARACTERISTIC_UUID_RX);
BLECharacteristic Tx(CHARACTERISTIC_UUID_TX);
BLEAdvertData advdata;
BLEAdvertData scndata;
bool notify = false;

void readCB(BLECharacteristic* chr, uint8_t connID) {
  printf("Characteristic %s read by connection %d \n", chr->getUUID().str(), connID);
}

int status = WL_IDLE_STATUS;  // the Wifi radio's status

String cred[2];
static int count = 0;

void writeCB(BLECharacteristic* chr, uint8_t connID) {
  printf("Characteristic %s write by connection %d :\n", chr->getUUID().str(), connID);

  if (chr->getDataLen() > 0) {
    String data = chr->readString();
    // Serial.print("Received string: ");
    Serial.print(data);
    Serial.println();
    cred[count] = data;
    count++;

    if (count >= 2) {
      Serial.println(cred[0]);
      Serial.println(cred[1]);
      connectToWifi();
      count = 0;
    }
  }
}

void connectToWifi() {
  Serial.println("Connecting to WiFi...");
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }


  Serial.println("WiFi Connected!");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}



void notifCB(BLECharacteristic* chr, uint8_t connID, uint16_t cccd) {
  if (cccd & GATT_CLIENT_CHAR_CONFIG_NOTIFY) {
    printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID);
    notify = true;
  } else {
    printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID);
    notify = false;
  }
}

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

  advdata.addFlags(GAP_ADTYPE_FLAGS_LIMITED | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED);
  advdata.addCompleteName("Name of device");
  scndata.addCompleteServices(BLEUUID(UART_SERVICE_UUID));

  Rx.setWriteProperty(true);
  Rx.setWritePermissions(GATT_PERM_WRITE);
  Rx.setWriteCallback(writeCB);
  Rx.setBufferLen(STRING_BUF_SIZE);
  Tx.setReadProperty(true);
  Tx.setReadPermissions(GATT_PERM_READ);
  Tx.setReadCallback(readCB);
  Tx.setNotifyProperty(true);
  Tx.setCCCDCallback(notifCB);
  Tx.setBufferLen(STRING_BUF_SIZE);

  UartService.addCharacteristic(Rx);
  UartService.addCharacteristic(Tx);

  BLE.init();
  BLE.configServer(1);
  configService.addService();
  configService.begin();
  BLE.beginPeripheral();
  BLE.configAdvert()->stopAdv();
  BLE.configAdvert()->setAdvData(configService.advData());
  BLE.configAdvert()->updateAdvertParams();
  delay(100);
  BLE.configAdvert()->startAdv();
}

void loop() {
  delay(1000);
}

Hi @akycdi,

Could you elaborate on the issues that you have encountered and what help you need? Thank you.

I need to make the ameba connect to wifi, The SSID and password will be sent from my application to the ameba I have used the basic BLEUart example I am getting the SSID and password, But when I called the connetTowWifi function it is not connecting to WIFI.

Am I missing anything in this that I wasn’t aware of I am pretty new to this Protocols and Board?
Thank you.

Hi @akycdi,

First of all, if you would like to get your board connected to WiFi via BLE and an app (Eg, Easy WiFi Config), you can refer to this example, BLE – WiFi Configuration Service – Realtek IoT/Wi-Fi MCU Solutions.

Next, the reason why you are unable to connect to WiFi after calling “connectToWifi” function is because you had this block of code as shown below,

 Serial.println("Connecting to WiFi...");
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

but you did not declare your WiFi SSID name and your password. For example,

char ssid[] = "yourNetwork";     // your network SSID (name)
char pass[] = "secretPassword";  // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

May I also know what is the purpose of adding the BLEUart code to your code? What data do you want to transmit and receive?
You may refer to these example guides to learn more about BLE UART:

Hi, Sorry for the late reply.
Thanks for the reply; I did not expect to get any replies. My use case is I have a Pi Pico I am trying to send data through wifi right now. I have a TTL board attached to pico and send the data through uart of ttl, i am planning to remove ttl board and transmit data through UART tx and rx of wifi.

Thank you.