Nodle SDK - Android API and Configuration
The SDK receives configuration remotely from Nodle servers as well as statically using API calls. The static configuration always takes precedence over the remote configuration.

Nodle SDK Api

To interact with the SDK you need to call the Nodle() method that will give you an Instance of the INodle class. The following are all the public methods for the Nodle API.
Java
Kotlin
1
import static io.nodle.sdk.android.Nodle.Nodle;
2
​
3
INodle nodle = Nodle();
Copied!
1
import io.nodle.sdk.android.Nodle.Nodle
2
​
3
val nodle = Nodle()
Copied!

init

public fun init(context: Context)
Initialize the Nodle SDK
Parameters
​
context
A Context of the application. This value must never be null.
Example:
Java
Kotlin
1
Nodle.init(this);
Copied!
1
Nodle.init(this)
Copied!

start

public fun start(public_key: String)
Immediately starts the Nodle SDK
Parameters
​
public_key
The application public_key created in Step 1
Example:
Java
Kotlin
1
Nodle().start("ss58:public_key");
Copied!
1
Nodle().start("ss58:public_key")
Copied!

isStarted

public fun isStarted(): Boolean
Checks if the Nodle SDK is started
Returns
​
boolean
true if the Nodle SDK is started, false otherwise
Example:
Java
Kotlin
1
Boolean sdkStarted = Nodle().isStarted()
Copied!
1
val sdkStarted = Nodle().isStarted()
Copied!

isScanning

public fun isScanning(): Boolean
Checks if the Nodle SDK is currently scanning the BLE neighborhood. This is useful if you want to show that the SDK is working.
Returns
​
boolean
true if the Nodle SDK is scanning, false otherwise
Example:
Java
Kotlin
1
Boolean sdkScanning = Nodle().isScanning()
Copied!
1
val sdkScanning = Nodle().isScanning()
Copied!

stop

public fun stop()
Immediately stops the Nodle SDK
Example:
Java
Kotlin
1
Nodle().stop();
Copied!
1
Nodle().stop()
Copied!

clear

public fun clear()
Clear any configs by Nodle SDK
Example:
Java
Kotlin
1
Nodle().clear();
Copied!
1
Nodle().clear()
Copied!

getVersion

public fun getVersion(): String
Get the version identifier of the Nodle SDK.
Returns
​
String
the current version of the Nodle SDK
Example:
Java
Kotlin
1
String nodleSdkVersion = Nodle().getVersion();
Copied!
1
val nodleSdkVersion = Nodle().getVersion()
Copied!

getEvents

