Skip to content

Communication protocols

Your Tap determines which protocols are available:

Your Tap may also be available through a relay (gateway), for example Tap Manager app. Additional communication protocols are available for this situation:

You can also implement a custom protocol.

Provided implementation

Bluetooth Low Energy (BLE)

Connect to bluetooth device with mac address C3:23:DE:AA:BB:CC

// Only available in node.js environment via noble library
import { NobleBLEAdapter, NobleBleScanner } from "@iotize/device-com-ble.node";

const DEVICE_ADDRESS = "C3:23:DE:AA:BB:CC";

let bleScanner = new NobleBleScanner();
let peripheral: noble.Peripheral = await bleScanner.getDeviceByAddress(DEVICE_ADDRESS);
let bleProtocol = new NobleBLEAdapter(peripheral);
import com.iotize.android.device.api.protocol.ComProtocol;
import com.iotize.android.communication.protocol.ble.BLEProtocol;

// From a bluetooth address
ComProtocol bleProtocol = BLEProtocol.fromAddress(context, "C3:23:DE:AA:BB:CC");

// If you already have an Android BluetoothDevice instance use this method:
BluetoothDevice bluetoothDevice = // ...
ComProtocol bleProtocol = BLEProtocol.fromDevice(context, bluetoothDevice);
// Not available yet

See javadoc for Android of BLEProtocol

NFC

Connect to an IoTize with an NFC tag:

// NOT AVAILABLE
import com.iotize.android.device.api.protocol.ComProtocol;
import com.iotize.android.communication.protocol.nfc.NFCProtocol;

// Suppose you have an NFC tag
android.nfc.Tag tag = // ...

// Instantiate the NFC protocol from this tag
ComProtocol nfcProtocol = NFCProtocol.create(tag);
// Not available yet

See javadoc for Android of NFCProtocol

Socket

For Wi-Fi communication, if you are connected on the same network as the IoTize, you can use this method to instantiate your communication object:

// With node environment, use sockets
import { SocketProtocol } from "@iotize/device-com-socket.node"
let protocol = new SocketProtocol({
    host: 'localhost',
    port: 2000
})

// With browser environment, use web sockets
import { WebSocketProtocol } from "@iotize/device-com-websocket.js"
let protocol = new WebSocketProtocol({
    url: 'tcp://localhost:2000'
})
import com.iotize.android.communication.protocol.socket.SocketProtocol;
import com.iotize.android.communication.protocol.socket.WIFI.WIFIProtocol;
import com.iotize.android.device.api.protocol.ComProtocol;

// Socket protocol
ComProtocol socketProtocol = new SocketProtocol(new InetSocketAddress("<YOUR_IP_ADDRESS>", <PORT>));

// Wi-Fi protocol (for Tap with Wi-Fi capability)
// If we are already connected to the same network as the Tap:
ComProtocol wifiProtocol = WIFIProtocol.fromIP(context, "192.168.1.1");

// To connect on a specific network, use WifiConfiguration
android.net.wifi.WifiConfiguration wifiConfig;
// If you have an open network
wifiConfig = WIFIProtocol.createConfiguration("networkssid", WIFIProtocol.SecurityType.OPEN);
// Network with WPA key
wifiConfig = WIFIProtocol.createConfiguration("networkssid", WIFIProtocol.SecurityType.WPA, "wifipassord");
// Network with WEP key
wifiConfig = WIFIProtocol.createConfiguration("networkssid", WIFIProtocol.SecurityType.WEP, "wifipassord");

// Create the protocol with a specific network configuration
wifiProtocol = WIFIProtocol.fromIP(context, "192.168.1.1", wifiConfig);
// Not available yet

See javadoc for Android of WIFIProtocol

MQTT

import { MqttProtocol } from "@iotize/device-com-mqtt.js";
let protocol = new MqttProtocol();
// Not yet documented 
import com.iotize.android.communication.protocol.mqtt.MQTTProtocol;
import com.iotize.android.communication.protocol.mqtt.IoTizeMQTTClient;

IoTizeMQTTClient mqttClient = new IoTizeMQTTClient("tcp://<yourbrokerurl>:<port>", "ClientId1", "/your/publish/topic");
MQTTProtocol protocol = new MQTTProtocol(mqttClient);

// Configure your protocol
protocol
    .subscribeToTopics(new String[]{
        "/topic/to/subscribe/for/incomming/requests"
    })
    .setResponseTopic("/topic/wher/to/send/response");
// Not available yet

LoRa

Not yet available.

Create your own

To use your own protocol, implement interface ComProtocol (See javadoc for Android of ComProtocol)

import { ComProtocol } from '@iotize/device-client/protocol/api';

// Implement interface
class MyCustomProtocol implements ComProtocol{

    // Your implementation here

}

// You can also simply override QueueComProtocol
import { QueueComProtocol } from '@iotize/device-client/protocol/impl';

class MyCustomProtocol extends QueueComProtocol{

}
import com.iotize.android.device.api.protocol.ComProtocol;

class MyCustomProtocol implements ComProtocol{

    // Your implementation here

}
import TapClientApi

class MyCustomProtocol: ComProtocol{

    // Your implementation here

}