Skip to content

Communication protocols

Depending on the type of Tap you have, the available protocols are:

In case of using a relay (gateway), for example Tap Manager app in relay mode, additional communication protocols are available:

Provided implementation

Bluetooth Low Energy (BLE)

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

// For Cordova environment
import { BLEComProtocol } from '@iotize/cordova-plugin-iotize-ble';
....
await this.tap.connect(new BLEComProtocol(AddressOrUUID));

// For node environment
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);

Please refer to javadoc of BLEProtocol and to Cordova Documentation.

NFC

Please note that NFC Communication is only available for Android environment.

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);

See javadoc for Android of NFCProtocol

Socket

For Wi-Fi communication, if you the program is connected to the same network as your Tap, 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);

See javadoc for Android of WIFIProtocol

MQTT

import { MqttProtocol } from '@iotize/device-com-mqtt.js';
let protocol = new MqttProtocol();
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");

Custom protocols

With implementing the ComProtocol interface (See javadoc for Android of ComProtocol), you can build your own version ofTap communication and a seamless integration with the rest of IoTize Libraries.

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

}