MQTT

From DreamFactory
Jump to: navigation, search
(Created page with "DreamFactory v2.8.0 and greater includes support for MQTT (Message Queuing Telemetry Transport), a lightweight messaging protocol commonly used for exchanging information betw...")
 
Line 38: Line 38:
  
 
With the extension in place, you'll need to restart the PHP service in order for the configuration changes to take effect.
 
With the extension in place, you'll need to restart the PHP service in order for the configuration changes to take effect.
 +
 +
== Integrating MQTT Into DreamFactory ==
 +
 +
To integrate an MQTT broker into DreamFactory, login to the DreamFactory administration interface and navigate to Services > Create > Service Type > IoT > MQTT. You'll then configure the MQTT service much as you would any other, completing a series of form fields:
 +
 +
* Name: The service name which will be included in the API URL.
 +
* Label: A friendly label with which the service will be identified inside the DreamFactory administration interface.
 +
* Description: A sentence or two describing the service.
 +
 +
Under the Config tab you'll supply credential-related information pertinent to your MQTT broker:
 +
 +
* Broker Host: The host name or IP address of your MQTT broker.
 +
* Broker Port: Your MQTT broker port number
 +
* Client ID: A unique identifier should be supplied to the MQTT broker. Keep in mind your DreamFactory instance will serve as the sole client, even if multiple devices connect to the broker via the DreamFactory API.
 +
* Username: If your broker requires clients to authenticate, you'll supply the account username here.
 +
* Password: If your broker requires clients to authenticate, you'll supply the account password here.

Revision as of 17:50, 12 April 2018

DreamFactory v2.8.0 and greater includes support for MQTT (Message Queuing Telemetry Transport), a lightweight messaging protocol commonly used for exchanging information between servers and often resource limited physical devices commonly hosted in low bandwidth network environments. You can configure DreamFactory to provide a REST API which can both publish data to, and retrieve data from (subscribe), an MQTT broker.

Requirements

The service integration requires the [Mosquitto-PHP] PHP extension to be installed on your server. You'll also need to install the Mosquitto development headers. Operating system-specific instructions are provided at [https://mosquitto.org/download/]. If you're running Linux but don't know what operating system you're using, you can run the following command to learn more:


$ cat /etc/*release*
NAME="Amazon Linux AMI"
VERSION="2017.09"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2017.09"
PRETTY_NAME="Amazon Linux AMI 2017.09"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2017.09:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"
Amazon Linux AMI release 2017.09
cpe:/o:amazon:linux:2017.09:ga


This output indicates Red Hat Enterprise Linux is used, so after following the associated instructions on the aforementioned link the Mosquitto development headers using the following command:

$ sudo yum install libmosquitto-devel


Next you'll need to install the Mosquitto-PHP client. This is most easily accomplished with PECL however keep in mind the Mosquitto-PHP version may have changed:


$ sudo pecl7 install Mosquitto-0.4.0


Once installed you'll need to make PHP aware of the extension. This can be done in a few different ways and depends upon your specific PHP installation, however the easiest universal solution involves adding the following line to your php.ini file:


extension=mosquitto.so


With the extension in place, you'll need to restart the PHP service in order for the configuration changes to take effect.

Integrating MQTT Into DreamFactory

To integrate an MQTT broker into DreamFactory, login to the DreamFactory administration interface and navigate to Services > Create > Service Type > IoT > MQTT. You'll then configure the MQTT service much as you would any other, completing a series of form fields:

  • Name: The service name which will be included in the API URL.
  • Label: A friendly label with which the service will be identified inside the DreamFactory administration interface.
  • Description: A sentence or two describing the service.

Under the Config tab you'll supply credential-related information pertinent to your MQTT broker:

  • Broker Host: The host name or IP address of your MQTT broker.
  • Broker Port: Your MQTT broker port number
  • Client ID: A unique identifier should be supplied to the MQTT broker. Keep in mind your DreamFactory instance will serve as the sole client, even if multiple devices connect to the broker via the DreamFactory API.
  • Username: If your broker requires clients to authenticate, you'll supply the account username here.
  • Password: If your broker requires clients to authenticate, you'll supply the account password here.