
本文来源:https://www.163.com/dy/article/LC2QFG9N05561FZI_pdya11y.html
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。
树莓派过去十年推出了多块板子,分出不同系列:主流的树莓派4 Model B和5,适合单一用途的Zero系列,以及面向嵌入式计算的Pico系列。我手上有一块4 Model B、一块Zero 2 W,最近又买了块Pico板子,本来想找时间学电子和电路,结果放了一个月也没找到时间和目的。对像我这样偏软件项目的普通用户来说,Pico是个挑战:它是微控制器,没有能轻松装上的操作系统,也跑不了DietPi那种完整命令行系统。于是我给自己定了个任务:在这块板子上搭一个轻量级监控服务器。
第一次尝试就撞墙:我买了一块1GB内存的4 Model B和一块Pico 2 W,偏好带排针和无线连接的板子,既给以后电子折腾留门,也不用外接东西就能联网。但在Thonny里跑第一轮脚本测试就报错,核对标签发现收到的其实是Pico 2,没有任何无线能力。硬件不匹配让项目停摆——一块连不上服务器的板子搭出来没意义,我把它用在依赖其他元件的物理连接项目上。在Pico 2上搭监控服务器,核心诉求是独立于故障:如果面板跑在家里的某台服务器上,那台机器一挂面板也用不了,只能挨个SSH去查。
摆在面前的选择有限:要么再买块带无线的Pico 2 W,要么给现有板子外接Wi-Fi模块。但我找到了另一条路——USB NCM。如果能让Windows电脑把网络共享给Pico 2,它就能托管面板并连接其他服务器。Pico 2及其他Pico板在BOOTSEL模式下会把自己呈现为USB存储设备。USB网络控制模型NCM是一项USB标准,能让微控制器在电脑面前呈现为网络设备。我之前用Zero 2 W的USB以太网模式配合几处配置改动做过类似的事,但Pico 2没有操作系统,所以我用Arduino-Pico核心和NCMEthernetlwIP库,在固件层面启用USB以太网支持:先添加Earlephilhower的Arduino-Pico板卡包,再用板卡管理器安装。
下一步是编写sketch,借助这些库在微控制器上托管一个轻量级面板,给它分配静态IP。面板通过基于Python的监控代理,从两台家用服务器拉取系统和Docker状态数据。我把Arduino sketch上传到Pico 2,等它重启时查看串口监视器,输出显示Zero 2 W那台服务器离线、另一台可用,用静态IP打开网页面板加载正常。最初搭面板时我把大部分网络环节交给Windows处理,用Windows的Internet连接共享ICS自动管理DHCP、IP分配和NAT,只需把Wi-Fi连上就行。但每次断开微控制器或关电脑,DHCP都会分配新IP,于是我改用静态IP:先给Pico的网络适配器配静态IP,再在sketch里给面板指定一个,这样面板的URL就固定了。
现在这块微控制器共享着我电脑的网络,即使运营商断网也能访问并显示最新数据。监控代理以JSON格式共享数据,sketch用HTML把它变成一个简单网页。Pico 2搭载双核Arm Cortex-M0+处理器,足够处理这种轻量面板。我想继续探索LED告警系统,减少查看面板页面的需要:加一个多色LED器件,为每种状态定义颜色代码,比如红色闪烁代表服务器无响应、每台服务器各用一种颜色,监控会更直观。用微控制器还能做更多 sensor 类扩展,但它最打动我的,是在没有操作系统、没有独立网络的情况下,靠一块小小的开发板,就能搭出一个稳定可靠、随时可看的家庭监控屏——这恰恰是嵌入式计算最有魅力的地方。

本文来源:https://www.163.com/dy/article/LC2QFG9N05561FZI_pdya11y.html
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。
Over the past decade Raspberry Pi has released several boards across different series: the mainstream 4 Model B and 5, the Zero series for single-purpose use, and the Pico series for embedded computing. I own a 4 Model B, a Zero 2 W, and recently bought a Pico board, intending to find time to learn electronics and circuits, but it sat untouched for a month. For a typical user like me, more into software projects, the Pico is a challenge: it is a microcontroller with no easily installed operating system and cannot run a full command-line system like DietPi. So I set myself a task: build a lightweight monitoring server on this board.
The first attempt hit a wall: I bought a 1GB 4 Model B and a Pico 2 W, preferring boards with headers and wireless so I could tinker later and connect without extra hardware. But the first script test in Thonny threw errors, and checking the label showed I had actually received a Pico 2 with no wireless at all. The mismatch stalled the project, since a board that cannot reach the server is pointless, so I used it for physical projects needing other components. Building a monitoring server on a Pico 2 has one core demand: independence from failures. If the panel runs on some home server, when that machine dies the panel dies too and you must SSH around to investigate.
My options were limited: buy another Pico 2 W with wireless, or add a Wi-Fi module to the board I had. But I found another path, USB NCM. If I could get Windows to share its network with the Pico 2, it could host the panel and reach other servers. Pico 2 and other Pico boards present themselves as USB storage devices in BOOTSEL mode. USB Network Control Model, or NCM, is a USB standard that lets a microcontroller appear to the PC as a network device. I had done something similar with the Zero 2 W USB Ethernet mode and a few config changes, but the Pico 2 has no OS, so I used the Arduino-Pico core and the NCMEthernetlwIP library to enable USB Ethernet at the firmware level: first add Earlephilhower Arduino-Pico board package, then install it through the boards manager.
Next I wrote a sketch using those libraries to host a lightweight panel on the microcontroller with a static IP. The panel pulls system and Docker status from two home servers through a Python-based monitoring agent. I uploaded the Arduino sketch to the Pico 2, watched the serial monitor as it rebooted, and the output showed the Zero 2 W server offline while the other was available; opening the web panel at the static IP loaded fine. At first I handed most networking to Windows, using Internet Connection Sharing to manage DHCP, IP assignment, and NAT automatically, so I only needed to connect Wi-Fi. But every time I disconnected the microcontroller or shut down the PC, DHCP assigned a new IP, so I switched to static IPs: first set a static IP on the Pico network adapter, then specify one for the panel in the sketch, fixing the panel URL.
Now this microcontroller shares my PC network, so even if the ISP connection drops I can still reach it and see the latest data. The monitoring agent shares data as JSON and the sketch turns it into a simple web page with HTML. The Pico 2 dual-core Arm Cortex-M0+ processor is more than enough for such a light panel. I want to explore an LED alert system next to reduce how often I open the panel page: add a multi-color LED device with a color code per status, such as blinking red for an unresponsive server and a distinct color for each server, making monitoring more intuitive. A microcontroller enables many more sensor-style extensions, but what struck me most is that with no operating system and no independent network, a tiny board can still host a stable, reliable, always-viewable home monitoring screen, which is exactly the charm of embedded computing.