Przewodnik programisty

Znajdź pobliskie urządzenie i steruj jego przekaźnikiem

Praktyczny przewodnik od listy urządzeń i skanowania Bluetooth po pakiet, transmisję BLE i bezpieczną weryfikację.

Wróć do dokumentacji API
1

Pobierz listę urządzeń

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/json

Backend online or offline status describes cloud communication. It must never decide whether a phone can currently see the device over Bluetooth.

2

Skanuj i dopasuj urządzenie fizyczne

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.

Expected local nameSVN
Manufacturer ID0x79fd
Nearby timeout10 s
  1. Request the platform’s Bluetooth scan and connect permissions, then start a low-latency scan.
  2. Accept the name SVN, but do not require it: Android may omit the local name.
  3. 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.
  4. 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.

3

Poproś backend o pakiet urządzenia

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.

Przykład pakietu przekaźnika

POST https://backend.solvotix.org/api/relay/{relayId}/package
Authorization: Bearer <TOKEN>
Tenant: <TENANT_ID>
Content-Type: application/json

Open

{ "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.

Pakiety inteligentnego zamka

Wybierz endpoint pakietu odpowiadający działaniu zamka. Pakiet korzysta z tego samego formatu node-core i transmisji BLE.

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/json
4

Dostarcz pakiet przez BLE

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.

GATT service12345678-1234-5678-1234-56789abcdef0
Write characteristic12345678-1234-5678-1234-5678efbeadde
Package size212 bytes
  1. Decode one package representation and verify that it is exactly 212 bytes.
  2. Read the negotiated MTU when available and calculate an MTU-safe chunk size.
  3. Write chunks sequentially in their original order. Prefer write without response when the characteristic supports it.
  4. After every chunk succeeds, disconnect in a final cleanup path. Never automatically retry a physical operation after delivery started.
  5. Resume continuous scanning after a short settling interval if the screen remains open.
chunkSize = max(20, min(215, negotiatedMtu - 3))
fallbackChunkSize = 20

Keep the communication overlay visible during package generation, connection, discovery, every write and disconnection. Show clear success or failure.

5

Zweryfikuj i zgłoś właściwy wynik

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.