OTA update service

91 Views Asked by At

I have a system composed by devices that control irrigation which connect to my server via ports TCP:8500-8509 when they are required to have a firmware update.

In the server, for each port I have a listener created in bash as follows:

for loop in {0..9};
do
    port=$loop
    ((port+=8500))
    netstat -at | grep $port
    if [[ $? -ne 0 ]] ; then
        ./updateservice2.sh $port $loop &
    fi
done

being updateservice2.sh as follows:

sudo socat -d -d TCP-LISTEN:$1 PTY,link=/dev/ttyVA$2,raw,echo=0 &
pid=$(lsof -ti tcp:$1)

flag=0
while true
do
    netstat -at | grep :$1 | grep ESTABLISHED
    if [[ $? -ne 1 ]] ;  then
        ./microchipboot -port /dev/ttyVA$2 -profile profile.yaml Valve_controler_NBIOT.X.production.hex
        flag=1
    else  
        sleep 1
        if [[ $flag -eq 1 ]]; then
            kill -9 $pid
            exit
        fi
    fi
done

In summary, I do a loop in socat between the listening port and a virtual serial tty, which feeds the bootloader application (microchipboot). The bootloader application only accepts serial port.

This is working perfectly, but it is quite static in terms that the devices need to connect to ports from 8500 to 8509, and this is kind of hardcoded (depends on serial number). I have then a maximum of ten concurrent updates.

I want the devices always connect to only 1 port (8500), then upon each accept, a child is created (fork) so that each remote address is connected to a local tty, launching the bootloader application against the created tty.

I think this is a basic OTA service or even a web server behaviour (one listening port, many concurrent and independent clients) but ending on a serial port. In other words, if 50 devices connect concurrently, 50 serial ports need to be created together with 50 instances of the bootloader application (written in golang).

I tested socat in many variants, also in combinations with python, but i am not able to get a solution let´s say multi-client <-- one port listening in server--> multi-serialport. Maybe a docker approach?? I don´t know... Have in mind that now I have around 100 conected devices under an IOT network which taked around 5 minutes to upload 60k of code... so i need the most concurrency possible...

Any idea?? many thanks in advance!!

0

There are 0 best solutions below