Controlling a Lovense Edge over Bluetooth using Python
Thanks to the details provided over at https://stpihkal.docs.buttplug.io/ I was able to figure out how to directly control the Lovense Edge using Python. It was a bit tricky finding a workable Python library but I found a solution.
Requirements:
- Python 3.8 or higher
- Bluetooth interface
- Bleak package
- A Lovense Edge device
I still donโt fully understand the BLE control structure but I was able to cobble together the following code that will control the Edge.
# -*- coding: utf-8 -*-
"""
"""
import asyncio
import platform
import bleak
from time import sleep
from bleak import BleakClient
from bleak import _logger as logger
DEVICE_ADDRESS = '78211627-1BCD-4$05-AEBB-2222815AA2676'
DEVICE_WRITE_UUID = '50300002-0023-4bd4-bbd5-a6920e4c5653'
async def run(device_uuid_address, debug=False):
async def set_vibration(client, vibrator, intensity, duration):
await client.write_gatt_char(
DEVICE_WRITE_UUID,
vibration_command_byte_string(vibrator, intensity), True
)
#await asyncio.sleep(duration)
sleep(duration)
async with BleakClient(device_uuid_address) as client:
try:
x = await client.is_connected()
logger.info("Connected: {0}".format(x))
except bleak.exc.BleakError as e:
print(e)
await set_vibration(client=client, vibrator=1, intensity=0.99, duration=10)
def vibration_command_byte_string(vibrator, intensity):
intensity = int(intensity*20)
return_string = f'Vibrate{vibrator}:{intensity};'
return str.encode(return_string)
if __name__ == "__main__":
device_uuid_address = (
"21:70:84:aa:04:09"
if platform.system() != "Darwin"
else DEVICE_ADDRESS
)
loop = asyncio.get_event_loop()
loop.run_until_complete(run(device_uuid_address, True))
Notes:
- This code was only tested on OSX, so YMMV. Bleak is cross platform so I think it should work on Windows as well.
- You will need to input the MAC address and DEVICE ADDRESS for your Edge device on lines 14 and 48.
- The Edge is controlled by the command on line 35. The variables work as follows:
- vibrator: can be either 1 or 2
- intensity: a value between 0 and 1, with 0 being off and 1 being maximum power.
- duration: how long you want the Edge to run with those settings.
- Just duplicate line 35 to add different instructions.
I will do another post on how to find your MAC
address and DEVICE_ADDRESS
.