SimpleBLE.jl

SimpleBLE is a cross-platform bluetooth low energy (BLE) library, designed for simplicity and ease of use.

Simple example

# Get an adapter that will handle requests
adapter = get_adapter(0)
# Find a peripheral using adapter
peripheral = find_peripheral(adapter) do id
    occursin("peripheral name", id)
end
id = identifier(peripheral)
connect(peripheral) do
    SERVICE = "de8d0b82-c7cd-0f33-d15d-c38e1f26673f"
    CHARACTER = "6706b606-0c12-3976-ddba-909377d43dc5"
    notify(peripheral, SERVICE, CHARACTER) do data
        # make sure not to pass the data handle outside the callback
        # it is not valid data once this callback is over, if you need to keep it, copy it
        println("$id received data:")
        println(String(data))
    end
    println("Press enter to stop listening")
    readline()
    unsubscribe(peripheral, SERVICE, CHARACTER)
end

Most common functions

SimpleBLE.find_peripheralFunction
find_peripheral(matchfunc, adapter)
find_peripheral(adapter) do identifier::String
	# Stuff
	return output::Bool
end

Convenience function for finding a peripheral. identifier is the name of the peripheral, it can be an empty string.

source
SimpleBLE.connectFunction
connect(peripheral)

Connect to a peripheral. Generally you should disconnect when you're done with it

source
connect(callback, peripheral)
connect(peripheral) do
	# Stuff
end

Convenience function for automatically disconnecting from a peripheral once you're done with it

source
Base.notifyFunction
notify(callback,
	peripheral::Peripheral,
	service::Union{AbstractString, SBLEUUID, SBLESERVICE},
	characteristic::Union{AbstractString, SBLEUUID, SBLECHARACTERISTIC}
)
notify(
	peripheral::Peripheral,
	service::Union{AbstractString, SBLEUUID, SBLESERVICE},
	characteristic::Union{AbstractString, SBLEUUID, SBLECHARACTERISTIC}
) do data
	# Stuff
end

Set a callback that is called when data is received from a Characteristic. notify is generally faster than indicate because it does not need to acknowledge that it received the data.

See also indicate

Warning

WARNING: YOU MUST NOT PASS THE data VECTOR OUTSIDE THE CALLBACK, IT IS NOT VALID AFTER THE CALLBACK FINISHES, IF YOU NEED TO KEEP THE DATA AFTER THE CALLBACK IS FINISHED, COPY IT!

source
SimpleBLE.write_requestFunction
write_request(peripheral,
	service::Union{AbstractString, SBLEUUID, SBLESERVICE},
	characteristic::Union{AbstractString, SBLEUUID, SBLECHARACTERISTIC},
	data <: Union{AbstractString, AbstractArray}
)

Write a request to a characteristic.

See also write_command

source
SimpleBLE.peripheral_readFunction
peripheral_read(peripheral, 
	service::Union{AbstractString, SBLEUUID, SBLESERVICE},
	characteristic::Union{AbstractString, SBLEUUID, SBLECHARACTERISTIC},
)

Read data from a characteristic.

service and characteristic can be AbstractStrings, SBLEUUIDs, or SBLESERVICE and SBLECHARACTERISTIC acquired by services.

source