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

完整阅读本篇»

ESP32 + Microdot + uPy-uasyncio

2022-11-12 作者:

基于ESP32和micropython制作的家用温湿度计原型机。可通过网页控制GPIO和OLED显示,为HA等其他服务提供访问环境传感器的实时数据API。使用uasyncio的协程实现非抢占式的异步多任务控制,估测效果应该不如基于C的RTOS,但胜在代码量小,写起来简单吧。

This ESP32 and micropython-uasyncio based indoor ambient sensors are basically working as expected, with web-controlled OLED display, and a quite simple http api for other services like home assistant to query the realtime data. The multitasking runs on non-preempt Python coroutine, which is theoretically incompetent against those C + RTOS stuff, but it wins on simplicity from my point of view, so far at least.

Hardware components:

  • NodeMCU (ESP32-WROOM-32E)
  • 1.3 inch OLED (SH1106, SPI/I2C, 128×64)
  • BME280 sensor (ambient temperature, relative humidity, barometric pressure)

Software libs:

  • Micropython 1.19.1 (for ESP32)
  • Microdot (minimalistic Python web framework which supports uasyncio)
  • Driver libs of all hardware components.

完整阅读本篇»

ESP32 + uPython + uaiohttpclient

2022-11-05 作者:

Updated 2022-12-01: Let go this rough  uaiohttpclient since it’s kind too simple (just GET, no POST, and lacking almost anything needed) to be integrated to something really useful. So currently I’m using someone’s own stuff (async mod on urequests) that works – from the REPO HERE.


This is a basic test around the async http client of micropython, which is NOT built-in with the official uPy image on download page of offcial site. Anyway it can be easily installed thru the  upip  – make sure you have sufficient free RAM before the installation though, otherwise it could fail.

I somehow guess that the reason it’s not included in standard build might be… the asyncio is not quite common among the uPy developers? So people can use the built-in urequests instead.

Well I’m not an async – await Python guy on Mac/Linux either (since we’ve an powerful O/S anyway), but here I consider it might be the only method, AFAIK, to make my ESP32 nodeMCU work with kinda multi-tasking with uPy, non-preemptive, though. If not, then I’m about to be left with no choice and head back to the C stuff (with a traditional RTOS), right?

完整阅读本篇»

基于Flask的简易webtelnet和webssh

2020-02-25 作者:

Chinese version README of the Github repo – flask-remote-terminal.

简而言之,一台具备多用户支持的,仅限使用telnet/ssh,访问远程固定地址的,web终端。

演示截图:


有啥稀罕的

  • 只可访问远程地址,非本机终端
  • 目前仅限telnet(支持十几年前老设备用)和ssh访问,代码中也可增加其他协议,但始终受控
  • 仅限访问固定远端地址(IP/域名),代码config可配,一旦服务运行后不可更改
  • 服务端session存储pid和fd等,用于多用户支持


参考项目


需求如此“扭曲”,何解

通过web终端去管理一台特定的中转机,其多数端口是(在特定时间段内)代理到真正需要管理的目标机。具体需求如下:

  • 同多数web terminal一样,浏览器即开即用,免安装
  • 只允许访问特定地址(中转机),避免被抓肉鸡
  • 只允许使用telnet和ssh进行连接,不可自选其他客户端命令,在此基础上允许用户自行输入用户名和端口号
  • 只用于远程连接,在用户exit退出终端后,也无法回到shell操作提供该服务的server
完整阅读本篇»

基于阿里云API实现简单DDNS

2019-02-28 作者:

This is a post talking about using Aliyun Domain Control API (and python sdk as well) to script a simple, self-own ddns service, with only one assumption – a public ip over WAN port of your router.

 

原始状态

光猫 <—> R7000主路由 <—> 需要出门的母鸡+小鸡们

 

设计思路

  • 办法1:破解光猫,将光猫与R7000桥接。
    • 优势:内网只有一层,简洁明了。
    • 劣势:打N通电话,下N多工具,还要将独立IPTV信道映射或proxy到R7000的某个LAN口。
  • 办法2:硬件不做任何变动,添加两层映射。
    • 优势:实施安全性高。
    • 劣势:理论上,走ddns经双层转发,传输性能受影响。
  • 总结:人老色衰,首选安全方案。

 

网络拓扑

【更新】代码已推至github,欢迎加星。

完整阅读本篇»

微信oAuth错误码10003最速解法

2018-04-06 作者:

服务号code两年没更新,最近花时间做了彻底重构,说白了差不多重新开发

填坑无数,信心上线后,点公号菜单跳页面时,遇到如下问题

redirect_uri域名与后台配置不一致,错误码:10003

OK,梳理一下,我的后台配置成啥了?(more)

完整阅读本篇»