MQTT
The VBOX Touch supports requests via MQTT. This requires the user to enter the MQTT broker they wish to connect and how they are connecting to it (publish, subscribe or gateway). You also have to be connected to a WiFi network first.
Subscribe
You can create an MQTT Subscribe connection on the VBOX Touch to a topic through a broker. Each time there is a publish to the topic you are subscribed to you will receive data, and this is done without requesting. To create a subscribe connection you need to pass the name of your connection, connection type, broker, port, clientid, username, password and the topic you wish to subscribe to, to the connect() function.
network.connect('My_MQTT_Subscribe', 'MQTT Subscribe', 'your-broker.example.com', 8883, '', 'My_Example_Username', 'My_Example_Password', 'my/test/topic') # This has no client ID
Now each time there is a publish to this topic this will receive data.
Publish
You can create an MQTT Publish connection on the VBOX Touch to a topic through a broker. Each time there is a publish to the topic all subscribed devices will receive the data too. To create a publish connection you need to pass the name of your connection, connection type, broker, port, clientid, username, password and the topic you wish to subscribe to, to the connect() function.
network.connect('My_MQTT_Publish', 'MQTT Publish', 'your-broker.example.com', 8883, '', 'My_Example_Username', 'My_Example_Password', 'my/test/topic') # This has no client ID
Once you have established a publish connection you can send messages using the send_data function. This takes a parameter of the message you wish to publish. This message needs to be encoded with valid Extended ASCII characters.
network.get_connection_object_from_name('My_MQTT_Publish').send_data('Hello World!')
If you set up the connection using the above 2 examples then you should receive ‘Hello World!’ in the subscribe connection.
Gateway
The Gateway allows for bluetooth devices to have an MQTT connection via the VBOX Touch. There are 3 steps to connecting an external device via an MQTT Gateway on the VBOX Touch. First you have to create the MQTT Gateway on the VBOX Touch.
This is done similarly to Subscribe and Publish
network.connect('My_MQTT_Gateway', 'MQTT Gateway', 'your-broker.example.com', 8883, '', 'My_Example_Username', 'My_Example_Password', 'my/test/topic') # This has no client ID
Once you have this set up you then need to create a Bluetooth connection:
network.bond_to_device('Device Name')
network.connect('Bluetooth connection', 'Bluetooth', 'Device Name')
Once this connection is established you then need to send an MQTT Gateway request to the external bluetooth device.
This string is structured in the following way:
CONNECT_MQTT Connection_name, Type
So if you wanted to subscribe to the Gateway it would look something like this:
CONNECT_MQTT My_MQTT_Gateway, Subscribe
Now whenever the VBOX Touch receives a message from this topic it will be directly streamed to the other device.