Introduction
Introduction Statistics Contact Development Disclaimer Help
seeedfarm: introduce a nicer UI that works over telnet - brcon2025-hackathons -…
git clone git://bitreich.org/brcon2025-hackathons git://enlrupgkhuxnvlhsf6lc3fz…
Log
Files
Refs
Tags
---
commit 8a6dd4b51a856d549863836b240d2a6d0c495043
parent b01932dc1daf4868cfbe4125d0ebed7b7274473c
Author: Josuah Demangeon <[email protected]>
Date: Thu, 31 Jul 2025 10:02:24 +0200
seeedfarm: introduce a nicer UI that works over telnet
Diffstat:
M seeedfarming/example.py | 13 +++++++++----
M seeedfarming/session.sh | 85 +++++++++++++++++++++++------…
2 files changed, 73 insertions(+), 25 deletions(-)
---
diff --git a/seeedfarming/example.py b/seeedfarming/example.py
@@ -1,16 +1,21 @@
#!/usr/bin/env python
# coding=utf-8
#
-# this is an example script that you can load into MicroPython prompt to
-# connect yourself to the WiFi access point
-import network, socket
+# This is an example script that you can load into MicroPython prompt to
+# connect yourself to the WiFi access point.
+import network
+import socket
+import time
wlan = network.WLAN()
wlan.active(True)
wlan.scan()
wlan.connect('seeeder', 'seeedrooots')
-# Then wait until wlan.isconnected() returns True
+# Then wait until internet is up
+while not wlan.isconnected():
+ print('.', end='')
+print(' connected')
myip = wlan.ipconfig('addr4')[0]
print(myip)
diff --git a/seeedfarming/session.sh b/seeedfarming/session.sh
@@ -1,31 +1,74 @@
#!/bin/sh
-# You do not need to run this, but have a look if you are curious
+SEEED_SCRIPTS=/tmp/seeed_scripts
-# Initial string sent to reboot the board and start from a clean session every…
-# Ctrl+C to cancel anything running
-# Ctrl+B to come back to the normal prompt mode
-# Then a python script to connect to hardware-reset the board and connect to w…
-init="$(printf '\x03\x02'; printf '%s\r' 'import machine' 'machine.reset()')"
+echo "Welcome to the MicroPython Seeed farm!"
-{
- echo "Welcome to the MicroPython Seeed farm!"
+mkdir -p "$SEEED_SCRIPTS"
+
+num=0
+
+while true; do
+ echo "What action do you want to run?"
for tty in /dev/ttyACM*; do
- if pgrep -fal "picocom --quiet --no-escape .* $tty"; then
- echo "- $tty busy"
+ s="$SEEED_SCRIPTS/${tty#/dev/}.py"
+ i=${tty#/dev/ttyACM}
+
+ if [ -f "$s" ]; then
+ echo " [$i] select $tty (running $s)"
+ elif pgrep -fal "picocom --quiet --no-escape .* $tty"; then
+ echo " [$i] select $tty (busy)"
else
- echo "- $tty free"
+ echo " [$i] select $tty (free)"
fi
done
-} | sed "s/$/$(printf '\r')/"
+ echo " [l] Load a new script instead of the current one (if any)"
+ echo " [p] Get a python prompt on the current script"
+ echo " [r] Reset the board and remove the script"
+ echo " [v] View the script "
+ echo -n "ttyACM$num>>> "
+ read action || exit
-i=0
-while [ "$i" -lt 100 ]; do
- port=$(printf 1%04d $i)
- picocom --quiet --no-escape --initstring="$init" --baud=115200 /dev/tt…
- i=$((i + 1))
-done
+ case $action in
+ ([0-9])
+ num=$action
+ script=$SEEED_SCRIPTS/ttyACM$num.py
+ ;;
+ (l)
+ echo "Paste your script and finish it by a dot character ('.')…
+ rm -f "$script"
+ while read line; do
+ if [ "$line" = "." ]; then break; fi
+ echo "$line" >>$script
+ echo "$line"
+ done
+
+ # Set the terminal in "paste" mode and load the script
+ picocom --quiet --baud="115200" --initstring="$reset" "/dev/tt…
-if [ "$?" != 0 ]; then
- echo "Failed to find any MicroPython board available... Ask for a farm…
-fi
+ # Set the terminal back to "normal" mode and show the output o…
+ reset=$(printf '\x03''import machine; machine.reset()\r''\x05')
+ done=$(printf '\x04\r')
+ tr '\n' '\r' | picocom --quiet --baud="115200" --initstring="$…
+ ;;
+ (p)
+ # Just connect without resetting
+ tr '\n' '\r' | picocom --imap="lfcrlf" --quiet --baud="115200"…
+ ;;
+ (e)
+ cat
+ ;;
+ (r)
+ # Just connect without resetting or sending a script to see th…
+ reset=$(printf '\x03''import machine; machine.reset()\r')
+ picocom --quiet --baud="115200" --initstring="$reset" --exit-a…
+ rm -f "$script"
+ ;;
+ (v)
+ cat "$script"
+ ;;
+ (*)
+ echo "error: unknown command '$action' selected"
+ ;;
+ esac
+done
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.