Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the simply-static domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6121
树莓派自动开关机执行延时录像

树莓派自动开关机执行延时录像

esp32侧程序,功能有3个,1、是连接Wi-Fi同步网络时间,2、是通过UART口跟树莓派进行通信,检查树莓派是否在预定时间内工作或关机,3、根据时间段控制树莓派开机或关机。该程序在esp32上的文件名为main.py(记得要改名),这样esp32一通电即可工作。程序如下:

上位机(树莓派)与esp32的通信程序check.py,程序如下:

import serial
Port = "/dev/ttyAMA0"
ser = serial.Serial(Port, baudRate, timeout=10)
while True:
   send = '2'
   ser.write(send.encode())
   str = ser.readline().decode()
   if(str !=""):
      print(str)
ser.close()

该程序需要开机自动运行,具体可以将其加入rc.local,具体:

sudo nano /etc/rc.local

在最后一行前加入:python check.py,保存退出重启即可

注意:

树莓派使用串口需要进行以下工作:

1、sudo raspi-config

根据以下步骤进行设置:

选择Interfacing Options

选择serial

再选择 no,禁用串口登录功能,将串口用于通信。
再选择 yes,启动串口硬件。
禁用蓝牙(硬件串口与mini串口默认映射对换

接线:(树莓派(左)——esp32(右))

RXD(GPIO15) <——> TXD(IO12)、TXD(GPIO14) <——> RXD(IO13)、GND <——> GND

sudo nano /boot/config.txt

在打开的文件最后面添加:
(注意:树莓派4b也一样是pi3)

dtoverlay=pi3-disable-bt

修改保存后重启树莓派:

reboot

安装serial,具体如下:

sudo apt-get install python3-serial