Leggere e scrivere le caratteristiche
Scambi valori tramite gli attributi BLE.
Leggere e scrivere le caratteristiche è una lezione Arduino & IoT Academy gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Arduino & IoT Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Where the Data Lives
A service is a folder, but the real values live inside characteristics. These are the slots a phone actually reads and writes. 📦
Characteristics Have UUIDs Too
Like services, every characteristic carries its own UUID. The phone uses it to target one exact value, such as temperature.
Create One
You build a characteristic on a service and declare what it allows: reading, writing, or both. Properties decide who can do what.
auto c = svc->createCharacteristic(uuid,
BLECharacteristic::PROPERTY_READ);Properties Set Permissions
Use PROPERTY_READ for values the phone fetches, and PROPERTY_WRITE for ones it sends back. Combine them when both directions matter.
Set a Value to Read
Your sketch stores the current data with setValue. When the phone reads, it gets exactly whatever you placed there last.
c->setValue("23.5");The Phone Writes Back
For a writable characteristic, the phone can push a value to your board. Your code reads it with getValue to learn what arrived.
std::string in = c->getValue();React with a Callback
To respond the instant a write happens, attach a callback. Its onWrite method fires automatically whenever the phone sends data.
Notify Instead of Polling
With notify, your board pushes new values the moment they change. The phone gets fresh data without asking again and again.
c->setValue(temp);
c->notify();Values Are Just Bytes
BLE sends raw bytes, not numbers. Send text like 23.5 or pack the number yourself, then unpack it on the phone side.
Keep Packets Small
A default BLE write fits about twenty bytes. Keep each characteristic focused on one small value rather than a giant blob.
Read, Write, Notify
Those three jobs cover almost every project. Read shares state, write accepts commands, and notify streams live updates.
Quick Check
You want the phone to get new readings the instant they change.
Recap
Characteristics hold the data: set properties for read, write, or notify, store values, and let callbacks react to incoming writes. 🚀
Domande Frequenti
La lezione «Leggere e scrivere le caratteristiche» è gratuita?
Sì — il testo completo di «Leggere e scrivere le caratteristiche» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Arduino & IoT Academy, passa a CoddyKit PRO. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Cosa imparerò in «Leggere e scrivere le caratteristiche»?
Scambi valori tramite gli attributi BLE. Eserciti Arduino & IoT Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Arduino & IoT Academy?
Non è richiesta alcuna esperienza precedente. Arduino & IoT Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.
Quanto tempo richiede la lezione «Leggere e scrivere le caratteristiche»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Arduino & IoT Academy?
Sì. Ogni lezione Arduino & IoT Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Bluetooth classico contro BLE
- Pubblicizzare un servizio BLE
- Leggere e scrivere le caratteristiche
- Controllare un LED da un'app del telefono