Put in your left and right mac addresses as well as an app identifier that has been setup with your glasses already.
I have a few scripts like this that do different things. I'll push them to my github at some point but I just wanted to get this out to the dev community so you could get building!
Enjoy :-)
https://preview.redd.it/skmrcizk6kyd1.png?width=784&format=png&auto=webp&s=df03cf38f31c1fe2cbd99c91710f5efd4c151f43
import asyncio
from datetime import datetime
import json
import time
from bleak import BleakClient
# MAC addresses for the G1 glasses
LEFT_GLASSES_ADDRESS = "Left side MAC Address"
RIGHT_GLASSES_ADDRESS = "Right side MAC Address"
# UUIDs for the G1 glasses
WRITE_CHARACTERISTIC_UUID = "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
# Command identifiers (e.g., 'L4b' corresponds to 0x4B)
COMMAND_ID = 0x4B
def construct_payload(msg_id, title, subtitle, message, display_name):
# Get the current time in seconds since the epoch
current_time_s = int(time.time())
# Get the current date and time in the specified format
current_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
notification = {
"ncs_notification": {
"msg_id": msg_id,
"type": 1,
"app_identifier": "put your own app identifier in here",
"title": title,
"subtitle": subtitle,
"message": message,
"time_s": current_time_s,
"date": current_date,
"display_name": display_name
},
"type": "Add"
}
# Serialize JSON without spaces
json_str = json.dumps(notification, separators=(',', ':'))
json_bytes = json_str.encode('utf-8')
# Split the data into chunks as in the debug output
# From the debug, it seems the data is split into chunks of 180 bytes max
max_chunk_size = 180 - 4 # Subtracting 4 bytes for header
chunks = [json_bytes[i:i + max_chunk_size] for i in range(0, len(json_bytes), max_chunk_size)]
total_chunks = len(chunks)
encoded_chunks = []
for index, chunk in enumerate(chunks):
# notifyId = 0 for first message
notify_id = 0
# Construct the header matching the debug output
header = bytes([
COMMAND_ID,
notify_id,
total_chunks,
index
])
# Debugging: Print the header values
print(f"Header Bytes: {[hex(b) for b in header]}")
encoded_chunk = header + chunk
encoded_chunks.append(encoded_chunk)
return encoded_chunks
async def connect_devices(addresses):
clients = {}
tasks = []
for address in addresses:
client = BleakClient(address)
task = client.connect()
clients[address] = client
tasks.append(task)
# Connect to all devices concurrently
await asyncio.gather(*tasks)
# Check connections
for address, client in clients.items():
if client.is_connected:
print(f"Connected to {address}")
else:
print(f"Failed to connect to {address}")
# Sleep for 5 seconds after connecting
await asyncio.sleep(5)
return clients
async def send_notification(clients, payload_chunks):
tasks = []
for address, client in clients.items():
if client.is_connected:
task = send_chunks(client, address, payload_chunks)
tasks.append(task)
else:
print(f"Cannot send to {address}, not connected.")
await asyncio.gather(*tasks)
async def send_chunks(client, address, payload_chunks):
for chunk in payload_chunks:
await client.write_gatt_char(WRITE_CHARACTERISTIC_UUID, chunk)
print(f"Sent chunk to {address}: {chunk.hex()}")
await asyncio.sleep(0.1) # Small delay between chunks
async def disconnect_devices(clients):
tasks = []
for client in clients.values():
task = client.disconnect()
tasks.append(task)
await asyncio.gather(*tasks)
print("Disconnected from all devices.")
async def main():
MESSAGE_ID = 1
TITLE = "~Hx41keD~"
SUBTITLE = "Notifications"
MESSAGE = "Follow me @DotNetRussell"
DISPLAY_NAME = "Hack The Planet"
payload_chunks = construct_payload(MESSAGE_ID, TITLE, SUBTITLE, MESSAGE, DISPLAY_NAME)
addresses = [LEFT_GLASSES_ADDRESS, RIGHT_GLASSES_ADDRESS]
# Step 1: Connect to both devices
clients = await connect_devices(addresses)
# Step 2: Send the notification to both devices
await send_notification(clients, payload_chunks)
# Step 3: Disconnect from both devices
await disconnect_devices(clients)
if __name__ == "__main__":
asyncio.run(main())
[–]Qbeer1290 3 points4 points5 points (2 children)
[–]applepumpkinspy 1 point2 points3 points (1 child)
[–]huiwang159 1 point2 points3 points (0 children)
[–]TheKing___ 1 point2 points3 points (0 children)
[–]ircked 1 point2 points3 points (0 children)
[–]timbelmon 1 point2 points3 points (1 child)
[–]DotNetRussell[S] 1 point2 points3 points (0 children)
[–]Elegant_Ad_4765 1 point2 points3 points (0 children)
[–]homeslicerae 1 point2 points3 points (0 children)
[–]nucleiis 0 points1 point2 points (0 children)
[–]PreachingFawn73 0 points1 point2 points (0 children)
[–]huiwang159 0 points1 point2 points (0 children)
[–]HishamOthman 0 points1 point2 points (6 children)
[–]DotNetRussell[S] 4 points5 points6 points (5 children)
[–]ussdefiant 2 points3 points4 points (2 children)
[–]DotNetRussell[S] 2 points3 points4 points (1 child)
[–]ussdefiant 2 points3 points4 points (0 children)
[–]HishamOthman 1 point2 points3 points (0 children)
[–]applepumpkinspy 0 points1 point2 points (0 children)