ESP32 折腾小记

接线

USB UART ESP32-CAM
TX U0R
RX U0T
DTR IO0
5V 5V
GND GND
注意不能接VCC 要接5V

安装相关包

pip install esptool picocom adafruit-ampy pyserial

烧录命令

下载固件
https://github.com/lemariva/micropython-camera-driver/tree/master/firmware
烧录 需要短接IO_0和GND 才能进行烧录
/opt/homebrew/bin/esptool.py –chip esp32 –port /dev/cu.SLAB_USBtoUART erase_flash
/opt/homebrew/bin/esptool.py –chip esp32 –port /dev/cu.SLAB_USBtoUART –baud 460800 write_flash -z 0x1000 ~/Downloads/micropython_cmake_9fef1c0bd_esp32_idf4.x_ble_camera.bin

配置vscode

https://lemariva.com/blog/2019/08/micropython-vsc-ide-intellisense
可以使用Pymakr 插件

上传到硬件中

ampy put boot.py

远程连接

http://www.1zlab.com/wiki/micropython-esp32/repl-over-the-serial-port/
picocom -b 115200 /dev/cu.SLAB_USBtoUART
也可以安装WebREPL 网页控制

后续远程监控,图像识别

下半年学习规划

下半年学习规划

以往学习的比较杂乱,现在统一制定下下半年的学习规划,年底截止,完成的打钩

阅读

  • 财经类两本
  • 悬疑、科幻、历史类
    • 《明朝1566》
    • 《白夜行》
    • 《放学后》
  • 英语阅读

工程能力

  • 掌握GO编程、阅读3本相关书籍、并重构IOT通信系统
  • 掌握Docker应用、阅读1本相关书籍,时间富足可以学习Kubernetes
  • 掌握Redis、MySQL集群的使用,并深入了解
  • 掌握Python的高级使用,并参加Kaggle比赛

算法能力

  • 学习基本的机器学习知识并应用起来
    • 线性回归
    • 逻辑回归
    • 神经网络
    • 算法评估
    • 支持向量机
    • 聚类
    • 异常检测
    • 实战
  • 学习深度学习相关知识
  • 复习数据结构和算法,参考书籍算法导论

Docker使用

  Docker使用Google公司推出的Go语言进行开发实现,基于Linux 内核的cgroup,namespace,以及 AUFS 类的Union FS等技术对进程进行封装隔离,属于操作系统层面的虚拟化技术。由于隔离的进程独立于宿主和其它的隔离的进程,因此也称其为容器。Docker 在容器的基础上,进行了进一步的封装,从文件系统、网络互联到进程隔离等,极大的简化了容器的创建和维护。而虚拟机会虚拟出一套硬件,在其上运行一套操作系统, 因此Docker 技术比虚拟机技术更为轻便、快捷。

快速上手

安装

curl -sSL https://get.docker.com/ |sh
注意使用国内镜像源

运行

docker run --name demo -it -d centos

基本概念

镜像

镜像是一个特殊的文件系统,除了提供容器运行时所需的程序、库、资源、配置等文件外,还包含了一些为运行时准备的一些配置参数(如匿名卷、环境变量、用户等)。镜像不包含任何动态数据,其内容在构建之后也不会被改变。在构建的过程中是一层一层构建的,前一层是后一层的基础,每一层构建完就不会发生改变。
相关命令:


Usage:docker image COMMAND Manage images Commands: build Build an image from a Dockerfile history Show the history of an image import Import the contents from a tarball to create a filesystem image inspect Display detailed information on one or more images load Load an image from a tar archive or STDIN ls List images prune Remove unused images pull Pull an image or a repository from a registry push Push an image or a repository to a registry rm Remove one or more images save Save one or more images to a tar archive (streamed to STDOUT by default) tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

容器

  容器可以理解为镜像运行时的实体,可以被创建、启动、停止、删除、暂停等
相关命令:

Usage:docker container COMMAND
Manage containers
Commands:
  attach      Attach local standard input, output, and error streams to a running container
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  inspect     Display detailed information on one or more containers
  kill        Kill one or more running containers
  logs        Fetch the logs of a container
  ls          List containers
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  prune       Remove all stopped containers
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  run         Run a command in a new container
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  wait        Block until one or more containers stop, then print their exit codes

注意事项:

  • 在执行命令的时候推荐用exec而不是attach,避免exit的时候容器退出
  • 可以使用inspect 命令查看容器详细信息,使用logs命令查看相关日志,用于定位错误
  • 容器与容器之间默认是无法互联的,可以使用docker-compose部署或使用link参数在运行时组网,不过建议使用docker create network命令构建网络

仓库

镜像存储分发的地方,类似于GITHUB,推荐使用阿里云做加速

