Conversation
| cur.execute( | ||
| "SELECT DISTINCT mac_addr FROM public.ble_stats as ble " | ||
| "WHERE ble.timestamp >= date_trunc('hour', current_timestamp) " | ||
| f"+ date_part('minute', current_timestamp)::int / {time} * interval '{time} minute'", |
There was a problem hiding this comment.
avoid string interpolation to prevent sql injection - shouldn't be a problem here as time is an int but generally dangerous
| start_datetime = timestamp.replace(hour=(timestamp.hour + (timestamp.minute - int(interval/2))//60)%24,minute=abs(timestamp.minute - int(interval/2))%60) | ||
| end_datetime = timestamp.replace(hour=(timestamp.hour + (timestamp.minute + int(interval/2))//60)%24,minute=(timestamp.minute + int(interval/2))%60) |
There was a problem hiding this comment.
should replace with timestamp addition eg: https://stackoverflow.com/questions/43192610/add-15-minutes-to-current-timestamp-using-timedelta.
|
|
||
| return [i[0] for i in cur.fetchall()] | ||
|
|
||
| @access_router.post("/ble_device_detected") |
There was a problem hiding this comment.
@Raphsinai rest api naming conventions: https://restfulapi.net/resource-naming/
I'd recommend POST /ble/device
| return "1" | ||
| return "0" | ||
|
|
||
| @access_server_router.post("/postBluetoothDevice", response_class=PlainTextResponse) |
There was a problem hiding this comment.
Same comment as above (yh some of the old endpoints are badly named 😬 )
| return "0" | ||
|
|
||
| @access_server_router.post("/postBluetoothDevice", response_class=PlainTextResponse) | ||
| async def post_bluetooth_addr(mac_addr: str = Query(max_length=17)): |
There was a problem hiding this comment.
add credentials to forward to internal api
There was a problem hiding this comment.
should it be the credentials : Annotated[HTTPBasicAuth...
There was a problem hiding this comment.
yup need to also update the database endpoint with this as well
| ) | ||
|
|
||
| if mac_addr in addresses.json(): | ||
| return "already captured" |
There was a problem hiding this comment.
return a HTTP response - eg 304
| result = requests.post( | ||
| DATABASE_ADAPTER_IP + "/access/ble_device_detected", | ||
| params={ | ||
| "mac_addr": mac_addr |
There was a problem hiding this comment.
it might also be worth capturing the mac address/id of the publisher/esp32
There was a problem hiding this comment.
yeah ok should be pretty simple
added bluetooth tracking functionality