Skip to content

Commit

Permalink
Release v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MGasztold committed May 6, 2017
1 parent c94c0f4 commit fa2e9c8
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 84 deletions.
173 changes: 119 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ Then add the following dependency:

```
dependencies {
compile('com.ubudu.iot:iot-sdk:1.0.0@aar')
compile('com.ubudu.iot:iot-sdk:1.1.0@aar')
// …
}
```

## How to use?

### u_ble_scanner discovery
### u\_ble\_scanner discovery

Create an object implementing the `DongleFilter` interface. This interface is used to let the `DongleManager` class pick the desired device from all detectable devices nearby.:

Expand All @@ -36,45 +36,51 @@ Create an object implementing the `DongleFilter` interface. This interface is us
}
};

Then to start Bluetooth LE discovery:
Then to discover a dongle:

dongleManager = new DongleManager(mContext);
dongleManager.findDongle(dongleFilter, new DongleManager.DiscoveryListener() {
@Override
public void onDongleFound(Dongle dongle) {
// matching dongle found
mDongle = dongle;
}
DongleManager.findDongle(dongleFilter, new DongleManager.DiscoveryListener() {

@Override
public void onDiscoveryError(Error error) {
// Bluetooth LE discovery error
}
});
@Override
public void onDongleFound(Dongle dongle) {
// matching dongle found
mDongle = dongle;
}

@Override
public void onDiscoveryError(Error error) {
// Bluetooth LE discovery error
}
});


### u_ble_scanner connection
### u\_ble\_scanner connection

Before connecting to the detected dongle first set a connection interface:

mDongle.setConnectionListener(new Dongle.ConnectionListener() {
@Override
public void onConnected() {
// connected to dongle
}

@Override
public void onDisconnected() {
// disconnected from dongle
}

@Override
public void onConnectionError(Error error) {
// connection error
}

@Override
public void onConnected() {
// connected to dongle
}
@Override
public void onDisconnected() {
// disconnected from dongle
}
@Override
public void onReady() {
// after this event the dongle is ready for handling sendData calls
}
@Override
public void onConnectionError(Error error) {
// connection error
}
});

Then the following can be called:
To connect to the dongle instance received in the `onDongleFound(Dongle dongle)` event please call the following:

mDongle.connect(mContext);

Expand All @@ -84,39 +90,39 @@ To disconnect from the dongle please call:

mDongle.disconnect();

### u_ble_scanner communication
### u\_ble\_scanner communication

To communicate with the connected dongle first set a communication interface:

mDongle.setCommunicationListener(new Dongle.CommunicationListener() {
@Override
public void onDataReceived(byte[] data) {
// data received from dongle
}

@Override
public void onDataSent(byte[] data) {
// data sent to dongle
}

@Override
public void onCommunicationError(Error error) {
// communication error
}
});

Then the following can be called:
@Override
public void onDataReceived(byte[] data) {
// data received from dongle
}
@Override
public void onDataSent(byte[] data) {
// data sent to dongle
}
@Override
public void onCommunicationError(Error error) {
// communication error
}
});

Then the `send(byte[] data)` can be called:

String message = "My message.";
byte[] data = message.getBytes();
mDongle.send(data);

### IBeacon advertising
### Bluetooth LE advertising

Setup advertiser:

Advertiser advertiser = new Advertiser(mContext);
advertiser.setListener(new Advertiser.EventListener() {
advertiser.setListener(new Advertiser.AdvertisingListener() {
@Override
public void onAdvertisingStarted() {
// advertising started
Expand All @@ -133,10 +139,69 @@ Setup advertiser:
}
});

Start advertising:
Start advertising as IBeacon:

advertiser.advertise(IBeacon.getAdvertiseBytes("67D37FC1-BE36-4EF5-A24D-D0ECD8119A7D", "12", "312", -55),true);

advertiser.advertise("67D37FC1-BE36-4EF5-A24D-D0ECD8119A7D", "12", "312", -55);
The boolean argument determines whether the device should be connectable or not.

Stop advertising:

advertiser.stopAdvertising();
advertiser.stopAdvertising();

### Make mobile device act as a connectable dongle

To make that happen the following code should be called before starting to advertise:

peripheralManager = new PeripheralManager(getApplicationContext(), new DeviceProfile() {
@Override
public String getServiceUuid() {
// service UUID to expose characteristics
return "D9500001-F608-42CD-A37E-92A559491B2B";
}
@Override
public String getWriteCharacteristicUuid() {
// write-only characteristic UUID
return "D9500002-F608-42CD-A37E-92A559491B2B";
}
@Override
public String getReadCharacteristicUuid() {
// read-only characteristic UUID
return "D9500003-F608-42CD-A37E-92A559491B2B";
}
});

peripheralManager.setEventListener(new PeripheralManager.PeripheralListener() {

@Override
public void onPeripheralReady() {
// gatt server is ready to handle connections and communication
}
@Override
public void onConnectionStateChange(String stateDescription) {
// outside device connection state changed
}
@Override
public void onCharacteristicWritten(UUID characteristicUUID, String value) {
// on data received
}
@Override
public void onCharacteristicRead(UUID characteristicUUID, String value) {
// on data read
}
@Override
public void onPeripheralError(Error error) {
// error event
}
});
peripheralManager.openGattServer();

To stop the device from being a connectable peripheral:

peripheralManager.closeGattServer();
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ dependencies {
compile 'com.jakewharton:butterknife:8.5.1'
apt 'com.jakewharton:butterknife-compiler:8.5.1'

compile('com.ubudu.iot:iot-sdk:1.0.0@aar')
compile('com.ubudu.iot:iot-sdk:1.1.0@aar')
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ubudu.costacoffee;
package com.ubudu.unittests;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand All @@ -21,6 +21,6 @@ public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.ubudu.costacoffee", appContext.getPackageName());
assertEquals("com.ubudu.unittests", appContext.getPackageName());
}
}
Loading

0 comments on commit fa2e9c8

Please sign in to comment.