Skip to content

Bluetooth#107

Open
Raphsinai wants to merge 6 commits into
mainfrom
bluetooth
Open

Bluetooth#107
Raphsinai wants to merge 6 commits into
mainfrom
bluetooth

Conversation

@Raphsinai

Copy link
Copy Markdown
Collaborator

added bluetooth tracking functionality

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'",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid string interpolation to prevent sql injection - shouldn't be a problem here as time is an int but generally dangerous

Comment on lines +116 to +117
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


return [i[0] for i in cur.fetchall()]

@access_router.post("/ble_device_detected")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Raphsinai rest api naming conventions: https://restfulapi.net/resource-naming/

I'd recommend POST /ble/device

Comment thread server/src/server.py
return "1"
return "0"

@access_server_router.post("/postBluetoothDevice", response_class=PlainTextResponse)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above (yh some of the old endpoints are badly named 😬 )

Comment thread server/src/server.py
return "0"

@access_server_router.post("/postBluetoothDevice", response_class=PlainTextResponse)
async def post_bluetooth_addr(mac_addr: str = Query(max_length=17)):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add credentials to forward to internal api

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be the credentials : Annotated[HTTPBasicAuth...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup need to also update the database endpoint with this as well

Comment thread server/src/server.py
)

if mac_addr in addresses.json():
return "already captured"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return a HTTP response - eg 304

Comment thread server/src/server.py
result = requests.post(
DATABASE_ADAPTER_IP + "/access/ble_device_detected",
params={
"mac_addr": mac_addr

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might also be worth capturing the mac address/id of the publisher/esp32

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah ok should be pretty simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants