基于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

完整阅读本篇»

HAOS集成和风天气

2022-09-27 作者:

室内搞完了,室外就别搞传感器了,直接走api拉数据。

系统默认集成的OpenWeather和AccuWeather都不太靠谱,前者填了api key后报无效,后者是数据离实际差距大+免费api次数不够用,最后还得自己搞国内的天气服务API。

注册了高德、和风两家,后者虽然没有前者的品牌,但毕竟数据种类更齐全,用来练手是不错的。

效果如下:

至于怎么安装,其实什么插件都不用装,直接File Editor插件编写 /config/configuration.yaml ,保存无误后,重启服务即可。

【注】重启服务,只需要“配置”->“系统”->“重新启动”。这个过程很快,30s搞定。不需要重启整个HAOS的vm或者物理机,那个时间要长很多。

要写什么内容呢?

完整阅读本篇»

PVE + HomeAssistant + ESPHome

2022-09-24 作者:

Today let’s try out this ESP32-C3-12F dev board that costs only $5 (domestic shipping included) but has 3 power supply mode (AC 220V, DC 7~12V and microUSB, which is super convenient!) and a relay to turn my ordinary led light strip to be a remote controlled.

记得上次玩Arduino已经是2014年的事情了,那会儿用的还是ATMega系列的MCU,装专用IDE,写的C lang。

近10年后,感觉家用IoT玩的都是ESP和Pico了。至于开发语言,常青树C lang自然还有的,但大多视频教程则是外行更容易上手的Micro Python、Lua乃至只要配个yaml config的ESP Home —— 可见贵圈也很卷。

今天搞的是这块ESP32-C3-12F,带wifi、蓝牙BLE和一路继电器,以上都属于一般配置。比较巴适的是,这货带三模供电,AC 220V、DC 7~12V,以及MicroUSB,这就很方便了,省一个手机充电头。

废话少叙,先看实验结果吧。

服务器自然是Proxmox VE Home Server上的vm,数据内网本地化存储(2C 2G 32G即可),公网使用走ddns没毛病。

【注】HAOS(Home Assistant Operating System)的部署有N多选择。支持X86物理机、至少三种VM(kvm、vbox、vmware)、三种主流操作系统(Linux、Win、MacOS),两种容器(docker、lxc)、以及包括树莓派在内的至少三种SBC…… 这友好程度,你要说自己小白不会安装,都对不起开发者。只是这里要注意,选择安装方式一定要带上Supervisor,否则无法支持ESPHome扩展,详情参阅官网文档

HAOS装好后,打开web服务,安装ESPHome的插件,打开后就能开始设计ESP固件了。

完整阅读本篇»

nginx控制iptables芝麻开门

2022-02-10 作者:

During maintenance of a production server, we use to encounter a problem like this – an internet-access-blocked port, say 3306 (mysql), is about to be open for a little while due to debugging needs, which is not uncommon, right? So how to make this easily operated, mostly secure, and automatically disabled after working – I guess this’s gonna help somehow.

A Linux server with whatever the distribution including iptables (e.g. CentOS, Rocky for now as example), Nginx, fcgiwrap, a simple shell script and a commonly used web browser, let’s say chrome, will be major ingredients on the recipe.

常做运维,总会遇到某些线上服务器,为了便于调试,在符合安全要求的基础上,需要相对便利的对公网短时定向开放某些端口。

昨天想了一招,用nginx操作shell脚本,对特定公网IP开口子,叫一声“芝麻开门”,便捷又安全。举例端口3306(mysql),系统是Rocky Linux 8(原CentOS 8)。

Doors of Durin

Doors of Durin

先查一下现有的防火墙规则,需要的话可以保存一下。换句话说,搞芝麻开门之前,先确定门是隐藏的;也即已经有相应(且持久化)的iptables rule确保到被保护端口的连接是DROP/REJECT状态。

然后就是fcgiwrap的安装,此处就不写nginx安装过程了,默认安装即可。

安装后增加两个systemd服务文件,并测试fcgiwrap服务生效。

【注】那俩服务文件,在Redhat之外的发行版上,fcgiwrap安装包可能自带,请针对所用版本自行检查。

接下来为一个新的nginx server准备个根目录,存放网页和之后控制iptables的脚本。

完整阅读本篇»

树莓派监控SANTAK UPS

2022-01-07 作者:

硬件:SANTAK TG-BOX 600 + RPi 4B (2GB) + Huawei ME909s-821

监控服务:NUT(Network UPS Tools)参考文章挺多,就不详解了;Pi上连了4G模块主要是掉电时可能无法得到Wired Ethernet供应,就发个短信而已,不如直接走wwan靠谱省心。

目前用的是standalone模式,回头有空查下文档试试netserver模式,看config文件介绍,猜测是client可以通过server知道市电挂了,从而在server之前关机?

完整阅读本篇»

OpenWrt测试双WAN和双机高可用

2021-12-03 作者:

So here’s a quick example. OpenWrt shows capability to provide business-level internet access reliabilities – with not only load balancing/failover between 2 or more ISPs, but also VRRP based hardware (dual x86 vm in this experiment) level redundancy.

从以下的例子可以看出,OpenWrt基本满足了提供小型商业级Internet访问可靠性的初步要求。它不仅可以在多个ISP之间实现负载均衡以及故障切换,在此基础上同时提供基于VRRP的硬件冗余(本实验中为双x86虚拟机)。

 

先开仨虚拟机,前两台做OpenWrt,可以先做1台,复制1台。注意要安装mwan3和keepalived。

 

双WAN做好后,断开一路wan做测试。这里的wanb,用的是楼道里的不可靠wifi,通过Raspberry Pi向下路由一层转成有线网,能体现出不稳定的ISP接入状态。

本来是两路负载均衡的策略,wanb断开后,5s之内可以让所有对外请求都稳定落在wan上。

 

下一步,把MASTER的br-lan断开,模拟一个路由器硬件直接宕掉。

 

这个切换时间很短,还没反应过来,BACKUP就接管了VIP地址,对外请求几乎不受什么影响。

完整阅读本篇»