Getting device output on 'first boot' during provisioning

graceyoung-ww
Posts: 4
Joined: Sun Mar 20, 2022 8:24 am

Getting device output on 'first boot' during provisioning

Postby graceyoung-ww » Mon Mar 21, 2022 3:32 am

Hi there.

I'm currently researching how best to provision our devices in a multi-step manufacturing process. We are planning to use python as our framework for doing this.

There is some on-device information that we wish to capture from the device during provisioning, that will then be used for device registration with our other systems. For example the IMEI of an attached LTE module which is used for certain downstream registration functions.

I'm wondering if anyone has solved this in the past, and how?

For example, the device could:
1. emit this information to the serial output as text (i.e. on first boot), or
2. it could send it to a separate web server, or
3. we could build some custom protocol for the python script to communicate with the device.

If we look at option 1—capturing the serial output during provisioning:

I haven't found any "definitive" docs on the best way to capture the device's serial output outside of an IDE (for example, idf.py monitor requires a CMakeLists.txt file, which we wouldn't have in the production environment). We could potentially use screen and capture output via a sub-process, but timing this might be a challenge.

Is there a more effective or "best practice" way to do this?

Thanks in advance. Grace

P.S. Please let me know if there is a better sub-forum for questions of this nature.

graceyoung-ww
Posts: 4
Joined: Sun Mar 20, 2022 8:24 am

Re: Getting device output on 'first boot' during provisioning

Postby graceyoung-ww » Mon Mar 21, 2022 8:03 am

One resolution that I've come up with, since originally posting this, is using the python serial library, for example:

Code: Select all

import serial
import time
ser = serial.Serial(DEVICE_PORT, 115200, timeout=1)
ser.flushInput()

device_id = None

t_end = time.time() + 5
while time.time() < t_end:
    try:
        ser_bytes = ser.readline()
        decoded_bytes = ser_bytes[0:len(ser_bytes)-2].decode("utf-8")
        # print(decoded_bytes)
        if ('<my token>:' in decoded_bytes):
            my_value = escape_ansi(decoded_bytes.rsplit(': ')[-1])
            break
    except Exception as e:
        print(e)
        break
I'm still interested in other's experiences and "best practices" as to how to implement this sort of interaction, if there's other ideas/views on how this should be done.

Thanks in advance.
Grace

Who is online

Users browsing this forum: amiral, johnny_henriksen and 98 guests