-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,101 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,8 @@ | ||
# Built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# Files for the ART/Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
out/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Android Studio Navigation editor temp files | ||
.navigation/ | ||
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
# Intellij | ||
*.iml | ||
.idea/workspace.xml | ||
|
||
# Keystore files | ||
*.jks | ||
.gradle | ||
/local.properties | ||
/.idea/ | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# Android-IoT-SDK | ||
|
||
This SDK is dedicated to handling connection + bidirectional communication with the `ub_ble_scanner` device. SDK also provides an IBeacon advertising feature. | ||
|
||
## Installing | ||
|
||
Add Ubudu nexus repository url to your `build.gradle` file: | ||
|
||
``` | ||
repositories { | ||
mavenCentral() | ||
maven { url 'http:https://nexus.ubudu.com:8081/nexus/content/groups/public/' } | ||
} | ||
``` | ||
|
||
Then add the following dependency: | ||
|
||
``` | ||
dependencies { | ||
compile('com.ubudu.iot:iot-sdk:1.0.0@aar') | ||
// … | ||
} | ||
``` | ||
|
||
## How to use? | ||
|
||
### 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.: | ||
|
||
DongleFilter dongleFilter = new DongleFilter() { | ||
@Override | ||
public boolean isCorrect(BluetoothDevice device) { | ||
// example implementation: | ||
return device.getName() != null && device.getName().equals(MY_DONGLE_NAME); | ||
} | ||
}; | ||
|
||
Then to start Bluetooth LE discovery: | ||
|
||
dongleManager = new DongleManager(mContext); | ||
dongleManager.findDongle(dongleFilter, new DongleManager.DiscoveryListener() { | ||
@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 | ||
|
||
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 | ||
} | ||
}); | ||
|
||
Then the following can be called: | ||
|
||
mDongle.connect(mContext); | ||
|
||
When a dongle is already connected to another device the `onConnectionError(error)` is called after a while. | ||
|
||
To disconnect from the dongle please call: | ||
|
||
mDongle.disconnect(); | ||
|
||
### 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: | ||
|
||
String message = "My message."; | ||
byte[] data = message.getBytes(); | ||
mDongle.send(data); | ||
|
||
### IBeacon advertising | ||
|
||
Setup advertiser: | ||
|
||
Advertiser advertiser = new Advertiser(mContext); | ||
advertiser.setListener(new Advertiser.EventListener() { | ||
@Override | ||
public void onAdvertisingStarted() { | ||
// advertising started | ||
} | ||
|
||
@Override | ||
public void onAdvertisingStopped() { | ||
// advertising started | ||
} | ||
|
||
@Override | ||
public void onAdvertisingError(Error error) { | ||
// advertising error | ||
} | ||
}); | ||
|
||
Start advertising: | ||
|
||
advertiser.advertise("67D37FC1-BE36-4EF5-A24D-D0ECD8119A7D", "12", "312", -55); | ||
|
||
Stop advertising: | ||
|
||
advertiser.stopAdvertising(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'android-apt' | ||
|
||
repositories { | ||
maven { url 'https://maven.fabric.io/public' } | ||
maven { url 'http:https://nexus.ubudu.com:8081/nexus/content/groups/public/' } | ||
} | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.2" | ||
defaultConfig { | ||
applicationId "com.ubudu.iot.sample" | ||
minSdkVersion 18 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:25.2.0' | ||
compile 'com.android.support.constraint:constraint-layout:1.0.2' | ||
compile 'com.android.support:design:25.2.0' | ||
testCompile 'junit:junit:4.12' | ||
|
||
// butter knife | ||
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') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/matthieu/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http:https://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/ubudu/costacoffee/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ubudu.costacoffee; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http:https://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.ubudu.costacoffee", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android" | ||
package="com.ubudu.iot.sample"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme.NoActionBar"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Oops, something went wrong.