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

**URL:** <https://forum.amebaiot.com/t/configure-wifi-with-sending-ssid-and-pass-from-ble-i-have-to-configure-my-own-name-and-uuid/1837>\
**Category:** WiFi\
**Tags:** evb-amb82, rtl872xd\
**Created:** [May 3, 2023, 10:02am UTC](https://forum.amebaiot.com/t/configure-wifi-with-sending-ssid-and-pass-from-ble-i-have-to-configure-my-own-name-and-uuid/1837 "2023-05-03T10:02:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![akycdi](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/akycdi/32/1416_2.png) [@akycdi](https://forum.amebaiot.com/u/akycdi)\
**Post date:** [May 3, 2023, 10:02am UTC](https://forum.amebaiot.com/t/configure-wifi-with-sending-ssid-and-pass-from-ble-i-have-to-configure-my-own-name-and-uuid/1837/1 "2023-05-03T10:02:40Z")

</div>

```auto
#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);
}

```

---

<div class="post-metadata">

**Author:** ![Pammy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/pammy/32/936_2.png) [@Pammy](https://forum.amebaiot.com/u/Pammy)\
**Post date:** [May 5, 2023, 1:20am UTC](https://forum.amebaiot.com/t/configure-wifi-with-sending-ssid-and-pass-from-ble-i-have-to-configure-my-own-name-and-uuid/1837/2 "2023-05-05T01:20:09Z")

</div>

Hi @akycdi,

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

---

<div class="post-metadata">

**Author:** ![akycdi](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/akycdi/32/1416_2.png) [@akycdi](https://forum.amebaiot.com/u/akycdi)\
**Post date:** [May 5, 2023, 5:03am UTC](https://forum.amebaiot.com/t/configure-wifi-with-sending-ssid-and-pass-from-ble-i-have-to-configure-my-own-name-and-uuid/1837/3 "2023-05-05T05:03:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pammy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/pammy/32/936_2.png) [@Pammy](https://forum.amebaiot.com/u/Pammy)\
**Post date:** [May 5, 2023, 9:34am UTC](https://forum.amebaiot.com/t/configure-wifi-with-sending-ssid-and-pass-from-ble-i-have-to-configure-my-own-name-and-uuid/1837/4 "2023-05-05T09:34:25Z")

</div>

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](https://www.amebaiot.com/en/amebapro2-amb82-mini-arduino-ble-wifi-configuration/).

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,

```auto
 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,

```auto
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:

- [BLE – BLE UART Client – Realtek IoT/Wi-Fi MCU Solutions](https://www.amebaiot.com/en/amebad-arduino-ble-uart/)
- [BLE – BLE UART Service – Realtek IoT/Wi-Fi MCU Solutions](https://www.amebaiot.com/en/amebad-arduino-ble-uart-service/)

---

<div class="post-metadata">

**Author:** ![akycdi](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/akycdi/32/1416_2.png) [@akycdi](https://forum.amebaiot.com/u/akycdi)\
**Post date:** [July 11, 2023, 9:54am UTC](https://forum.amebaiot.com/t/configure-wifi-with-sending-ssid-and-pass-from-ble-i-have-to-configure-my-own-name-and-uuid/1837/5 "2023-07-11T09:54:02Z")

</div>

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.
