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.

  1. Create a certificate for TLS handshake between the client and the server.
  1. 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 generated rootkey.pem.
    $ openssl req -new -x509 -subj "/CN=root" -days 3650 -sha256 -out rootCA.pem -keyout rootkey.pem
  2. 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"
  3. Use the previously generated rootCA to process the server-side certificate signing request and generate the signing certificate cacert.pem. The passphrase set earlier for the encrypted rootkey.pem must be entered in this step.
    $ openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootkey.pem -CAcreateserial -out cacert.pem -days 500 -sha256
    Among the generated certificates, cacert.pem and prvtkey.pem are compiled into the server, and rootkey.pem is suitable for client-side scripts for server-side verification. The directory of the certificate can be set in the script
    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'
  1. Use the following command to connect to the local control server via script. If sec_ver is 0, it means that PROTOCOM_SEC0 is set on the server.

    $ python --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}
  2. 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) :