Answers.Body: <p>With the prime hub you need to exit the hub default process before you can send commands using <kbd>ctrl</kbd>-<kbd>c</kbd>.</p>
  <p><kbd>Ctrl</kbd>-<kbd>c</kbd> is the character <code>0x03</code>.</p>
  <p>This is my python script that I use to send micropython scripts over to my hub:
  <a href="https://github.com/gpdaniels/spike-prime/blob/master/simulator/run.py" rel="nofollow noreferrer">https://github.com/gpdaniels/spike-prime/blob/master/simulator/run.py</a></p>
  <p>It has lots of nastyness in it like this:</p>
  <pre><code>port.write(b'\x03')
  time.sleep(0.1)
  port.write(b'\x03')
  time.sleep(1.0)
  </code></pre>
  <p>To try and get the hub to stop the running script and behave.</p>
  <p>Also there's functions to read the serial input from the hub until it sees the <code>&gt;&gt;&gt;</code> characters which indicate the REPL is ready to receive python commands.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-01T22:06:04.033Z
Answers.Text: Wouldn't it be easier to send the script file in a whole with rsync and force the hub to execute it by calling execfile() ? That might be faster because you call sleep(0.1) between every command. Anyway your script is a big help, thanks man.
Answers.UserDisplayName: areop-enap
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-08T10:51:20.510Z
Answers.Text: The sleeps in my script are just to get the REPL into a good state.
  I send the whole script using the paste mode of the REPL.
  After which it is executed in one go.
Answers.UserDisplayName: gpdaniels
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-09T16:31:50.207Z
Answers.Text: Well, sounds good, but isn't the readline of python reading a file line by line ? Later you pass the file line by line to write_command(...) which then waits for every line 0.2 seconds. Not sure if that might be slow thou, I have to get into the code for a bit longer to clearly understand...
Answers.UserDisplayName: areop-enap
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-11T12:03:46.797Z
Answers.Text: Yeah there is a lot of delays, rather than spending time on my dodgy code, I'd recommend rshell [ https://github.com/dhylands/rshell ] which is great!
Answers.UserDisplayName: gpdaniels
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-11T21:39:32.090Z
Answers.Text: I found that repository already but I didn't know it can execute code on the hub. It's in the pyboard.py file. I still have to figure out how it works but accordingly to the header it shouldn't be that hard. Thanks for your help. Btw I tried to use your run.py to paste a larger code file in one big chunk but it fails after some lines. Seemingly the REPL paste mode cant handle big chunks. I used rsync to copy files to the board already before but wanted copy and execute at once.
Answers.UserDisplayName: areop-enap
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-13T21:28:47.453Z
Answers.Text: The pyboard.py program from rshell isn't working out of the box. You have to replace the line where it sends the break signal twice '\r\x03\r\x03' with two send commands sending one break each and a delay in between, similar to the suggested code in run.py above. I wonder if those pyboard.py devs would update their project.
Answers.UserDisplayName: areop-enap
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-31T13:17:33.893Z
Answers.LastActivityDate: 2021-01-01T23:31:48.373Z
Answers.LastEditDate: 2021-01-01T23:31:48.373Z
Answers.UserDisplayName: gpdaniels
Body: <p>I am trying to execute commands using the -X switch on the Spike Prime Hub but all I get is either nothing, or unknown command errors.
  Here is what I tried so far:</p>
  <p><code>screen /dev/ttyACM0 -X 'print(&quot;test&quot;)'
  screen /dev/ttyACM0 -X $'print(&quot;test&quot;)/n'
  screen /dev/ttyACM0 | 'print(&quot;test&quot;)'
  screen /dev/ttyACM0 | $'print(&quot;test&quot;)/n'</code></p>
  <p>The piped commands gave me unknown command errors. When I change the main.py and add some prints, they are shown even if printed before I login. So stream wise that is working no matter when I login.</p>
  <p>Another issue occures with the rshell rsync. I had to add a switch to stop the sound files from syncing since they crash rshell. Also rshell stops the code execution on the hub. I tried the above commands before and after rshell rsync call. When I login the hub after rshell I can enter python commands without hitting ctrl+c. Before rsync I have to stop execution with ctrl+c before I am able to type.</p>
  <p>But the screen command does not execute python in all cases. Any ideas ?</p>
  <p>The main task I want to achieve is that the hub continues execution after rsync. I wanted that with a screen command. But the whole Spike Prime software seems buggy and sluggish from the open source point of view.</p>
  
