Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module exports all you should need to build a Bluetooth Low Energy (BLE) peripheral.
The core concepts involved are:
Application
- This contains the entirety of your application, and is
composed of zero or more
Service
s. Service
- A set of zero or more conceptually related
Characteristic
s. Identified by it'sUUID
. Characteristic
Characteristic
s represent the actual data of your application. They may allow reading, writing, and subscribing. Also identified by it'sUUID
.Advertisement
- This describes how an application will advertise itself to other BLE devices.
All three have IsString
instances and lens field accessors. The
recommended way of using this library is by using the OverloadedStrings
pragma and lenses. A complete example can be found
here.
{-# LANGUAGE OverloadedStrings #-} import Bluetooth import Control.Concurrent (threadDelay) app :: Application app = "/com/turingjump/example" & services .~ [aService] aService :: Service aService = "d0bc6707-e9a5-4c85-8d22-d73d33f0330c" & characteristics .~ [aCharacteristic] aCharacteristic :: CharacteristicBS aCharacteristic = "b3170df6-1770-4d60-86db-a487534cbcc3" & readValue ?~ encodeRead (return (32::Int)) & properties .~ [CPRead] main :: IO () main = do conn <- connect runBluetoothM (registerAndAdverstiseApplication app) conn threadDelay maxBound
- registerApplication :: Application -> BluetoothM ApplicationRegistered
- registerAndAdvertiseApplication :: Application -> BluetoothM ApplicationRegistered
- unregisterApplication :: ApplicationRegistered -> BluetoothM ()
- advertise :: WithObjectPath Advertisement -> BluetoothM ()
- advertisementFor :: Application -> WithObjectPath Advertisement
- unadvertise :: WithObjectPath Advertisement -> BluetoothM ()
- connect :: IO Connection
- runBluetoothM :: BluetoothM a -> Connection -> IO (Either Error a)
- runHandler :: Handler a -> IO (Either Text a)
- uuid :: HasUuid s a => Lens' s a
- properties :: HasProperties s a => Lens' s a
- readValue :: HasReadValue s a => Lens' s a
- writeValue :: HasWriteValue s a => Lens' s a
- characteristics :: HasCharacteristics s a => Lens' s a
- services :: HasServices s a => Lens' s a
- path :: HasPath s a => Lens' s a
- type_ :: HasType_ s a => Lens' s a
- value :: HasValue s a => Lens' s a
- solicitUUIDs :: HasSolicitUUIDs s a => Lens' s a
- serviceUUIDs :: HasServiceUUIDs s a => Lens' s a
- manufacturerData :: HasManufacturerData s a => Lens' s a
- serviceData :: HasServiceData s a => Lens' s a
- includeTxPower :: HasIncludeTxPower s a => Lens' s a
- connectionName :: Connection -> Text
- characteristicIsNotifying :: UUID -> MVar Bool
- triggerNotification :: ApplicationRegistered -> CharacteristicBS -> BluetoothM ()
- data Connection
- data Application
- data ApplicationRegistered
- data Service
- data UUID = UUID UUID
- data CharacteristicProperty
- data Characteristic typ
- type CharacteristicBS = Characteristic ByteString
- data Advertisement = Advertisement {}
- data WithObjectPath a
- encodeRead :: Serialize a => Handler a -> Handler ByteString
- encodeWrite :: Serialize a => (a -> Handler Bool) -> ByteString -> Handler Bool
- data Handler a
- errorFailed :: Handler a
- errorInProgress :: Handler a
- errorNotPermitted :: Handler a
- errorNotSupported :: Handler a
- errorNotAuthorized :: Handler a
- errorInvalidValueLength :: Handler a
- module Lens.Micro
- module Lens.Micro.GHC
Documentation
registerApplication :: Application -> BluetoothM ApplicationRegistered Source #
Registers an application (set of services) with Bluez.
registerAndAdvertiseApplication :: Application -> BluetoothM ApplicationRegistered Source #
Registers an application and advertises it. If you would like to have
finer-grained control of the advertisement, use registerApplication
and
advertise
.
advertise :: WithObjectPath Advertisement -> BluetoothM () Source #
Advertise a set of services.
advertisementFor :: Application -> WithObjectPath Advertisement Source #
Create an advertisement for all of an application's services. The advertisement will be for peripheral (not broadcast) by default.
unadvertise :: WithObjectPath Advertisement -> BluetoothM () Source #
Unregister an adverstisement.
connect :: IO Connection Source #
Creates a connection to DBus. This does *not* represent Bluetooth connection.
runBluetoothM :: BluetoothM a -> Connection -> IO (Either Error a) Source #
Field lenses
properties :: HasProperties s a => Lens' s a Source #
The properties of e.g. a characteristic.
readValue :: HasReadValue s a => Lens' s a Source #
Access the handler for reading a value, if there is one.
writeValue :: HasWriteValue s a => Lens' s a Source #
Access the handler for writing a value, if there is one. The handler
should return True
if the value was successfully update.
characteristics :: HasCharacteristics s a => Lens' s a Source #
An access for the list of characteristics.
services :: HasServices s a => Lens' s a Source #
An access for the list of services.
value :: HasValue s a => Lens' s a Source #
Returns the actual value of an entity that is wrapped in an
solicitUUIDs :: HasSolicitUUIDs s a => Lens' s a Source #
Accessor for solicit UUIDs. These are UUIDs that an application or service expects to be available.
serviceUUIDs :: HasServiceUUIDs s a => Lens' s a Source #
Accessor for service UUIDs
manufacturerData :: HasManufacturerData s a => Lens' s a Source #
Accessor for manufacting data.
serviceData :: HasServiceData s a => Lens' s a Source #
Accessor for manufacting data.
includeTxPower :: HasIncludeTxPower s a => Lens' s a Source #
Accessor for indicating whether an Advertisement
announces TX power
(transmission power).
connectionName :: Connection -> Text Source #
The unique DBus connection name, Useful for monitoring activity with 'dbus-monitor'. For information on how to setup dbus-monitor for debugging, see DebuggingDBus.
Since: 0.1.3.0
Notifications
triggerNotification :: ApplicationRegistered -> CharacteristicBS -> BluetoothM () Source #
Triggers notifications or indications.
BLE Types
Types representing components of a BLE application.
data Application Source #
An application. Can be created from it's IsString
instance.
The string (application path) is used only for the DBus API, and will not
have relevance within Bluetooth.
data ApplicationRegistered Source #
This datatype, which is kept opaque, is returned when an application is successfully registered, and required as an argument from functions that should only be called after the application has been registered.
UUIDs, used for services and characteristics.
Unofficial UUIDs will have 128-bits, and will look this:
d45e83fb-c772-459e-91a8-43cbf1443af4
Official UUIDs will have either 32 or 16 bits.
See ITU-T Rec. X.677 for more information on the format and generation of these UUIDs. You can use the Online UUID Generator to generate UUIDs.
Eq UUID Source # | |
Ord UUID Source # | |
Show UUID Source # | |
IsString UUID Source # | |
Generic UUID Source # | |
Representable UUID Source # | |
Random UUID Source # | |
HasUuid Service UUID Source # | |
HasSolicitUUIDs Advertisement [UUID] Source # | |
HasServiceUUIDs Advertisement [UUID] Source # | |
HasServiceData Advertisement (Map UUID ByteString) Source # | |
HasUuid (Characteristic typ0) UUID Source # | |
type Rep UUID Source # | |
type RepType UUID Source # | |
data CharacteristicProperty Source #
data Characteristic typ Source #
HasCharacteristics Service [CharacteristicBS] Source # | |
IsString (Characteristic a) Source # | |
Generic (Characteristic typ) Source # | |
Representable (WithObjectPath (Characteristic a)) Source # | |
HasUuid (Characteristic typ0) UUID Source # | |
HasInterface (WithObjectPath CharacteristicBS) GattCharacteristic Source # | |
HasInterface (WithObjectPath CharacteristicBS) Properties Source # | |
HasWriteValue (Characteristic typ0) (Maybe (typ0 -> Handler Bool)) Source # | |
HasReadValue (Characteristic typ0) (Maybe (Handler typ0)) Source # | |
HasProperties (Characteristic typ0) [CharacteristicProperty] Source # | |
type Rep (Characteristic typ) Source # | |
type RepType (WithObjectPath (Characteristic a)) Source # | |
data Advertisement Source #
An advertisement can be generated automatically with advertisementFor
,
or with the IsList
instance. Both of these by default assume the
advertisement is for a peripheral.
You can also, of course, use the constructor.
data WithObjectPath a Source #
Encoding and decoding
Helpers for readValue
and writeValue
.
encodeRead :: Serialize a => Handler a -> Handler ByteString Source #
encodeWrite :: Serialize a => (a -> Handler Bool) -> ByteString -> Handler Bool Source #
Handler
Handler
is the monad BLE handlers run in.
Monad Handler Source # | |
Functor Handler Source # | |
Applicative Handler Source # | |
MonadIO Handler Source # | |
MonadError Text Handler Source # | |
Generic (Handler a) Source # | |
HasWriteValue (Characteristic typ0) (Maybe (typ0 -> Handler Bool)) Source # | |
HasReadValue (Characteristic typ0) (Maybe (Handler typ0)) Source # | |
type Rep (Handler a) Source # | |
Handler errors
errorFailed :: Handler a Source #
Generic failure
errorInProgress :: Handler a Source #
errorNotPermitted :: Handler a Source #
errorNotSupported :: Handler a Source #
errorNotAuthorized :: Handler a Source #
errorInvalidValueLength :: Handler a Source #
Indicates that the argument has invalid length. Should not be used from a read handler
Re-exports
module Lens.Micro
module Lens.Micro.GHC