Advertisement
howtophil

meshbbs.sh

Feb 17th, 2024 (edited)
1,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.91 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #----------------------------------
  4. # A proof of concept to watch for
  5. # and respond to Meshtastic
  6. # messages over serial (USBserial).
  7. #
  8. # More here than the first paste.
  9. #
  10. # Can be thought of as a bash-based
  11. # BBS or Meshtastic Bot.
  12. #
  13. # Requires: bash, stty, meshtastic (cli),
  14. # sed, tr, grep...
  15. #
  16. # Make sure "Debug log enabled"
  17. # is checked to on in the
  18. # Radio Configuration->Device menu
  19. # of Meshtastic
  20. #
  21. # ~HowToPhil Updated 2024/02/17 21:00 EST
  22. #----------------------------------
  23.  
  24. #--------------------------------------
  25. # A Bulletin Board System
  26. # at least needs System Bulletins
  27. #--------------------------------------
  28. systemBulletins () {
  29.     meshtastic --sendtext "The system is new
  30. and not at all stable.
  31. and you can see this bulletin now!"
  32.  
  33. }
  34.  
  35. #--------------------------------------
  36. # A function to handle commands
  37. #--------------------------------------
  38. parseCommand () {
  39.     echo "$1 in parseCommand"
  40.  
  41.     #The help/menu
  42.     if [ "$1" == "help" ]; then
  43.         meshtastic --sendtext "This is a SUPER-SIMPLE BBS on Meshtastic!
  44. Use these commands:
  45. @meshbbs help - Show this help message
  46. @meshbbs weather [location] - The weather at a location
  47. @meshbbs bulletins - System bulletins
  48. "
  49.     fi
  50.  
  51.     #The weather
  52.     if [ $1 == "weather" ]; then
  53.         meshtastic --sendtext "`ansiweather -l $2 $3 $4 |sed -e 's/\x1b\[[0-9;]*m//g'`"
  54.     fi
  55.  
  56.     #System Bulletins Pass-Off
  57.     if [ $1 == "bulletins" ]; then
  58.         systemBulletins
  59.     fi
  60.  
  61. }
  62.  
  63. #--------------------------------------
  64. # The loop that looks for commands
  65. # and responds to those commands
  66. #--------------------------------------
  67. while [ 1==1 ]; do
  68.     #configure the USB serial port properly
  69.     stty -F /dev/ttyUSB0 115200 -echo -icrnl raw
  70.  
  71.     #start watching for a command
  72.     COMMAND=$(grep -a -m1 "@meshbbs" /dev/ttyUSB0| grep "^INFO"|sed 's/.*@meshbbs //'| tr -d "\r")
  73.  
  74.     #do something with the command
  75.     echo "GOT $COMMAND"
  76.     parseCommand $COMMAND
  77. done
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement