Lataa laiteluettelo
First request the tenant’s sensors. Keep each device UUID, name and type. Show relay controls only when the backend device type is relay. Normalize UUIDs to lowercase hexadecimal without separators before comparing them.
GET https://backend.solvotix.org/api/sensor
Authorization: Bearer <TOKEN>
Tenant: <TENANT_ID>
Accept: application/jsonBackend online or offline status describes cloud communication. It must never decide whether a phone can currently see the device over Bluetooth.
Skannaa ja tunnista fyysinen laite
Scan continuously with duplicate advertisements while the device screen is visible. Use one application-wide scan owner because mobile BLE libraries commonly expose only one native scan.
- Request the platform’s Bluetooth scan and connect permissions, then start a low-latency scan.
- Accept the name SVN, but do not require it: Android may omit the local name.
- Recognize manufacturer ID 0x79fd. Build the primary eight-byte UUID from that ID in little-endian order followed by the first six manufacturer payload bytes.
- Match the normalized result with backend inventory, retain the native BLE device ID and RSSI, and remove nearby state after 10 seconds without an advertisement.
Stop scanning before connecting and resume it after disconnection. Two screens must not start competing native scans.
Pyydä laitepaketti taustapalvelulta
After the user confirms the target and physical action, request a complete node-core package for the device. Both relays and smart locks can provide packages for direct delivery. HTTP 200 means package generated only; it does not mean delivered or executed.
Esimerkki relepaketista
POST https://backend.solvotix.org/api/relay/{relayId}/package
Authorization: Bearer <TOKEN>
Tenant: <TENANT_ID>
Content-Type: application/jsonOpen
{ "operation": "open" }Close
{ "operation": "close" }Pulse
{
"operation": "pulse",
"value": 5,
"unit": "seconds"
}Consumption
{
"operation": "consumption",
"kwh": 1.5
}Pulse requires a positive value and milliseconds, seconds or minutes. Consumption requires kwh. Decode either packageBase64 or packageHex—not both—and require exactly 212 bytes. Never modify or log those bytes.
Älylukon paketit
Valitse haluttua lukon toimintoa vastaava pakettipäätepiste. Paketti käyttää samaa node-core-muotoa ja BLE-siirtoa.
GET https://backend.solvotix.org/api/smartlocks/{lockId}/packages/pulse-open
GET https://backend.solvotix.org/api/smartlocks/{lockId}/packages/open
GET https://backend.solvotix.org/api/smartlocks/{lockId}/packages/lock
Authorization: Bearer <TOKEN>
Tenant: <TENANT_ID>
Accept: application/jsonSiirrä paketti BLE:n kautta
Use the most recently seen native BLE device ID. Display a blocking progress overlay, stop scanning, clear a stale connection, connect and discover the exact node-core GATT service and write characteristic.
- Decode one package representation and verify that it is exactly 212 bytes.
- Read the negotiated MTU when available and calculate an MTU-safe chunk size.
- Write chunks sequentially in their original order. Prefer write without response when the characteristic supports it.
- After every chunk succeeds, disconnect in a final cleanup path. Never automatically retry a physical operation after delivery started.
- Resume continuous scanning after a short settling interval if the screen remains open.
chunkSize = max(20, min(215, negotiatedMtu - 3))
fallbackChunkSize = 20Keep the communication overlay visible during package generation, connection, discovery, every write and disconnection. Show clear success or failure.
Varmista ja raportoi oikea tulos
Completing all writes proves transport completion, not necessarily physical execution. Use a device acknowledgement or observed state when available.
- Report “Package transferred successfully” when BLE transport completes.
- Report physical completion only when the device or observed state confirms it.
- Log lifecycle stages and chunk lengths, but never tokens, package bytes, credentials or decoded payloads.
Do not automatically send the package again after an uncertain result. The relay may already have acted, and a repeated pulse or open command can be unsafe.
