0Pricing
Arduino & IoT Academy · Lekcja

Rozgłaszanie usługi BLE

Udostępnić ESP32, aby telefon mógł je znaleźć.

Rozgłaszanie usługi BLE to bezpłatna lekcja Arduino & IoT Academy na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Arduino & IoT Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Arduino & IoT Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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. ✨

Często zadawane pytania

Czy lekcja „Rozgłaszanie usługi BLE” jest bezpłatna?

Tak — pełny tekst „Rozgłaszanie usługi BLE” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Arduino & IoT Academy, przejdź na CoddyKit PRO. Kurs Arduino & IoT Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Rozgłaszanie usługi BLE”?

Udostępnić ESP32, aby telefon mógł je znaleźć. Ćwiczysz Arduino & IoT Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Arduino & IoT Academy?

Nie wymagamy żadnego doświadczenia. Arduino & IoT Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Rozgłaszanie usługi BLE”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Arduino & IoT Academy?

Tak. Każda lekcja Arduino & IoT Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Bluetooth Classic a BLE
  2. Rozgłaszanie usługi BLE
  3. Odczytywanie i zapisywanie charakterystyk
  4. Sterowanie diodą LED z aplikacji telefonu
← Powrót do Arduino & IoT Academy