session.sh - brcon2025-hackathons - Bitreichcon 2025 Hackathons
(HTM) git clone git://bitreich.org/brcon2025-hackathons git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/brcon2025-hackathons
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
---
session.sh (2069B)
---
1 #!/bin/sh
2
3 SEEED_SCRIPTS=/var/tmp/seeed_scripts
4
5 echo "Welcome to the MicroPython Seeed farm!"
6
7 mkdir -p "$SEEED_SCRIPTS"
8
9 num=0
10
11 # Show the errors on the network directly instead of hiding them
12 exec 2>&1
13
14 while true; do
15 echo "What action do you want to run?"
16 for tty in /dev/ttyACM*; do
17 s="$SEEED_SCRIPTS/${tty#/dev/}.py"
18 i=${tty#/dev/ttyACM}
19
20 if [ -f "$s" ]; then
21 echo " [$i] select $tty (running $s)"
22 elif pgrep -fal "picocom --quiet --no-escape .* $tty"; then
23 echo " [$i] select $tty (busy)"
24 else
25 echo " [$i] select $tty (free)"
26 if [ "$free" = "" ]; then free=$i; fi
27 fi
28 done
29 echo " [a] Auto-select a free board (for automation)"
30 echo " [l] Load a new script instead of the current one (if any)"
31 echo " [p] Get a python prompt on the current script"
32 echo " [r] Reset the board and remove the script"
33 echo " [v] View the script"
34 echo " [q] Quit"
35 echo -n "seeedcluster[$num]>>> "
36 read action || exit
37
38 date +"%Y-%m-%d %H:%M:%S action '$action' on /dev/ttyACM$num" >>$SEEED_SCRIPTS/log.txt
39
40 case $action in
41 ([0-9])
42 num=$action
43 ;;
44 (a)
45 num=$free
46 ;;
47 (l)
48 echo "Paste your script and finish it by a dot character ('.') alone on its own line:"
49 script=$SEEED_SCRIPTS/ttyACM$num.py
50 sed '/^\.$/ { d; q; }' >$script
51 cp "$script" "$SEEED_SCRIPTS/archive_$(date +%Y_%m%d_%H%M)_ttyACM$num.py"
52
53 # Set the terminal in "paste" mode and load the script
54 mpremote connect "/dev/ttyACM$num" soft-reset run "$script"
55 ;;
56 (p)
57 # Just connect without resetting
58 tr '\n' '\r' | picocom --imap="lfcrlf" --quiet --baud="115200" "/dev/ttyACM$num"
59 ;;
60 (e)
61 cat
62 ;;
63 (r)
64 # Just connect without resetting or sending a script to see the ongoing execution
65 script=$SEEED_SCRIPTS/ttyACM$num.py
66 reset=$(printf '\x03''import machine; machine.reset()\r')
67 picocom --quiet --baud="115200" --initstring="$reset" --exit-after="500" "/dev/ttyACM$num"
68 rm -f "$script"
69 ;;
70 (v)
71 script=$SEEED_SCRIPTS/ttyACM$num.py
72 cat "$script"
73 ;;
74 (q)
75 exit
76 ;;
77 (*)
78 echo "error: unknown command '$action' selected"
79 ;;
80 esac
81 done