其它内容

数据管理

数据卷

数据卷 是一个可供一个或多个容器使用的特殊目录,它绕过 UFS,可以提供很多有用的特性:

  • 数据卷可以在容器之间共享和重用

  • 对数据卷的修改会立马生效

  • 对数据卷的更新,不会影响镜像

  • 数据卷默认会一直存在,即使容器被删除

 docker volume create my-vol
 docker volume ls
 docker volume rm my-vol

网络连接

  • -p 映射 TCP/UDP 不一样
  • 创建网络
  • 容器互联

DockerFile的编写

  • 参考网上教程

Compose的使用

  • 使用PIP安装,安装后创建compose文件即可使用,管理起来比较方便而且默认是互联的

Kubernetes的使用

一些示例

Docker run --name test -it -d centos bash 启动交互式命令行
Docker run --name redis -it -d redis redis-server --appendonly yes -v /home/work/data/redis:/data 使用AUFS在宿主机保存Redis数据
Docker run --name test -it -d -p 23:22  centos bash 端口23 映射到22

生活

  又很久没来了,最近一个半月好像也没特别重要的事发生,去了趟丽江、大理,陪老婆孩子回了趟扬州,也提了晋升材料,平平淡淡。
  最近生活也挺枯燥的,上班、回家、哄孩子、做饭、睡觉,日子一天天过,总觉得少了点什么。刚刚出去打乒乓球浑身湿透,感觉挺好的,生命在于运动,运动中无其它杂念,也是畅快。
  上学的时候一心想赚钱,会想着什么时候能挣到自己的第一个五十万、一百万,想着什么时候能工资到五十万、一百万。现在回过头来看,反而觉得没这么重要了,简单的生活、简单的人际关系未尝不好,每个人追求的不太一样,我更倾向于精神与身体上的自由。
  今年投资很失败,累积亏损了7万左右,投资本来没什么确定性的东西,是我承受能力太差、太贪心、自制力不强,或许本不该做这件事。原本只想跑赢通胀,却输了很多时间和金钱,得不偿失了。
  竟然都8月了,一年又一年,又收获了什么呢?
  

squid 配置HTTPS代理

从源代码编译:(编译的squid必须是3.3或以上的版本。2.x版好像没有加密代理功能)

 yum install openssl openssl-devel  gcc-c++ bzip2 gcc perl

(如果你的系统是DEBIAN/UBUNTU,则需运行命令:

apt-get install openssl libssl-dev gcc g++ bzip2 perl

否则编译时,会遇到错误提示:configure: error: library ‘crypto’ is required for OpenSSL。参见
http://superuser.com/questions/371901/openssl-missing-during-configure-how-to-fix)

wget http://www.squid-cache.org/Versions/v3/3.5/squid-3.5.7.tar.bz2
tar jxvf squid-3.5.7.tar.bz2
cd squid-3.5.7
./configure --prefix=/usr --sysconfdir=/etc/squid --libdir=/usr/lib --with-openssl
--enable-basic-auth-helpers="LDAP,MSNT,NCSA,PAM,SASL,SMB,YP,DB,POP3,getpwnam,squid_radius_auth,multi-domain-NTLM" --with-swapdir=/var/spool/squid --libexecdir=/usr/lib/squid
make (此步骤耗时15分钟)
make install

配置squid,(修改SQUID的配置文件squid.conf)
然后修改Squid的配置文件。把http_port变成https_port ,修改监听的端口号为443:

https_port 443 cert=/etc/squid/public.crt key=/etc/squid/private.key

其中cert和key分别是网站的HTTPS证书和私钥。在/etc/squid/目录中,运行openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout private.key -out public.crt即可生成public.crt和private.key 。注意:监听的端口号必须设为443.否则squid启动不了。
chrome支持https类型的代理。启动chrome的时候在末尾加上–proxy-server=https://vps-ip:443 –ignore-certificate-errors即可。注意,把这里的vps-ip换成你的服务器的ip。
全配置好之后,用chrome浏览器即可翻墙。

证书可以用商业证书,自己生成的比较麻烦。。

启用用户认证了。

具体方法如下:yum install httpd (debian/ubuntu系统下,则apt-get install apache2)这样你的系统上就会出现htpasswd命令。然后在/etc/squid/目录里,运行htpasswd -cb /etc/squid/users jones fx5rm31s上述命令将生成密码文件users.(jones和fx5rm31s分别为你指定的用户名和密码)然后,编辑/etc/squid/squid.conf文件,在http_access deny all那一段的上方,插入:

auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/users
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
acl normal proxy_auth REQUIRED
http_access allow normal
auth_param basic casesensitive off

然后重启squid,即可启用squid的认证机制。