0Pricing
Arduino & IoT Academy · บทเรียน

อ่านและเขียนคุณลักษณะ

แลกเปลี่ยนค่าผ่านแอตทริบิวต์ BLE

อ่านและเขียนคุณลักษณะ เป็นบทเรียน Arduino & IoT Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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. 🚀

คำถามที่พบบ่อย

บทเรียน “อ่านและเขียนคุณลักษณะ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “อ่านและเขียนคุณลักษณะ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Arduino & IoT Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Arduino & IoT Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “อ่านและเขียนคุณลักษณะ”

แลกเปลี่ยนค่าผ่านแอตทริบิวต์ BLE คุณปฏิบัติ Arduino & IoT Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Arduino & IoT Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Arduino & IoT Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “อ่านและเขียนคุณลักษณะ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Arduino & IoT Academy นี้ได้ไหม

ได้ บทเรียน Arduino & IoT Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. Bluetooth แบบคลาสสิกเทียบกับ BLE
  2. ประกาศบริการ BLE
  3. อ่านและเขียนคุณลักษณะ
  4. ควบคุม LED จากแอปโทรศัพท์
← กลับไปที่ Arduino & IoT Academy