Spaces:
Sleeping
Sleeping
LapStore commited on
Commit ·
dc09e66
1
Parent(s): 5564f37
debug mqtt
Browse files- traffic_utils.py +11 -4
traffic_utils.py
CHANGED
|
@@ -3,6 +3,8 @@ from database_manager import *
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
import os
|
| 5 |
import state
|
|
|
|
|
|
|
| 6 |
load_dotenv(dotenv_path="keys.env")
|
| 7 |
|
| 8 |
overpass_url = os.getenv("URL_Traffic")
|
|
@@ -30,16 +32,21 @@ def get_rectangle_container(coordinates):
|
|
| 30 |
min_lat, max_lat = min(lats), max(lats)
|
| 31 |
min_lon, max_lon = min(lons), max(lons)
|
| 32 |
return min_lat, max_lat, min_lon, max_lon
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
async def open_signal(tl_id,state_,duration,delay):
|
| 36 |
check_time = 10
|
| 37 |
await asyncio.sleep(delay)
|
| 38 |
|
| 39 |
state.request[tl_id]['State'] = state.status_chk
|
| 40 |
-
|
| 41 |
-
check_time = 10
|
| 42 |
-
await asyncio.sleep(check_time)
|
| 43 |
|
| 44 |
|
| 45 |
if (state.request[tl_id]['accepted']== True):
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
import os
|
| 5 |
import state
|
| 6 |
+
import asyncio
|
| 7 |
+
|
| 8 |
load_dotenv(dotenv_path="keys.env")
|
| 9 |
|
| 10 |
overpass_url = os.getenv("URL_Traffic")
|
|
|
|
| 32 |
min_lat, max_lat = min(lats), max(lats)
|
| 33 |
min_lon, max_lon = min(lons), max(lons)
|
| 34 |
return min_lat, max_lat, min_lon, max_lon
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
async def wait_check_conection(tl_id,check_time):
|
| 38 |
+
start = time.time()
|
| 39 |
+
while time.time() - start < check_time:
|
| 40 |
+
if state.request[tl_id]['State'] != state.status_chk:
|
| 41 |
+
break
|
| 42 |
+
await asyncio.sleep(0.2)
|
| 43 |
|
| 44 |
async def open_signal(tl_id,state_,duration,delay):
|
| 45 |
check_time = 10
|
| 46 |
await asyncio.sleep(delay)
|
| 47 |
|
| 48 |
state.request[tl_id]['State'] = state.status_chk
|
| 49 |
+
await wait_check_conection(tl_id,check_time)#asyncio.sleep(check_time)
|
|
|
|
|
|
|
| 50 |
|
| 51 |
|
| 52 |
if (state.request[tl_id]['accepted']== True):
|