惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
N
Netflix TechBlog - Medium
罗磊的独立博客
F
Full Disclosure
I
InfoQ
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
U
Unit 42
Microsoft Security Blog
Microsoft Security Blog
Webroot Blog
Webroot Blog
Apple Machine Learning Research
Apple Machine Learning Research
T
Threatpost
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog
P
Proofpoint News Feed
B
Blog RSS Feed
G
GRAHAM CLULEY
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cisco Talos Blog
Cisco Talos Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Palo Alto Networks Blog
博客园 - 三生石上(FineUI控件)
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
I
Intezer
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
L
LangChain Blog
B
Blog
雷峰网
雷峰网
K
Kaspersky official blog
S
Secure Thoughts
Security Latest
Security Latest
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Security @ Cisco Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟 从Python转向Pharo https://blog.just4fun.site/post/iot/iot-open-source-projects/ Python异步编程笔记 https://blog.just4fun.site/post/iot/iot-open-source-hardware-community/ 万物积木化开发者社区 CodeLab ❤️ Blender Scratch3技术分析之云变量 API(第7篇) [译]对管道(Pipes)的偏爱 [译]提出正确的问题比得到正确答案更重要 蓝牙设备与Scratch3.0 创建你的第一个Scratch3.0 Extension Scratch3技术分析之项目内部数据(第6篇) Scratch3技术分析之社区 API(第5篇) Scratch3技术分析之User API(第4篇) Scratch3技术分析之项目主页API(第3篇) Scratch3技术分析之静态资源API(第2篇) Scratch3.0、micro:bit与Windows7 https://blog.just4fun.site/post/iot/zerynth-vs-micropython/ 核聚变、方所与半宅空间 可视化编程为何是个糟糕的主意 codelab.club周末聚会 关于codelab.club '下一件大事'是一个房间 Hungry Robot - Eat everything 编程作为一种思考方式 今日简史 史蒂夫·乔布斯传 罗素自选文集 https://blog.just4fun.site/post/edx/tianjin-scratch-ai/ https://blog.just4fun.site/post/edx/richie-cms-openedx/ 徒步武功山 WebUSB与micro:bit 积木化编程与3D场景 夜宿武功山顶 scratch3-adapter接入优必选Alpha系列机器人 https://blog.just4fun.site/post/edx/video-migration-note/ scratch3-adapter重构笔记 https://blog.just4fun.site/post/edx/edx-community-members/ 两种硬件编程风格的比较 使用micro:bit自制PPT翻页笔 柏拉图对话集 scratch3.0 + micro:bit 七月电影放映计划 非营利组织的管理 Screenly--用树莓派让任何屏幕变为可编程的数字标牌 以最佳实践开始你的Django项目 micro:bit与事件驱动 为Scratch3.0设计的插件系统(上篇) OCR应用一例 近两年读过的一些好书 blockly开发之使用python驱动浏览器中的turtle(2) 牛顿新传 文学理论入门 逻辑的引擎 人生的意义 blockly开发之生成并运行js代码(1) blockly开发之hello world(0) micro:bit使用笔记 神器之Termux https://blog.just4fun.site/post/iot/micropython-notes/ Cozmo what is this Scratch的前世今生 下段旅程 我行在远方 爆裂 途中杂记 https://blog.just4fun.site/post/edx/open-edx-startup/ cozmo系列之入门 - 有性格且可编程的机器人 PaperWeekly开发笔记 创业二三事
MicroBlocks 编程案例: WiFi Radio 库
种瓜 · 2024-01-28 · via 夜行人

文章目录

前言

MicroBlocks 内置了 WiFi Radio(WiFi 广播)库, 用于支持板子之间的通信, 连到同一个网络里的板子, 可以使用 WiFi Radio 库相互广播消息。

它使用起来像 micro:bit radio 库。

以下是内置在 MicroBlocks 里的简单例子:

详细的视频教程参考 使用 Wi-Fi 广播在两块 ESP32 板子间传送信息

WiFi Radio 基于 UDP 实现。 因此支持 UDP 的编程环境(大多数都支持)都能够加入到 MicroBlocks WiFi Radio 网络里。

用户经常想要让计算机与板子直接通信, 典型的用例包括:

  • 利用计算机的强大算力, 诸如在机器视觉相关项目中, 视觉处理程序(通常是 Python)跑在计算机上, 根据实时的分析结果, 驱动硬件设备
  • 在计算机上构建 dashboard 面板(Scratch 和 Snap! 是很好的选择), 驱动空间里的多个设备。
  • 在计算机上观察 WiFi radio 网络中流动的消息(monitor程序), 调试 bug, 或展示系统的工作原理。

因此, 我为 Python/Scratch/Snap! 构建了 WiFi Radio 库, 让这些编程环境能够与 MicroBlocks 驱动的板子实时通信。

Python

参考 microblocks_wifi_radio

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# pip install microblocks_wifi_radio

import time
from microblocks_wifi_radio import Radio
r = Radio()
r.send_number(123)
time.sleep(1)
r.send_string("hello")
time.sleep(1)
r.send_pair("light", 10)

while True:
    time.sleep(0.01)
    if r.message_received():
        print(r.last_number)
        print(r.last_string)

Scratch

前边提到:

WiFi Radio 基于 UDP 实现

由于浏览器不支持 UDP 协议(未来的 Isolated Web Application(IWA) 或许可以支持, 我在这里做了相关分享), 我们需要使用 CodeLab Adapter 来增强Scratch。

我已经在 CodeLab Adapter 实现了 WiFi Radio 插件(源代码)。

下载并运行(需要关掉翻墙软件) CodeLab Adapter 之后。在 webui 里, 搜索并下载相关插件。 操作过程如下所示:

完成以后就可以在 Scratch 里使用它: 示例项目

目前在 Scratch 中, 只允许消息从 Scratch 发往 MicroBlocks。 未来可能会在 Scratch 里推出正式插件,支持双向 WiFi 广播功能。

Snap!

Snap! 中的使用方式与 Scratch 类似, 需要运行 CodeLab Adapter 并安装相关插件。

然后就可以在 Snap! 里使用它。

Snap! 实现的 WiFi 广播库与 MicroBlocks 内置的 WiFi 广播 API 完全相同。 支持双向 WiFi 广播消息.

FAQ

与其他通信方式的区别

MicroBlocks 支持许多种通信方式, 我们在之前的文章里讨论了:

与 WiFi radio 功能最接近的库是 Simple BLE Radio 库。 它们在使用场景上的主要区别是, WiFi radio 速度更快, 且消息送达率更高。而 Simple BLE Radio 功耗更低,支持 micro:bit 这样不支持 wifi 的板子。

参考