cd ~
git clone https://gitee.com/EspressifSystems/esp-gitee-tools.git
git clone https://gitee.com/EspressifSystems/esp-idf.git
ls
cd esp-idf
git checkout v4.4.1
cd ~/esp-gitee-tools
./submodule-update.sh ~/esp-idf/
./install.sh ~/esp-idf/
. /home/peter/esp-idf/export.sh
idf.py build
cd ~/esp-idf/
source export.sh
cd ~
git clone https://gitee.com/CHN_ZC/micropython.git
sudo chmod a+rwx micropython
cd ~/micropython
make -C mpy-cross
cd ports/esp32
make submodules
make
1.1.4. 测试模块
Python文件模块放在esp32下的modules文件夹,进入该文件夹:
cd modules
新建一个测试用的python文件,如下:
nano test.py
文件内容如下:
from time import sleep
def hello():
print("hello world")
def hw(str):
print(str)
def cycle(str):
while True:
print(str)
sleep(1)
def wlan_connect(ssid='MYSSID', password='MYPASS'):
import network
wlan = network.WLAN(network.STA_IF)
if not wlan.active() or not wlan.isconnected():
wlan.active(True)
print('connecting to:', ssid)
wlan.connect(ssid, password)
while not wlan.isconnected():
pass
print('network config:', wlan.ifconfig())
This script will mount the root filesystem read-only and overlay it with a temporary tempfs
which is read-write mounted. This is done using the overlayFS which is part of the linux kernel
since version 3.18.
when this script is in use, all changes made to anywhere in the root filesystem mount will be lost
upon reboot of the system. The SD card will only be accessed as read-only drive, which significantly
helps to prolong its life and prevent filesystem coruption in environments where the system is usually
not shut down properly
#
Install:
copy this script to /sbin/overlayRoot.sh and add “init=/sbin/overlayRoot.sh” to the cmdline.txt
file in the raspbian image’s boot partition.
I strongly recommend to disable swapping before using this. it will work with swap but that just does
not make sens as the swap file will be stored in the tempfs which again resides in the ram.
run these commands on the booted raspberry pi BEFORE you set the init=/sbin/overlayRoot.sh boot option:
sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo update-rc.d dphys-swapfile remove
#
To install software, run upgrades and do other changes to the raspberry setup, simply remove the init=
entry from the cmdline.txt file and reboot, make the changes, add the init= entry and reboot once more.
fail(){ echo -e “$1” /bin/bash }
Load overlay module
modprobe overlay if [ $? -ne 0 ]; then fail “ERROR: missing overlay kernel module” fi
Mount /proc
mount -t proc proc /proc if [ $? -ne 0 ]; then fail “ERROR: could not mount proc” fi
Create a writable fs on /mnt to then create our mountpoints
mount -t tmpfs inittemp /mnt if [ $? -ne 0 ]; then fail “ERROR: could not create a temporary filesystem to mount the base filesystems for overlayfs” fi
Mount a tmpfs under /mnt/rw
mkdir /mnt/rw mount -t tmpfs root-rw /mnt/rw if [ $? -ne 0 ]; then fail “ERROR: could not create tempfs for upper filesystem” fi
Identify root fs device, PARTUUID, mount options and fs type
rootDev=blkid -o list | awk '$3 == "/" {print $1}'
Changed here(point to / ) in case the cmd above doesn’t work # By ChenYang 20171122
Mount original root filesystem readonly under /mnt/lower
mkdir /mnt/lower mount -t ${rootFsType} -o ${rootMountOpt},ro ${rootDev} /mnt/lower if [ $? -ne 0 ]; then fail “ERROR: could not ro-mount original root partition” fi
Mount the overlay filesystem
mkdir /mnt/rw/upper mkdir /mnt/rw/work mkdir /mnt/newroot mount -t overlay -o lowerdir=/mnt/lower,upperdir=/mnt/rw/upper,workdir=/mnt/rw/work overlayfs-root /mnt/newroot if [ $? -ne 0 ]; then fail “ERROR: could not mount overlayFS” fi
Create mountpoints inside the new root filesystem-overlay
mkdir /mnt/newroot/ro mkdir /mnt/newroot/rw
Remove root mount from fstab (this is already a non-permanent modification)
grep -v “$rootPARTUUID” /mnt/lower/etc/fstab > /mnt/newroot/etc/fstab echo “#the original root mount has been removed by overlayRoot.sh” >> /mnt/newroot/etc/fstab echo “#this is only a temporary modification, the original fstab” >> /mnt/newroot/etc/fstab echo “#stored on the disk can be found in /ro/etc/fstab” >> /mnt/newroot/etc/fstab
Change to the new overlay root
cd /mnt/newroot pivot_root . mnt exec chroot . sh -c “$(cat <<END
# Move ro and rw mounts to the new root
mount --move /mnt/mnt/lower/ /ro
if [ $? -ne 0 ]; then
echo "ERROR: could not move ro-root into newroot"
/bin/bash
fi
mount --move /mnt/mnt/rw /rw
if [ $? -ne 0 ]; then
echo "ERROR: could not move tempfs rw mount into newroot"
/bin/bash
fi
# Unmount unneeded mounts so we can unmout the old readonly root
umount /mnt/mnt
umount /mnt/proc
umount /mnt/dev
umount /mnt
# Continue with regular init
exec /sbin/init
END )”
注意,我的脚本和帖子里面的有些不同,我把
rootDev=blkid -o list | awk '$3 == "/" {print $1}'
root-rw on /rw type tmpfs (rw,relatime) /dev/mmcblk0p2 on /ro type ext4 (ro,noatime,data=ordered) overlayfs-root on / type overlay (rw,relatime,lowerdir=/mnt/lower,upperdir=/mnt/rw/upper,workdir=/mnt/rw/work) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,relatime) devtmpfs on /dev type devtmpfs (rw,nosuid,size=470160k,nr_inodes=117540,mode=755) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755) tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k) tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd) cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct) cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=25,pgrp=1,timeout=0,minproto=5,maxproto=5,direct) debugfs on /sys/kernel/debug type debugfs (rw,relatime) sunrpc on /run/rpc_pipefs type rpc_pipefs (rw,relatime) mqueue on /dev/mqueue type mqueue (rw,relatime) configfs on /sys/kernel/config type configfs (rw,relatime) /dev/mmcblk0p1 on /boot type vfat (ro,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro) tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=94952k,mode=700,uid=1000,gid=1000)
原来的根文件系统 /dev/mmcblk0p2 改为挂载在 /ro ,并且是只读;/boot 也挂载为只读;而 / 的 type 变成了overlay。
(adnice) adnice:Downloads zhangyi$ python3 fake.py Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; SLCC1; .NET CLR 1.1.4322) Opera/9.80 (Windows NT 6.1; U; fi) Presto/2.7.62 Version/11.00 Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1500.55 Safari/537.36 Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:23.0) Gecko/20131011 Firefox/23.0 Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27 Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.2117.157 Safari/537.36 1 2 3 4 5 6 7 fake_useragent 报错及解决方案
报错信息:
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “d:\programdata\anaconda3\lib\site-packages\fake_useragent\utils.py”, lin e 166, in load verify_ssl=verify_ssl, File “d:\programdata\anaconda3\lib\site-packages\fake_useragent\utils.py”, lin e 122, in get_browser_versions verify_ssl=verify_ssl, File “d:\programdata\anaconda3\lib\site-packages\fake_useragent\utils.py”, lin e 84, in get raise FakeUserAgentError(‘Maximum amount of retries reached’) fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 首先找出关键报错信息:
fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached 1 大概意思是:这个模块尝试请求一个东西已达到最大重试次数
(edison) adnice:T zhangyi$ python3 Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) [Clang 6.0 (clang-600.0.57)] on darwin Type “help”, “copyright”, “credits” or “license” for more information.