| Add seeedfarming hackaton. - brcon2025-hackathons - Bitreichcon 2025 Hackathons | |
| git clone git://bitreich.org/brcon2025-hackathons git://enlrupgkhuxnvlhsf6lc3fz… | |
| Log | |
| Files | |
| Refs | |
| Tags | |
| --- | |
| commit 050aff722903afb0acc885e88e2ac732e6cb1df4 | |
| parent 890a9a8d8c7102eb08c91a134a3af5409148d7ec | |
| Author: Josuah Demangeon <[email protected]> | |
| Date: Mon, 28 Jul 2025 18:01:57 +0200 | |
| Add seeedfarming hackaton. | |
| Signed-off-by: Josuah Demangeon <[email protected]> | |
| Diffstat: | |
| A seeedfarming/README.md | 91 +++++++++++++++++++++++++++++… | |
| A seeedfarming/client.sh | 8 ++++++++ | |
| A seeedfarming/example.py | 26 ++++++++++++++++++++++++++ | |
| A seeedfarming/forward.sh | 3 +++ | |
| A seeedfarming/server.sh | 7 +++++++ | |
| A seeedfarming/session.sh | 29 +++++++++++++++++++++++++++++ | |
| 6 files changed, 164 insertions(+), 0 deletions(-) | |
| --- | |
| diff --git a/seeedfarming/README.md b/seeedfarming/README.md | |
| @@ -0,0 +1,91 @@ | |
| +# Seeed farm live at: nc bitreich.org 7000 | |
| + | |
| +Welcome Seeed Farmer! | |
| + | |
| +Let me show you the way around: | |
| + | |
| +``` | |
| + ((( [] [] [] ))) .-------. | |
| + \ | / _[] ))) | | | |
| +((( []__\ |/ / | | | |
| + _\\||_/ ((( usb-wifi----/=======/--------bitreich.org | |
| + /______/-----------usb-serial--/=======/ | |
| + '------' =======' | |
| + | |
| +ESP32-C3 boards Laptop doing SSH port forwarding | |
| +Connected on USB HUB | |
| +``` | |
| + | |
| +For you that means visitting bitreich.org on port 7000 and you will | |
| +be given one gopher seed! You can use that tool to farm the seed: | |
| + | |
| +``` | |
| +$ sh client.sh | |
| +MicroPython df05cae on 2025-07-24; ESP32C3 module with ESP32C3 | |
| +Type "help()" for more information. | |
| +>>> | |
| +``` | |
| + | |
| +That's it fellow farmer! Nature is this generous, you just have to | |
| +bow down and put down a seed, you'll see a tree growing! | |
| + | |
| +## Programming the farm | |
| + | |
| +Now you can whisper python runes to the tree, and it might grant | |
| +your wishes... | |
| + | |
| +``` | |
| +>>> from network import WLAN | |
| +>>> from socket import socket | |
| +>>> # Connect to WiFi | |
| +>>> # Connect to Internet APIs | |
| +``` | |
| + | |
| +Every seed has an IP address given by DHCP, with a port redirection | |
| +done on bitreich.org for it: | |
| + | |
| +- 192.168.66.3:70 is accessible from bitreich.org:7003 | |
| +- 192.168.66.4:70 is accessible from bitreich.org:7004 | |
| +- 192.168.66.5:70 is accessible from bitreich.org:7005 | |
| +- 192.168.66.6:70 is accessible from bitreich.org:7006 | |
| +- ... | |
| +- 192.168.66.123:70 is accessible from bitreich.org:7123 | |
| +- 192.168.66.124:70 is accessible from bitreich.org:7124 | |
| + | |
| +In this repo, you will find the scripts that make maintain the farm: | |
| + | |
| +- forward.sh - to maintain the port forwarding | |
| +- server.sh - that runs session.sh on every incoming connection on port :7000 | |
| +- session.sh - that connects to the seed with python access | |
| +- client.sh - that's for you! run this and you can send python commands to the… | |
| + | |
| +## Quick-start on MicroPython seed farming | |
| + | |
| +The seeds run https://micropython.org/ as a firmware! | |
| + | |
| +That way you can run python program directly bare-metal: python is your OS! | |
| + | |
| +There is a `example.py` that shows you how you can connect | |
| +to the farm WiFi and get outta here on the world wide gopher. | |
| + | |
| +Every time you connect to the farm with `client.sh`, you will get a new seed. | |
| +It will be completely reset using `machine.reset()` and you'll be having a | |
| +fresh new seed to plant! | |
| + | |
| +The seeds are boards called Xiao ESP32-C3: | |
| +https://wiki.seeedstudio.com/XIAO_ESP32C3_Getting_Started/ | |
| + | |
| +Here, you can use this page to understand how WiFi and network | |
| +handling works: | |
| +https://docs.micropython.org/en/latest/esp32/quickref.html#wlan | |
| + | |
| +Here, you can lookup the networking functions of MicroPython, | |
| +which use the same API as Python: | |
| +https://docs.micropython.org/en/latest/library/socket.html | |
| + | |
| +Here, you can see instructions to run a MicroPython simulator | |
| +on your desktop and connect to Internet with it too: | |
| +https://github.com/micropython/micropython/tree/master/ports/unix | |
| + | |
| +You will have a `micropython` program that you can run to test programs | |
| +that work just like on the seeds. | |
| diff --git a/seeedfarming/client.sh b/seeedfarming/client.sh | |
| @@ -0,0 +1,8 @@ | |
| +# Clean the terminal when exiting | |
| +trap 'stty sane' INT TERM EXIT | |
| + | |
| +# Set the terminal in raw mode so that keybindings work | |
| +stty raw -echo | |
| + | |
| +# Connect to the seeed farm! | |
| +nc -v bitreich.org 7000 | |
| diff --git a/seeedfarming/example.py b/seeedfarming/example.py | |
| @@ -0,0 +1,26 @@ | |
| +# this is an example script that you can load into MicroPython prompt to | |
| +# connect yourself to the WiFi access point | |
| +import network, socket | |
| + | |
| +wlan = network.WLAN() | |
| +wlan.active(True) | |
| +wlan.scan() | |
| +wlan.connect('seeeder', 'seeedrooots') | |
| + | |
| +# Then wait until wlan.isconnected() returns True | |
| + | |
| +myip = wlan.ipconfig('addr4')[0] | |
| +print(myip) | |
| + | |
| +# To access internet services: | |
| +# https://docs.micropython.org/en/latest/library/socket.html | |
| + | |
| +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| +s.bind((myip, 70)) | |
| +s.listen(9) | |
| + | |
| +conn, addr = s.accept() | |
| + | |
| +print('Connected with ' + addr[0] + ':' + str(addr[1])) | |
| + | |
| +conn.write('hello world!\n') | |
| diff --git a/seeedfarming/forward.sh b/seeedfarming/forward.sh | |
| @@ -0,0 +1,3 @@ | |
| +ssh -Nv -R 7000:127.0.0.1:7000 \ | |
| + $(for i in $(seq 1 256); do echo -R $(printf 7%03d $i):192.168.66.$i:70; done… | |
| + bitreich.org | |
| diff --git a/seeedfarming/server.sh b/seeedfarming/server.sh | |
| @@ -0,0 +1,7 @@ | |
| +# Default parameters | |
| + | |
| +# Change to the current directory to find the session.sh script | |
| +cd "${0%/*}" | |
| + | |
| +# You do not need to run this, but have a look if you are curious | |
| +s6-tcpserver -v 0.0.0.0 7000 sh session.sh | |
| diff --git a/seeedfarming/session.sh b/seeedfarming/session.sh | |
| @@ -0,0 +1,29 @@ | |
| +# You do not need to run this, but have a look if you are curious | |
| + | |
| +# 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!" | |
| + for tty in /dev/ttyACM*; do | |
| + if pgrep -fal "picocom --quiet --no-escape .* $tty"; then | |
| + echo "- $tty busy" | |
| + else | |
| + echo "- $tty free" | |
| + fi | |
| + done | |
| +} | sed "s/$/$(printf '\r')/" | |
| + | |
| +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 | |
| + | |
| +if [ "$?" != 0 ]; then | |
| + echo "Failed to find any MicroPython board available... Ask for a farm… | |
| +fi |