-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
44 lines (35 loc) · 1.13 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
# Server URL
server_url = "http://192.168.0.6/data_collection/"
def get_latest_entry(rpi_id, room_id):
"""
Get the latest entry in local database of given Raspberry Pi and room.
Args:
rpi_id (str): ID of the Raspberry Pi.
room_id (str): ID of the room.
Returns:
str: Date and time of last inserted row.
"""
row_data = {"rpi_id": rpi_id, "room_id": room_id}
url = server_url + "get_latest_entry.php"
try:
response = requests.post(url, params=row_data)
return response.text
except requests.exceptions.RequestException as e:
print(f"Exception: {e}")
return None
def sendFile(file_name):
"""
Send a file to the central server.
Args:
file_name (str): Name of the file to send.
"""
url = server_url + "file_receive.php"
try:
with open(file_name, 'rb') as f:
files = {'file': f}
response = requests.post(url, files=files)
if response.text == "1":
print("Error uploading file\n")
except FileNotFoundError as e:
print(f"File not found: {e}")