reset after webrepl ota update

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
naute
Posts: 4
Joined: Wed Jul 07, 2021 9:06 am

reset after webrepl ota update

Post by naute » Wed Jul 07, 2021 10:09 am

Hello :) ,

I use an ESP-01 as a server on a private network to display data in a browser.

These data are generated by a program on the PC and transmitted in JSON format to the ESP-01 in a file named "data.js". I use the following command line to do this:

Code: Select all

./webrepl_cli.py -p password data.js 192.168.1.30:/html/data.js
which works very well but has the disadvantage of stopping the execution of the current script on the ESP-01 (main.py).
As in my case the manual reset is not practical, I use the following command line:

Code: Select all

./webrepl_client.py -p password 192.168.1.30 < <(echo "D")
which also works very well. So far, no problem.

To automate the process, I want to make the program that generates the data also take care of transferring it to the ESP-01.
However, when the program send the first command line, the file "data.js" is sent to the ESP-01, and so the process works, but when it send the second line, using the same process, the "reset" is not done (main.py doesn't restart), and the process sends me back the usage information, as when we execute "./webrepl_client.py" without any parameter, which indicates, by the way, that the process is working there too.

So the problem seems to be the parameters that are not suitable to send this command (a CTRL D in fact) other than from a terminal.

Does anyone have an idea to solve this problem, if it is possible?

Thanks in advance,
cordially,
naute

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: reset after webrepl ota update

Post by jimmo » Thu Jul 08, 2021 1:19 am

naute wrote:
Wed Jul 07, 2021 10:09 am
So the problem seems to be the parameters that are not suitable to send this command (a CTRL D in fact) other than from a terminal.
Yeah it sounds like something's going wrong with the way you're sending the Ctrl-D.

How does your automation work? How does it invoke webrepl_client.py?

I'm surprised that `echo "D"` works -- that would send a D (i.e 0x44). You need to send 0x04, which would be `echo -ne "\x04"`

naute
Posts: 4
Joined: Wed Jul 07, 2021 9:06 am

Re: reset after webrepl ota update

Post by naute » Thu Jul 08, 2021 9:11 am

Hello jimmo :) ,
thank you for your answer.
jimmo wrote: How does your automation work? How does it invoke webrepl_client.py?
My program is written in Pascal. To invoke this command, I use a library allowing to launch any external program by providing the name of the corresponding executable and the execution parameters if there are any.
Here is what my procedure looks like:

Code: Select all

 
  Process := TProcessEX.Create(nil);
  try
    with Process do
    begin
      Executable := './webrepl_client.py';
      Parameters.Clear;
      Parameters.Delimiter := ' ';
      Parameters.DelimitedText := '-p password 192.168.1.30 < <(echo "D")';
      Options := [poNoConsole, poWaitOnExit, poUsePipes];
      Execute;
      ShowMessage(Process.OutputString); // for testing during debugging
    end;
  finally
    Process.Free;
  end;
At runtime, "ShowMessage(Process.OutputString);" returns me :

Code: Select all

webrepl_client.py - remote shell using MicroPython WebREPL protocol
Arguments:
  [-p password] [-dbg] [-r] <host> - remote shell (to <host>:8266)
Examples:
  webrepl_client.py 192.168.4.1
  webrepl_client.py -p abcd 192.168.4.1
  webrepl_client.py -p abcd -r 192.168.4.1 < <(sleep 1 && echo "...")
Special command control sequences:
  line with single characters
    'A' .. 'E' - use when CTRL-A .. CTRL-E needed
  just "exit" - end shell
which is in fact the help that is displayed in the console when you invoke "webrepl_client.py" without parameters.

I don't think this procedure is at fault because I use it frequently without any problem, and that in this particular case, when invoking "webrepl_cli.py" (not to be confused with "webrepl_client.py") :

Code: Select all

  Process := TProcessEX.Create(nil);
  try
    with Processus do
    begin
      Executable := './webrepl_cli.py';
      Parameters.Clear;
      Parameters.Delimiter := ' ';
      Parameters.DelimitedText := '-p password data.js 192.168.1.30:/html/data.js';
      Options := [poNoConsole, poWaitOnExit, poUsePipes];
      Execute;
      ShowMessage(Process.OutputString); // for testing during debugging
    end;
  finally
    Process.Free;
  end;
"ShowMessage(Process.OutputString);" returns :

Code: Select all

op:put, host:192.168.1.30, port:8266, passwd:password.
data.js -> /html/data.js
Remote WebREPL version: (1, 13, 0)
Sent 0 of 482 bytes
Sent 482 of 482 bytes
which informs me that everything went well.
jimmo wrote: I'm surprised that `echo "D"` works -- that would send a D (i.e 0x44). You need to send 0x04, which would be `echo -ne "\x04"`
For the command, I used the example provided in the github repository https://github.com/Hermann-SW/webrepl :

Code: Select all

$ ./webrepl_client.py -p abcd -r 192.168.4.1 < <(sleep 1 && echo "E" && cat sc.py && echo -e "D\nc(7)\nexit")
From a terminal, the following four commands work:

Code: Select all

./webrepl_client.py -p htro 192.168.1.30 < <(echo "D")
./webrepl_client.py -p htro 192.168.1.30 < <(echo -e "D")
./webrepl_client.py -p htro 192.168.1.30 < <(echo -ne "\x04")  // your suggestion
./webrepl_client.py -p htro 192.168.1.30 < <(echo -e "D\nc(7)\nexit")
None of them work when I invoke them from my program.

Here's where I'm at now.

Friendly,
naute

naute
Posts: 4
Joined: Wed Jul 07, 2021 9:06 am

Re: reset after webrepl ota update

Post by naute » Fri Jul 09, 2021 9:29 am

Hi jimmo :) .


From a practical point of view, I solved my problem by a different approach. First I create the following shell script:

Code: Select all

#!/bin/bash

./webrepl_cli.py -p htro data.js 192.168.1.30:/html/data.js
./webrepl_client.py -p htro 192.168.1.30 < <(echo "D")
which I save as "export.sh", then in my program I run the procedure:

Code: Select all

  Process := TProcessEX.Create(nil);
  try
    with Processus do
    begin
      Executable := './export.sh';
      Parameters.Clear;
      Execute;
    end;
  finally
    Process.free;
  end;
and it works perfectly.

So, my problem is technically solved, but I would like to know, for the principle, why the first approach did not work. If you have an idea, don't hesitate.

Anyway, thanks a lot for your help, because it's your question about how I was invoking "wrebrepl_client.py" that gave me the idea to look for another approach.

Kind regards,
naute

Post Reply