uav2.py 975 Bytes
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import socket 
import select 
import os 


# In[ ]:


def removeAllFile(filePath):
    if os.path.exists(filePath):
        for file in os.scandir(filePath):
            os.remove(file.path)
        return 'Remove All File'
    else:
        return 'Directory Not Found'

print(removeAllFile('/home/pi/capdesign/frames'))
address = ('192.168.51.1', 8083)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(address)

while True:
    data, addr = sock.recvfrom(1024)
    if data:
        data = data.decode()
        print("filename", data)
        file_name = data.strip()
    
    f = open('frames/{}'.format(file_name), 'wb')
    
    while True:
        ready = select.select([sock], [], [], 3)
        if ready[0]:
            data, addr = sock.recvfrom(1024)
            if(data == "FINISH".encode('utf-8')):
                f.close()
                break
            else:
                f.write(data)