Characteristicを読み書きする
BLE属性を通じて値を交換します。
「Characteristicを読み書きする」はCoddyKit上の無料Arduino & IoT Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはArduino & IoT Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Arduino & IoT Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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. 🚀
よくある質問
「Characteristicを読み書きする」レッスンは無料ですか?
はい。「Characteristicを読み書きする」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Arduino & IoT Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Arduino & IoT Academyコースには全4レッスンが含まれています。
「Characteristicを読み書きする」で何を学びますか?
BLE属性を通じて値を交換します。 ブラウザで直接実行するハンズオンコードでArduino & IoT Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Arduino & IoT Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのArduino & IoT Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「Characteristicを読み書きする」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このArduino & IoT Academyレッスンでコードを書いて実行できますか?
はい。すべてのArduino & IoT Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Classic BluetoothとBLEの違い
- BLEサービスをアドバタイズする
- Characteristicを読み書きする
- スマートフォンアプリからLEDを制御する