Functions Description
SetCredentials(mqtt_username,mqtt_password)
This function allows the user to set the username and password designated for that topic or mqtt URL
setCredentials('iot_1234','123456')
The above function .call has an example username and password.Using this function, you can set the designated username and password for your asset inside a project.(The username and password can be seen under the settings tab inside a project).'
DebugMode(condition)
This function is used to enable or disable all the print statement present inside the code; it accepts only Boolean variables (true/false)
debugMode(true)
Return Type: none
The above function call passes true as an argument, which will enable all the debug statements (print statements) in the code. If passing false as an argument the debug statements (print statements) will be disabled and only the normal code function as usual.
SetTopic(mqtt_topic)
This function assigns mqtt topic with the function argument value.
setTopic('a/IIOT_demo_12345')
Return Type: none
The above function calls a specific topic, this will assign the topic to the local variable inside the library.
AddParameter(key,value)
This function appends the data to be sent via mqtt in a key,value pair.
addParameter('temperature', 32.21)
Return Type: none
The above function is used to append data in the key value pair format onto a dictionary variable. This variable will be later used inside the publish function to send the appended data.
InitWifi();
This function is used to initialize Wi-Fi
initWifi()
The above example initializes the Wi-Fi connection and display the status of connection in serial monitor.
InitMqtt()
This function is used to initialize mqtt, it sets the username and password as per the information given by user. It also initializes callback functions like on_connect, on_message, on_disconnect.
initMqtt()
This function has no argument required but has significant importance in establishing a connection with MQTT. This is the function where an object is created for the mqtt client, and also initializes all the required callback function mentioned above. Several other function of this function is to set username and password given by user, and established a connection with the mqtt server then starts the mqtt loop. Returns none.
Publish()
This function publishes the set message to the set mqtt server, port, username, and password.
publish()
Return Type: none
This function has no arguments. This function will first check for connected_flag, only then it starts to send message to the designated mqtt server on a specific topic. The data will be taken from the dictionary variable to which that data has been appended in the addParameter() function, Once the data is sent, it will clear the variable and wait for any other new parameters to be added. Returns none.
Debug_statements(message)
This function is used to print messages as per users input to the argument.
debug_statements('Connection established with MQTT Broker')
Return Type: none
The above function call passes an argument of a message to be printed in terminal.
GetLastPublishTime()
To get last, publish time this function can be used.
getLastPublishTime()
Return Type: last published time.
This function doesn't need any input arguments thus, this function doesn’t have any input arguments.
GetLastDisconnectTime()
To get the last disconnect time of the device from the MQTT broker this function is used.
getLastDisconnectTime()
Return Type: last disconnected time.
To display previous, disconnected time there is no need of any input arguments thus, this function doesn’t have any input arguments, with this function we can publish last publish time.
GetTopic()
To get the topic of the project use this command.
getTopic()
Return Type: mqtt topic.
The function returns the topic of the project which is a string. There is no need for any input arguments.
GetMacId()
This command displays Media Access Control (MAC Address) of the device.
getMacId()
Return Type: MacId.
The command returns with string of MAC ID of the project. There is no need for any input arguments thus, this function doesn’t have any input arguments.
GetCredentials()
This command displays username and password.
getCredentials()
Return Type: username and password.
To display input credentials there is no need of any input arguments thus, this function doesn’t have any input arguments. The command returns with string with credentials of the project.
GetLastReceiveTime()
To get the last received time of device from the MQTT broker this function is used.
getLastReceiveTime()
Return Type: last received time.
The command returns with string of credentials of the project. To display last received time there no need of any input arguments thus, this function doesn’t have any input arguments.
GetToken()
This command displays only token/password.
getToken()
Return Type: token (password).
To display input password there is no need of any input arguments thus, this function doesn’t have any input arguments. The command returns with string with credentials of the project.
GetConfigs()
This command gets configuration data of username, password, and topic.
getConfigs()
Return Type: username,password,topic(Json format).
The command returns with Jason type data.To display existing configuration data there is no need of any input arguments thus, this function doesn’t have any input arguments.
GetProjectName()
This command displays project name.
getProjectName()
Return Type: project name.
To display project name there is no need of any input arguments thus, this function doesn’t have any input arguments. The command returns with string type data project.
GetProjectId()
This command displays project ID.
getProjectId():
The command returns with string type data project. To display project ID there is no need of any input arguments thus, this function doesn’t have any input arguments.