publishMessage = async (topic, message) => {
  return new Promise((resolve, reject) => {
    device.publish(
      topic,
      message ? JSON.stringify(message) : '{}',
      {
        qos: 1, // Quality of Service level. This gives the message prioirty.
      },
      (error) => {
        if (error) {
          console.error(
            `Failed to publish message to AWS IoT: ${error.message}`,
          )
          reject(error)
        } else {
          console.log('Message successfully published to AWS IoT topic:')
          console.log(topic)
          resolve(message)
        }
      },
    )
  })
}
Publishes a message to a specified topic on AWS IoT.

This function sends a message to a given topic using AWS IoT's publish method. It wraps the publish action in a Promise
to handle asynchronous execution. The message is serialized to JSON format before sending.

@async
@param {string} topic - The topic to which the message will be published.
@param {Object} message - The message payload to be published. The payload is converted to a JSON string before publishing.
@returns {Promise<Object>} A promise that resolves with the message payload if the message is successfully published,
or rejects with an error if the publication fails.
@throws Will log an error to the console and reject the promise if publishing the message fails.