Anuncie um serviço BLE
Exponha seu ESP32 para que um celular possa encontrá-lo.
Anuncie um serviço BLE é uma aula grátis de Arduino & IoT Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Arduino & IoT Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Arduino & IoT Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Make Your Board Findable
Before a phone can connect, your ESP32 must announce itself. This shouting into the air is called advertising. 📣
What Advertising Sends
Advertising broadcasts tiny packets with your device name and what it offers, so nearby phones can list it without connecting yet.
Start with the Library
The Arduino core gives you a BLE library. Include it once, then everything for advertising and connecting becomes a few clean calls.
#include <BLEDevice.h>
#include <BLEServer.h>Name Your Device
First you initialize BLE and give your board a friendly name. That name is what users will tap in their phone's Bluetooth list.
BLEDevice::init("Smart-Sensor");Create a Server
Your board acts as a BLE server: it holds the data, and the phone is the client that asks for it. Create the server next.
BLEServer *server = BLEDevice::createServer();What a Service Is
A service is a labeled group of related data, like all the values for one sensor. A device can offer several services at once.
Services Need a UUID
Each service is identified by a UUID, a long unique code. The phone uses this exact id to find the right service among many.
BLEService *svc = server->createService("180F");Standard vs Custom UUIDs
Short UUIDs like 180F are official standard ones. For your own data, generate a long custom UUID so it never clashes with others.
Start the Service
Once the service is defined, you must start it. Until you do, the phone cannot actually use any of its data.
svc->start();Begin Advertising
Finally, tell the radio to advertise. Now the board broadcasts its name and service so phones nearby can discover it.
server->getAdvertising()->start();Find It on Your Phone
Open a scanner app like nRF Connect and you should see Smart-Sensor appear. Seeing your name means advertising works.
Quick Check
You wrote a service but the phone shows no data inside it.
Recap
Init BLE, name the board, make a server, add a service with a UUID, start it, then advertise. Now your device is discoverable. ✨
Perguntas Frequentes
A aula “Anuncie um serviço BLE” é grátis?
Sim — o texto completo de “Anuncie um serviço BLE” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Arduino & IoT Academy, atualize para CoddyKit PRO. O curso de Arduino & IoT Academy inclui 4 aulas no total.
O que vou aprender em “Anuncie um serviço BLE”?
Exponha seu ESP32 para que um celular possa encontrá-lo. Você pratica Arduino & IoT Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Arduino & IoT Academy?
Nenhuma experiência prévia é necessária. Arduino & IoT Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “Anuncie um serviço BLE”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Arduino & IoT Academy?
Sim. Cada aula de Arduino & IoT Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Bluetooth clássico versus BLE
- Anuncie um serviço BLE
- Leia e grave características
- Controle um LED por um aplicativo de celular