howtophil

sendfilemesh.sh

Feb 19th, 2024 (edited)
288
0
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.87 KB | None | 0 0
  1. #!/bin/bash
  2. #------------------------------------------------
  3. # An UNTESTED example of sending a binary file
  4. # as a series of messages over Meshtastic
  5. # after the file is converted to base64.
  6. # The meshtastic commands are echoed to stdout
  7. # instead of actually being issued in this script.
  8. # I want to show what commands would be sent
  9. # rather than sending the commands at this point.
  10. # Try not to bring down your local mesh with too
  11. # many data messages, kids.
  12. # ~HowToPhil 2024/02/19 02:40 EST
  13. #------------------------------------------------
  14. # Added md5 checksums for each previous line
  15. # to make error detection more managed.
  16. # ~HowToPhil 20214/02/19 13:55 EST
  17. #------------------------------------------------
  18. # ./sendmeshfile.sh [filename] '[destNodeID]'
  19. #------------------------------------------------
  20.  
  21. # Prep the line count variable
  22. LINECOUNT=0
  23.  
  24. #PREVLINEMD5=$(echo ""|md5sum)
  25. PREVLINEMD5="FIRSTLINE  -"
  26.  
  27. # Put the arguments into pretty variables
  28. FILENAME=$1
  29. NODEID=$2
  30.  
  31. # Get the md5 of the last line of the base64 encoded file.
  32. # Getting this when the loop ends is rough, so I just
  33. # get it now and save it for later.
  34. LASTLINEMD5=$(base64 "$FILENAME" | tail -n1 |md5sum)
  35.  
  36. # Count how many lines/texts long the base64 encoded file will be
  37. # for adding to the header before sending the file.
  38. # I encode it before sending to get the number of lines
  39. # so my header can include how many messages long the file
  40. # will be and then I send the header message.
  41. TOTALTEXTS=$(base64 "$FILENAME" |wc -l)
  42. echo "meshtastic --dest $NODEID --ack --sendtext \"Sending $FILENAME as base64 in $TOTALTEXTS texts\""
  43.  
  44. # Now begins the bulk of the workload delivering the file as
  45. # a base64 encoded text with checksums included.
  46. base64 "$FILENAME" | (while read line; do
  47.     #-------START OLD UNUSED TEST THOUGHT CODE------#
  48.     # For line numbering
  49.     #LINECOUNT=$[$LINECOUNT +1]
  50.     #
  51.     # This would prepend a line number so missed lines could be requested again
  52.     # The receiver would need to strip the line numbers after putting them in order
  53.     #meshtastic --dest $NODEID --ack --sendtext "$LINECOUNT,$line";
  54.     #-------END OLD UNUSED TEST THOUGHT CODE------#
  55.    
  56.     # I have not tested but waiting for ack might make lines go through better
  57.     # and in order, in which case, line numbers would not be needed...
  58.     echo "meshtastic --dest $NODEID --ack --sendtext \"$PREVLINEMD5 $line\";"
  59.  
  60.     # md5 checksum for "previous" line in next loop
  61.     # This way each line can include error checking
  62.     # to make sure the file is being sent and received
  63.     # properly.
  64.     PREVLINEMD5=$(echo "$line" |md5sum)
  65. done)
  66.  
  67. # Send the md5 of the last line of the base64 encoded file
  68. echo "meshtastic --dest $NODEID --ack --sendtext \"$LASTLINEMD5 LASTLINE\";"
  69.  
  70. # Send footer to be sure the other side knows we think we're done
  71. echo "meshtastic --dest $NODEID --ack --sendtext \"Sent $FILENAME as base64 in $TOTALTEXTS texts.\""
  72.  
  73.  
Comments
  • howtophil
    269 days
    # text 0.26 KB | 0 0
    1. Thoughts: I think I'd have the other side count up the lines and report missing lines... maybe include the line number either way... I'd also do the --ack and have the sending machine pause and "watch for node return" before sending the line again and continuing...
  • howtophil
    269 days
    # text 0.12 KB | 0 0
    1. Updating the send side of the script. After I decide on a "solid sending format" I can work on the receivefilemesh.sh script.
  • howtophil
    269 days (edited)
    Comment was deleted
Add Comment
Please, Sign In to add comment