今日已更新 331 条资讯 | 累计 41105 条内容
关于我们

Building a Dual-Mode (WiFi + Bluetooth) Scratch Extension for My ESP32 Robot

ekko1500 2026年09月09日 14:41 2 次阅读 来源:Dev.to

I built KanKaung , an ESP32-based robot car that kids control with Scratch-style blocks — rotate a servo, blink an LED, read a sensor. It supports two ways to talk to it: WiFi and Bluetooth . This post is the story of turning that into one clean extension instead of two, and every bug I ran into along the way. I'm writing it mostly so future-me doesn't repeat these mistakes. The starting point The firmware originally drove two continuous-rotation servos through a simple command set: left_servo cw|ccw|stop right_servo cw|ccw|stop left_servo_speed 0-100 , right_servo_speed 0-100 led_on|led_off green|red|all sensor_distance , sensor_ir_left , sensor_ir_right Both the WiFi path (plain HTTP GET /cmd?action=...&value=... ) and the Bluetooth path (a BLE characteristic you write a plain string to, like "left_servo cw" ) spoke the exact same vocabulary. That symmetry mattered a lot later. Why I wanted one extension instead of two I had kankaung-extension-wifi.js and kankaung-extension-bluetooth.js as separate files. Same blocks, copy-pasted twice, differing only in how they sent commands. The real problem: if a kid built a whole program using the WiFi extension and then wanted to switch to Bluetooth, they had to rebuild everything from scratch — the blocks were tied to a specific extension ID. So the plan was: one extension, one block set, and pick the transport once. Mistake #1: I first tried a dropdown on a "connect" block My first design had a connect via [WiFi/Bluetooth] (IP: [IP]) block that kids would drag in. It worked, technically — but it didn't match how the app was actually meant to be used. The intent was: you connect once when the extension loads, and never think about it again. Having a "connect" block meant re-running it every time, which didn't make sense for something that should just be a one-time setup. Lesson: figure out the actual intended UX before building the mechanism. I built the dropdown-on-a-block version first and had to rip it out later. Mistake

本文内容来源于互联网,版权归原作者所有
查看原文