Anunciar un servicio BLE
Haga visible su ESP32 para que un teléfono lo encuentre.
Anunciar un servicio BLE es una lección gratuita de Arduino & IoT Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Arduino & IoT Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Arduino & IoT Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en 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. ✨
Preguntas frecuentes
¿La lección «Anunciar un servicio BLE» es gratis?
Sí — el texto completo de «Anunciar un servicio BLE» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Arduino & IoT Academy, actualiza a CoddyKit PRO. El curso de Arduino & IoT Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Anunciar un servicio BLE»?
Haga visible su ESP32 para que un teléfono lo encuentre. Practicas Arduino & IoT Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Arduino & IoT Academy?
No se requiere experiencia previa. Arduino & IoT Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.
¿Cuánto tiempo toma la lección «Anunciar un servicio BLE»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Arduino & IoT Academy?
Sí. Cada lección de Arduino & IoT Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Bluetooth clásico frente a BLE
- Anunciar un servicio BLE
- Leer y escribir características
- Controlar un LED desde una aplicación móvil