Android
Setting up a connection
import com.terra.TerraRT
import com.terra.TerraRT.Connections
import com.terra.TerraRT.DataTypes
import com.terra.TerraRT.Update
import android.os.Handler
import android.os.Looper
val terraRT = TerraRT()
val token = "yourAuthToken" // Replace with your actual token
// Initialize TerraRT SDK connection
terraRT.initConnection(token) { success ->
if (success) {
println("TerraRT initialized successfully!")
// Start device scan for BLE connection
terraRT.startDeviceScan(type = Connections.BLE) { scanSuccess ->
if (scanSuccess) {
println("Device connected successfully!")
// Start streaming real-time data using the new function signature
val dataTypes: Set<DataTypes> = setOf(DataTypes.HEART_RATE, DataTypes.STEPS)
terraRT.startRealtime(
type = Connections.BLE,
dataTypes = dataTypes,
token = token,
updateHandler = { update ->
handleUpdate(update)
},
connectionCallback = { connectionSuccess ->
if (connectionSuccess) {
println("Real-time connection successfully established!")
} else {
println("Failed to establish real-time connection.")
}
}
)
// Stop streaming after 5 seconds for demo purposes
Handler(Looper.getMainLooper()).postDelayed({
terraRT.stopRealtime(type = Connections.BLE)
println("Real-time streaming stopped.")
// Optionally disconnect the device
terraRT.disconnect(type = Connections.BLE)
println("Device disconnected.")
}, 5000)
} else {
println("Failed to connect to the device.")
}
}
} else {
println("Failed to initialize TerraRT.")
}
}
fun handleUpdate(update: Update) {
println("Received update at timestamp: ${update.ts}")
println("Update type: ${update.type}")
update.`val`?.let { value ->
println("Value: $value")
}
}
Endpoint for generation of a token for a user (producer) connection
Authorizations
x-api-keystringRequired
dev-idstringRequired
Query parameters
idstringOptional
The ID of the user to generate a token for
Header parameters
dev-idstringRequired
your developer ID
x-api-keystringRequired
your API key
Responses
200
Successful response
application/json
403
Forbidden
text/plain
post
/auth/userLast updated
Was this helpful?