update server

This commit is contained in:
Untriex Programming 2021-04-22 20:43:57 +02:00
parent 2156570723
commit e514054c6b
4 changed files with 26 additions and 4 deletions

@ -157,3 +157,7 @@
SENSOR: name='sensor1' value='test'
2021-04-14 14:10:06.190377 -> Warning: Address(host='192.168.1.99', port=58192) created new sensor.
SENSOR: name='sensor2' value='123456789'
2021-04-22 10:15:53.540044 -> Warning: Address(host='192.168.1.99', port=43642) created new sensor.
SENSOR: name='test1' value='juhuu'
2021-04-22 10:16:02.865022 -> Warning: Address(host='192.168.1.99', port=43644) created new sensor.
SENSOR: name='test2' value='eeeh'

@ -75,6 +75,11 @@ class Sensor(BaseModel):
value: str
class Message(BaseModel):
m_sender: str
message: str
@app.get("/")
def read_root():
return "wikispot"
@ -265,9 +270,12 @@ def register():
@app.post("/messages/post")
def get_messages(m_sender: str = None, message: str = None):
if m_sender and message:
messages.append({"sender": m_sender, "message": message, "timestamp": time.time()})
def post_messages(data: Message):
log.debug(f"Message was posted. Sender: {data.m_sender}\n MESSAGE: {data.message}")
if len(messages) >= settings["max_mess"]:
del messages[:len(messages) - settings["max_mess"]]
if data.m_sender and data.message:
messages.append({"sender": data.m_sender, "message": data.message, "timestamp": time.time()})
return "successful"
else:
return "Empty message/sender"

@ -6,6 +6,7 @@
"time_to_heartbeat_offline": 25,
"save_table": false,
"time_to_save": 60,
"max_mess": 20,
"log": {
"save_error": true,
"print_error": true,

@ -0,0 +1,9 @@
import requests
import time
send_n = 100
wait_t = 0.5
for x in range(send_n):
r = requests.post("http://192.168.1.99:8000/messages/post", json={"m_sender": "server", "message": str(x)})
print(f"Sent message {x+1}/{send_n}\nResponse: {r.text}")
time.sleep(wait_t)