简单RestAPI获取硬件状态

2023-05-11 作者:

简单来说,我需要一个能从HA上直接浏览家里主路由的CPU温度的首屏,因为RK3399发热比较猛却只有被动散热。有人可能说,加个小风扇难度很大么?呃,具备Netgear R7000(博通方案)在夏天轻松面对75℃服役5年的经验,我觉得国货不妨一战。

所以这个小项目,其实提供了对运行在物理机上几乎任意Linux的cpu温度、磁盘余量、上电时间等参数的rest api获取。写的比较糙快猛,主要满足自己需求,所以莫要预期过高哈。

提供何种接口

随意运行一个http client,比如  curl http://[hostname]:9090/stats/[data_type]

data_type初期支持三种, du, temps, boot_time 分别代表磁盘用量,多个温度,和上电时间。然后就可以返回数据了。

完整阅读本篇»

基于 Asus Tinker Board 2S 单臂路由

2023-05-07 作者:

书接上回,这次实验对象轮到了压箱底旧货,基于RK3399的华硕Tinker Board 2S

虽然原厂OS拉胯,不得不说硬件用料还是大厂风范

话说这CPU运行libvirt比较艰难,直接新建vm确定100%报错cpu初始化失败。

查阅了一些资料,发现这种大小核的cpu,libvirt支持上比较有个性,vm要么选择小核,要么选择大核,万不可“既要又要”,否则就报错摆烂。也好,A72双核 vs. A53四核,看看老话“双拳难敌四手”到底靠谱不靠。

带上vlan,蛮好一台4口路由

那么先给OpenWrt配置A72双核,注意是RK3399的后2核,莫要搞错。

完整阅读本篇»

基于 Raspberry Pi 4B 单臂路由

2023-04-30 作者:

Here we’re gonna talk about a hand-made router (NAT gateway) using a Raspberry Pi 4B with at least 3 implementations. Sorry the wifi router is not included since it’s kinda easy to find the tutorials about the hostapd stuff, and the signal from onboard wifi is not quite usable anyway.

这里聊一下基于树莓派4B的有线单臂路由实现,至少三种技术实现;wifi路由就不谈了,基于hostapd的教程遍地都是,信号强度也是个问题,可用性仅限于贴脸。

如果只使用iptables的话,实现一个基于pi的路由其实只需要一句话。加上让内核开启转发,两句话打完收工。

Method #1: Several simple commands could simply turn the Pi OS to be a layer 3 device with SNAT (or MASQUERADE).

开个玩笑,起码还得先给LAN口设个固定地址,比如给eth0设置 192.168.17.1/24 ,那么上边<lan subnet>就应当是 192.168.17.0/24 。

如果还需要dhcp服务器(非必须)的话,去看一下dnsmasq,熟练工的话,基于一般的Pi OS手打路由只要10分钟(含参考文档)。

PS:要问wan口谁来承担?wifi可以,给eth0加vlan也可以,看想怎么玩。


接下来就是自行编译OpenWrt的玩法,如果不想编,直接去官网下载预编译的镜像也完全ok。该镜像内置了基于Pi 4B的所有硬件驱动,也包括802.11nac的wifi支持,刷机后直接使用没有任何问题。

Method #2: Feel free to build the OpenWrt and run it on the bare metal Pi 4B, or a prebuilt image can be downloaded from OpenWrt official website then you don’t have to build that on your own.

默认设定是br-lan连接eth0,无wan口。因其为单臂路由(没有两张物理网卡),我把br-lan口连接改为 eth0.120 ,wan口设定为 eth0.12 ,当然交换机需要是802.1q VLAN switch,保存设置后正常上网就可以了。

PS:更改lan口vlan id设置的过程,最好走wifi,这样就不会在设置过程中断线。当然还有个选择就是把vlan id 1留给一个接口(无论wan还是lan),随意就好。

对单臂路由在内网进行iperf3带宽测试,MTU 1500就不改了,差不多可以跑满(下图右下)。由此可见,Pi 4B的全双工千兆网靠得住,作为单臂路由没问题,同时跑满带宽的资源消耗也不高。

完整阅读本篇»

“Case Closed”

2022-12-23 作者:

So the MK-III finally got its (3D-printed) case, now the case is closed.

Yep, case closed!

Sure the case is kinda rough (sorry, 1st time stuff there…), it still reminds me of the TARS, I don’t know why though.

完整阅读本篇»

Indoor Weather Station IoT – Mk III

2022-12-11 作者:

Now it’s Mark III, having a self-designed simple carrier board with all dev kits mounted on it – seems working reliably.

室内气象采集节点,Wifi + 有线以太网两网通用,uPy固件。需要接HA的话,可以用restful sensor请求板端API,已经试过了,没毛病。这样玩的话,板子固件功能可以比esphome生成的更具自由度。

不要问我carrier board为啥选了白色,对我玩相机有印象的哥们,应该知道我备机(EOS-M3)就自己配的熊猫色,至今喜欢。

距离上次做layout,我算了一下15年有余。好在我不在乎外观,没打算从零画起,就只做了块载板。那么工作量自然也低,连原理图一起一天搞定。至于产出质量么……话说下单有点快,下完单回头review schematics发现电容接错了,又改了一版立即重新下单。

然后摩拳擦掌天天等快递,板子到手后,上电一遍过。当然一张底板,着实也是简单。

考虑到如果很多节点,server挨个请求node吧也不大合理,所以还做了个配置api地址,然后主动post数据的功能。

要问为啥不搞mqtt,呃,懒得摸新东西算个理由不?

折腾了半天,还以为想找个靠谱的asyncio http client有困难,结果还是有大佬给移植好了一版能用的

到今天,算下来已经有三个版本了,只用业余时间,外加陪娃的话,感觉效率还凑合?

最近疫情放开,年底很多活儿堆在头上,加班免不了咯……什么时候才有精力做个壳体试试呢?

完整阅读本篇»

基于RPi和LXD的ESP32开发环境

2022-11-22 作者:

对于在板子手动重启时经常把ESP32带进下载模式的问题,LAN8720所需的上/下拉电阻恐怕是最大嫌犯。于是斥巨资近CNY 10元采购了万用板、线仔包和各种直/弯母座,终于搞了MKII —— 重启可靠性问题果然迎刃而解。

过程中,基于lxd的Debian in Debian做了套新环境,顺手也试了试C语言的esp-idf编译,用起来整体感觉很顺手。

RS232 connected with an lxc in raspberry pi 4b (not in pic)

Yes, it actually performs nicely to work on ESP32 development in debian bullseye LXD in Pi OS, no mater you’re working on hardcore C lang based esp-idf or the nice & easy micropython development.

“Hmm… so you need a standard Debian in a derived Debian? “

Well, since I found out that LXD is something very helpful to isolate different needs on different Linux distributions in different containers, while it kinda works pretty much like vm (instead of docker) since it’s easy to config the resources consumption or even usb devices pass-through, and the most important – having its own block storage which can be exported into a single archive.
Then, the only thing I can’t agree with, could be the deep connection with the snapd. Instead of switching to another distribution, such as Arch, I choose to build the LXD of my own (on both Pi OS aarch64 and Ubuntu 22.04 X86_64). Thanks to the good documentation, the stuff (native lxd without the snap crxp) works like a charm.

with Xfce and xrdp, the bullseye lxc can work as an esp dev server quite well

完整阅读本篇»