Skip to content

Instantly share code, notes, and snippets.

@ibanezmatt13
Last active December 17, 2015 19:49
Show Gist options
  • Save ibanezmatt13/5663226 to your computer and use it in GitHub Desktop.
Save ibanezmatt13/5663226 to your computer and use it in GitHub Desktop.
import os
import time
import os.path
import serial
def process_image():
best_file = ""
biggest_size = 0
imgdir = '/home/pi/to_transmit/'
for file in os.listdir(imgdir): # for all files in "to_transmit" folder
size = os.path.getsize(imgdir + file) # get the size of the file
if size > biggest_size: # if the size is bigger than the previous biggest size
biggest_size = size # reset biggest size
best_file = file # the file is now the "best" file
send_image(best_file) # initiate the sending of 'best_file'
def send_image(best_file):
print best_file
if best_file == "":
print "No image available."
else:
os.system('ssdv -e -t 50 -c PIE1 -i ibanezmatt13 /home/pi/to_transmit/' + best_file + ' packets')
os.system('mv /home/pi/to_transmit/* /home/pi/archive')
packets_file = open("packets", "rb")
packets = packets_file.read(256)
print "sending packets..."
while packets != '':
NTX2 = serial.Serial('/dev/ttyAMA0', 300, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_TWO)
NTX2.write(packets)
NTX2.close()
packets = packets_file.read(256)
print packets
print "PACKETS SENT!"
while True:
process_image() # this includes processing and sending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment