ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / MQTT functions
  • Properties specific to mqttSession variables
  • Authentication mode
  • Functions that use mqttSession variables
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
mqttSession (Variable type)
In french: mqttSession
The mqttSession type is used to define the parameters for connecting to the MQTT broker. These connection parameters can be defined and changed by several WLanguage properties.
Remark: For more details on the declaration of this type of variable and the use of WLanguage properties, see Declaring a variable.
Example
// Declare the MQTT connection
gMqttSession is mqttSession

// Retrieve the data typed in the connection window
gMqttSession.Address = EDT_Broker_Address
gMqttSession.Port = EDT_Port
gMqttSession.Option = CBOX_SSL
gMqttSession.ConnectionTimeout = EDT_Connection_Timeout
gMqttSession.User = EDT_Login
gMqttSession.UserPassword = EDT_PSW
gMqttSession.PrivateKey = EDT_Private_Key
gMqttSession.PrivateKeyPassword = EDT_Private_Key_PSW
gMqttSession.ClientID = EDT_ClientID
gMqttSession.CleanSession = CBOX_Clean_Session
IF MQTTConnect(gMqttSession) THEN
	Message("Connection OK")
ELSE
	Error("Connection problem. '" + ErrorInfo() + "')")
END
Remarks

Properties specific to mqttSession variables

The following properties can be used to handle a MQTT session:
Property nameType usedEffect
AddressCharacter stringAddress of MQTT server (also called "MQTT broker"). This address can be given in the following format:
  • IP address in XXX.XXX.XXX.XXX format (125.5.110.100 for example).
  • IP address containing the server name (MQTTServer for example). This syntax is recommended.
CleanSessionBoolean
  • True to clean the generic global parameters on the server,
  • False otherwise.
ClientIDCharacter stringClient identifier. This property must not be left empty.
ConnectionTimeoutInteger or DurationConnection timeout in seconds. This property can correspond to:
  • an integer corresponding to the number of seconds,
  • a Duration variable,
  • the duration in a readable format (e.g., 10 s).
IgnoreErrorInteger constantSpecifies the ignored errors. Corresponds to a constant or to a combination of constants:
  • mqttIgnoreExpiredCertificate: The certificate date is ignored.
  • mqttIgnoreInvalidCertificate: The certificate is ignored.
  • mqttIgnoreInvalidCertificateName: The site name specified in the certificate is ignored.
  • mqttIgnoreRevocation: The certificate revocation is ignored.
OptionInteger constantConnection options. This property can correspond to the optionSSL constant for an SSL connection.
PortIntegerPort of MQTT server. This port correspondsn to 1883 by default (or 8883 for an SSL connection).
PrivateKeyCharacter string or Certificate variableName of the Certificate variable or path of the pem file (to make a private key connection).
If this property is specified, an authentication by key is performed: only the User, PrivateKey and PrivateKeyPassword properties are taken into account.
PrivateKeyPasswordCharacter stringPassword of key file (for a connection by private key). The PrivateKey property corresponds to the private key to be used.
UserCharacter stringUsername.
UserPasswordCharacter stringUser's password used in password authentication (the User property is the user's name).

Authentication mode

The authentication by key has priority over the authentication by password.
Key authentication is used if:
  • the server supports this authentication mode.
  • the PrivateKey property is specified.
Password authentication is used if:
  • the server supports this authentication mode.
  • the UserPassword is specified.

Functions that use mqttSession variables

The following functions are used to handle mqttSession variables:
MQTTConnectUsed to connect to a MQTT server (also called "Broker").
MQTTDisconnectAllows you to disconnect from a MQTT server (also called "Broker").
MQTTPublishPublishes a message on the MQTT broker.
MQTTSubscribeUsed to subscribe to a MQTT notification.
MQTTUnsubscribeUsed to unsubscribe from a MQTT notification.
MQTTUnsubscribeAllAllows you to unsubscribe from all the existing subscriptions.
See also
Minimum version required
  • Version 22
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 04/16/2024

Send a report | Local help