Tags: <spike-prime><micropython>
Title: Spike Prime remote command using screen
UserDisplayName: areop-enap
ThreadText: # Spike Prime remote command using screen
  
  (Asked by: username_0 on 2020-12-31)
  
  I am trying to execute commands using the -X switch on the Spike Prime Hub but all I get is either nothing, or unknown command errors.
  Here is what I tried so far:
  
  `screen /dev/ttyACM0 -X 'print("test")'
  screen /dev/ttyACM0 -X $'print("test")/n'
  screen /dev/ttyACM0 | 'print("test")'
  screen /dev/ttyACM0 | $'print("test")/n'`
  
  The piped commands gave me unknown command errors. When I change the main.py and add some prints, they are shown even if printed before I login. So stream wise that is working no matter when I login.
  
  Another issue occures with the rshell rsync. I had to add a switch to stop the sound files from syncing since they crash rshell. Also rshell stops the code execution on the hub. I tried the above commands before and after rshell rsync call. When I login the hub after rshell I can enter python commands without hitting ctrl+c. Before rsync I have to stop execution with ctrl+c before I am able to type.
  
  But the screen command does not execute python in all cases. Any ideas ?
  
  The main task I want to achieve is that the hub continues execution after rsync. I wanted that with a screen command. But the whole Spike Prime software seems buggy and sluggish from the open source point of view.
  
  **Tags:** spike-prime, micropython
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-12-31. Score: 4
  
  With the prime hub you need to exit the hub default process before you can send commands using ctrl-c.
  Ctrl-c is the character 0x03.
  This is my python script that I use to send micropython scripts over to my hub:
  https://github.com/gpdaniels/spike-prime/blob/master/simulator/run.py
  It has lots of nastyness in it like this:
  port.write(b'\x03')
  time.sleep(0.1)
  port.write(b'\x03')
  time.sleep(1.0)
  
  To try and get the hub to stop the running script and behave.
  Also there's functions to read the serial input from the hub until it sees the >>> characters which indicate the REPL is ready to receive python commands.
  
  > **Comments:**
  > **username_0**: Wouldn't it be easier to send the script file in a whole with rsync and force the hub to execute it by calling execfile() ? That might be faster because you call sleep(0.1) between every command. Anyway your script is a big help, thanks man.  
  > **username_1**: The sleeps in my script are just to get the REPL into a good state. I send the whole script using the paste mode of the REPL. After which it is executed in one go.  
  > **username_0**: Well, sounds good, but isn't the readline of python reading a file line by line ? Later you pass the file line by line to write_command(...) which then waits for every line 0.2 seconds. Not sure if that might be slow thou, I have to get into the code for a bit longer to clearly understand...  
  > **username_1**: Yeah there is a lot of delays, rather than spending time on my dodgy code, I'd recommend rshell [ https://github.com/dhylands/rshell ] which is great!  
  > **username_0**: I found that repository already but I didn't know it can execute code on the hub. It's in the pyboard.py file. I still have to figure out how it works but accordingly to the header it shouldn't be that hard. Thanks for your help. Btw I tried to use your run.py to paste a larger code file in one big chunk but it fails after some lines. Seemingly the REPL paste mode cant handle big chunks. I used rsync to copy files to the board already before but wanted copy and execute at once.  
  > **username_0**: The pyboard.py program from rshell isn't working out of the box. You have to replace the line where it sends the break signal twice '\r\x03\r\x03' with two send commands sending one break each and a delay in between, similar to the suggested code in run.py above. I wonder if those pyboard.py devs would update their project.  
  
  ---
  
  