Camera
Camera
Camera
Camera
Cloud/Fog/Server/
Load Balancer
async def send_content(self, foldername):
# gets the folder of images to send files
folder = os.path.dirname(foldername)+foldername
logging.log(logging.INFO, "Folder to send: " + folder)
# Loop throuhg all files, and send the data.
for f in os.listdir(folder):
fullpath = os.path.join(folder, f)
context = await Context.create_client_context()
with open (fullpath, "rb") as img:
self.image = img.read()
request = Message(code=POST, payload=self.image, uri="coap://localhost/api/1.0/receiveVideo")
response = await context.request(request).response
print("Result: %s\n%r" % (response.code, response.payload))
async def render_post(self, request):
global imageType
# Gets the current time and puts it in a specific format
currentTime = datetime.datetime.now().strftime("-%Y-%m-%d-%H-%M-%S")
logging.log(logging.INFO, "Current Time: " + currentTime)
#makes directory if it doesn't exist (for receiving files)
if not os.path.exists('receivedFiles'):
os.makedirs('receivedFiles')
logging.log(logging.INFO, "Created new folder for receiving files")
# Constructs the file path and writes the file that it has received
filename = "./receivedFiles/trafficVideo" + currentTime + ".png"
logging.log(logging.INFO, "FileName: " + filename)
logging.log(logging.DEBUG, str(request.payload))
with open(filename, "wb") as f:
try:
f.write(request.payload)
logging.log(logging.INFO, "Successfully wrote to file")
except e:
logging.log(logging.ERROR, e)
# constructs and sends response message
return aiocoap.Message(code=aiocoap.CREATED, payload="File received".encode("utf-8"))