09 Automatically Send Instructions When Powered On
Automatically Sending Commands at Boot
This tutorial explains the commands that the upper computer automatically executes and sends to the lower computer every time it boots. The code blocks in this tutorial do not need to be executed (nor can they be executed); they are only meant to help you understand the automatic operations of the product after booting. If needed, you can modify or add these commands.
cmd_on_boot() Function
The cmd_on_boot() function is located in the product's main program app.py. This function is called every time the system boots. You can edit this function to adjust parameters or add commands that will run automatically at boot.
def cmd_on_boot():
# Define the list of commands to be executed at boot
cmd_list = [
'base -c {"T":142,"cmd":50}', # set feedback interval
'base -c {"T":131,"cmd":1}', # serial feedback flow on
'base -c {"T":143,"cmd":0}', # serial echo off
'base -c {"T":4,"cmd":2}', # select the module - 0:None 1:RoArm-M2-S 2:Gimbal
'base -c {"T":300,"mode":0,"mac":"EF:EF:EF:EF:EF:EF"}', # the base won't be ctrl by esp-now broadcast cmd, but it can still recv broadcast megs.
'send -a -b' # add broadcast mac addr to peer
]
# Iterate through the command list
for i in range(0, len(cmd_list)):
camera.cmd_process(cmd_list[i])
The upper computer can perform various functional controls via command line instructions. For example, the base -c command directly passes the following JSON command to the lower computer through the Raspberry Pi's GPIO serial port. Below we explain the meaning of the default commands that run automatically at boot.
- base -c {"T":142,"cmd":50}
Sets the extra interval time for continuous feedback from the lower computer. The value of cmd is in milliseconds. This function reduces the frequency of feedback from the lower computer to lighten the computational load on the upper computer when processing feedback information.
- base -c {"T":131,"cmd":1}
Enables continuous information feedback from the lower computer. When this function is enabled, the upper computer does not need to request feedback one‑by‑one. The lower computer normally enables this function by default, but we send the command again for safety.
- base -c {"T":143,"cmd":0}
Disables serial command echo. When this is off, the lower computer will not echo received commands back to the upper computer, preventing the upper computer from processing unnecessary information.
- base -c {"T":4,"cmd":2}
Sets the type of external module. When cmd is 0, it means no external module; 1 means a robotic arm; 2 means a pan‑tilt. If your product does not have a pan‑tilt or robotic arm, you should change this value to 0.
- base -c {"T":300,"mode":0,"mac":"EF:EF:EF:EF:EF:EF"}
Prevents the chassis from being controlled by ESP‑NOW broadcast from other devices (except the device with the specified MAC address). You can make up any MAC address or use the MAC address of your own ESP32 remote control.
- send -a -b
Adds the broadcast address (FF:FF:FF:FF:FF:FF) to the peer list, so you can later send broadcast messages to other devices directly via broadcast signals.
Other upper computer command line instructions can be learned in the later chapter "Web Command‑Line Application".