public fun getEvents(): NodleEvent
Get the raw bluetooth events from the Nodle SDK with the following type:
Returns
​
NodleEventType.BlePayloadEvent
Returns NodleBluetoothScanRecord
NodleEventType.BleStartSearching
Returns NodleBluetoothEvent
NodleEventType.BleStopSearching
Returns NodleBluetoothEvent
Example of available return event classes below:
Returns
​
NodleBluetoothScanRecord
Raw Bluetooth Record from Nodle SDK
NodleBluetoothEvent
Bluetooth Event when the SDK start/stop
Example:
Java
Kotlin
1
BuildersKt.launch(GlobalScope.INSTANCE, (CoroutineContext) Dispatchers.getMain(), CoroutineStart.DEFAULT,
2
(Function2<CoroutineScope, Continuation<? super Unit>, Unit>) (coroutineScope, continuation) -> {
3
// start collecting events
4
nodle.getEvents().collect(new NodleCollector(), new NodleContinuation());
5
return Unit.INSTANCE;
6
}
7
);
Copied!
1
Nodle().getEvents().collect { event ->
2
// collect the NodleEvents events here by chosing a type
3
when (event.type) {
4
NodleEventType.BlePayloadEvent -> handlePayload(it)
5
NodleEventType.BleStartSearching -> println("Bluetooth started searching")
6
NodleEventType.BleStopSearching -> println("Bluetooth stopped searching")
7
}
8
}
9
​
10
fun handlePayload(payload: NodleEvent) {
11
val data = payload as NodleBluetoothScanRecord
12
println("Bluetooth payload available ${data.device} ")
13
}
Copied!
Example Nodle Collector for Java:
Java
1
import androidx.annotation.NonNull;
2
import androidx.annotation.Nullable;
3
import io.nodle.sdk.NodleEvent;
4
import io.nodle.sdk.core.actions.events.NodleBluetoothRecord;
5
import kotlin.Unit;
6
import kotlin.coroutines.Continuation;
7
import kotlinx.coroutines.flow.FlowCollector;
8
​
9
public class NodleCollector implements FlowCollector<NodleEvent> {
10
@Nullable
11
@Override
12
public Object emit(NodleEvent nodleEvent, @NonNull Continuation<? super Unit> continuation) {
13
switch (nodleEvent.getType()) {
14
case BlePayloadEvent:
15
NodleBluetoothRecord payload = (NodleBluetoothRecord) nodleEvent;
16
System.out.println("Bluetooth payload available: " + payload.getDevice());
17
break;
18
case BleStartSearching:
19
System.out.println("Bluetooth started searching");
20
break;
21
case BleStopSearching:
22
System.out.println("Bluetooth stop searching");
23
break;
24
}
25
return nodleEvent;
26
}
27
}
28
​
Copied!
Example Nodle Continuation for Java:
Java
1
import androidx.annotation.NonNull;
2
import kotlin.coroutines.Continuation;
3
import kotlin.coroutines.CoroutineContext;
4
import kotlin.coroutines.EmptyCoroutineContext;
5
​
6
public class NodleContinuation implements Continuation {
7
@NonNull
8
@Override
9
public CoroutineContext getContext() {
10
// pass an empty instance or one that you need
11
return EmptyCoroutineContext.INSTANCE;
12
}
13
​
14
@Override
15
public void resumeWith(@NonNull Object o) {
16
// provide a base implementation if you need
17
}
18
}
19
​
Copied!
The following data can be collected from the NodleEventType:
Key
Description
Default Value
type
returns nodle bluetooth event type
NodleEventType
The following data can be collected from the NodleBluetoothScanRecord:
Key
Description
Default Value
device
returns device unique identifier
String
rssi
returns received signal strength indicator
Int
bytes
returns raw bytes of the record
ByteArray
manufacturerSpecificData
returns the manufacturer specific data associated with the manufacturer id
Map<Int, ByteArray>
servicesUuids
returns an array of services UUID's within the advertisement
List<UUID>
The following data can be collected from the NodleBluetoothEvent:
Key
Description
Default Value
scanning
returns bluetooth scanning state
Boolean

config

public fun config(resourceId: AndroidNodleResourceId)
public fun <T> config(key: String, value: T)
configure the SDK either by supplying a json file located in res/raw/config.json or by directly configuring a key. An example of a json configuration look like this:
1
{
2
"ble": {
3
"scan": {
4
"duration-msec": 10000,
5
"interval-msec": 90000,
6
"interval-x-factor": 1
7
}
8
},
9
"dtn": {
10
"use-cellular": false
11
}
12
}
Copied!
the following are the table of all the keys available and their description:
Key
Description
Default Value
ble.scan.duration-msec
duration of a single ble pass in milliseconds. Longer scan increase battery consumption but gives more reward.
10000
ble.scan.interval-msec
wait time between two ble pass in milliseconds. Longer period reduce battery consumption but gives less reward
90000
ble.scan.interval-x-factor
multiplier for the ble scan interval above.
1
dtn.use-cellular
if true, the cellular connexion will be used. if false, only wifi connection will be used.
true
sentry.enabled
if true, our crash reporting will send us crash reports. If false there will be no crash reports to send.
true
Example:
Java
Kotlin
1
import io.nodle.sdk.android.common.config.AndroidNodleResourceId;
2
​
3
// load the json config located in res/raw/config.json
4
Nodle().config(AndroidNodleResourceId(R.raw.sdk_config));
5
​
6
// or you can manually set the entries, for instance
7
Nodle().config("dtn.use-cellular", false);
8
​
9
// then proceed to start Nodle
10
Nodle().start()
Copied!
1
import io.nodle.sdk.android.common.config.AndroidNodleResourceId
2
​
3
// load the json config located in res/raw/config.json
4
Nodle().config(AndroidNodleResourceId(R.raw.sdk_config))
5
​
6
// or you can manually set the entries, for instance
7
Nodle().config("dtn.use-cellular", false)
Copied!
​