Verifying Local Control Functionality using Scripts
After introducing how to create a local control module, this section
will further introduce how to use scripts for verification. Here, we use
the official example esp_local_ctrl
as an example for verification.
- Create a certificate for TLS handshake between the client and the server.
-
Generate a
rootCA
that will be used to sign the server-side certificate, and the client will use it to verify the server-side certificate during the SSL handshake. A passphrase needs to be set to encrypt the generatedrootkey.pem
.$ openssl req -new -x509 -subj "/CN=root" -days 3650 -sha256 -out rootCA.pem -keyout rootkey.pem
-
Generate a certificate signing request and its private key
prvtkey.pem
for the server.$ openssl req -newkey rsa:2048 -nodes -keyout prvtkey.pem -days 3650 -out server.csr -subj "/CN=my_esp_ctrl_device.local"
-
Use the previously generated
rootCA
to process the server-side certificate signing request and generate the signing certificatecacert.pem
. The passphrase set earlier for the encryptedrootkey.pem
must be entered in this step.
Among the generated certificates,$ openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootkey.pem -CAcreateserial -out cacert.pem -days 500 -sha256
cacert.pem
andprvtkey.pem
are compiled into the server, androotkey.pem
is suitable for client-side scripts for server-side verification. The directory of the certificate can be set in the scriptesp_local_ctrl.py
.def get_transport(sel_transport, service_name, check_hostname): ... example_path = os.environ['IDF_PATH'] + '/examples/protocols/esp_local_ctrl' cert_path = example_path + '/main/certs/rootCA.pem' ...
-
Use the following command to connect to the local control server via script. If
sec_ver
is 0, it means thatPROTOCOM_SEC0
is set on the server.$ python esp_local_ctrl.py --sec_ver 0
The script will automatically get the property value, i.e.:
Connecting to my_esp_ctrl_device.local ==== Starting Session ==== ==== Session Established ==== ==== Available Properties ==== S.N. Name Type Flags Value [1] status STRING {"status": true}
-
According to the script prompt, enter the attribute number "1", and set the attribute value to
{"status": false}
. Then the script will automatically start querying and find that the property value has been changed.Select properties to set (0 to re-read, 'q' to quit) : 1 Enter value to set for property (status) : {"status": false} ==== Available Properties ==== S.N. Name Type Flags Value [1] status STRING {"status": false} Select properties to set (0 to re-read, 'q' to quit) :