ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Communication / MQTT functions
  • Properties specific to mqttSession variables
  • Authentication mode
  • Functions that use mqttSession variables
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
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.
Note: For more details on the declaration of this type of variable and the use of WLanguage properties, see Declaring a variable.
Example
// Déclaration de la connexion MQTT
gMqttSession is mqttSession

// Récupère les données saisies dans la fenêtre de connexion
gMqttSession.Address = SAI_Adresse_Broker
gMqttSession.Port = SAI_Port
gMqttSession.Option = INT_SSL
gMqttSession.ConnectionTimeout = SAI_Timeout_Connexion
gMqttSession.User = SAI_Login
gMqttSession.UserPassword = SAI_PSW
gMqttSession.PrivateKey = SAI_Clé_Privée
gMqttSession.PrivateKeyPassword = SAI_PSW_Clé_Privée
gMqttSession.ClientID = SAI_IDClient
gMqttSession.CleanSession = INT_Session_Vierge
IF MQTTConnect(gMqttSession) THEN
	Message("Connexion OK")
ELSE
	Error("Problème de connexion. '" + ErrorInfo() + "')")
END
Properties

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 specified as follows:
  • 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:
  • mqttIgnoreCertificateExpired: Certificate date is ignored.
  • mqttIgnoreCertificatInvalide: The certificate is ignored.
  • mqttIgnoreNomCertificatInvalide: The name of the site in the certificate is ignored.
  • mqttIgnoreRevocation: 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 set, authentication by key is performed: only the properties User, PrivateKey and PrivateKeyPassword are taken into account..
PrivateKeyPasswordCharacter stringPassword of the key file (for a private-key based authentication). The PrivateKey property corresponds to the private key to be used.
UserCharacter stringUsername.
UserPasswordCharacter stringUser password (the User property corresponds to the user's name).
Remarks

Authentication mode

Key-based authentication takes precedence over password-based authentication.
Key-based authentication is used if:
  • the server supports this authentication mode.
  • the PrivateKey property is specified.
Password-based authentication is used if:
  • the server supports this authentication mode.
  • property UserPassword is set.

Functions that use mqttSession variables

The following functions use 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: 09/20/2024

Send a report | Local help