-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add session creation and sensor data posting
functionality
- Loading branch information
1 parent
a06ba95
commit fb22659
Showing
1 changed file
with
28 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
from random import randint, random | ||
from time import sleep | ||
|
||
import requests | ||
|
||
import kb_2315.config as config | ||
from kb_2315.api import schemas | ||
|
||
|
||
conf: config.env = config.read_config(dir=config.root_dir) | ||
|
||
|
||
requests.post( | ||
url=conf.host_url, | ||
json=schemas.machine(id=1, status=False).model_dump(), | ||
) | ||
|
||
sleep(2) | ||
import requests | ||
from kb_2315.backend.schemas import schema_session, schema_sensor | ||
|
||
requests.post( | ||
url=conf.host_url, | ||
json=schemas.machine(id=1, status=True).model_dump(), | ||
) | ||
from kb_2315.config import conf | ||
from kb_2315.backend import schemas | ||
|
||
sleep(2) | ||
device_id = randint(1, 100) | ||
|
||
requests.post( | ||
url=conf.host_url, | ||
json=schemas.machine(id=1, status=False).model_dump(), | ||
resp: schema_session.create_session = schema_session.create_session.model_validate( | ||
obj=requests.get(f"{conf.host_url}/session/?shoe_id={device_id}").json() | ||
) | ||
print(resp, resp.session_id) | ||
str_sesison_id = str(resp.session_id) | ||
|
||
it = 3 | ||
|
||
for i in range(it): | ||
requests.post( | ||
url=f"{conf.host_url}/sensor", | ||
json=schema_sensor.sensor( | ||
session_id=str_sesison_id, | ||
device_id=device_id, | ||
external_temperature=random() * 30, | ||
external_humidity=random() * 100, | ||
internal_temperature=random() * 30, | ||
internal_humidity=random() * 100, | ||
drying=(i < it - 1), | ||
).model_dump(), | ||
) | ||
|
||
sleep(2) |