constmqtt=require('mqtt')constfs=require('fs')constpath=require('path')constKEY=fs.readFileSync(path.join(__dirname,'/private.pem.key'))constCERT=fs.readFileSync(path.join(__dirname,'/certificate.pem.crt'))constTRUSTED_CA_LIST=fs.readFileSync(path.join(__dirname,'/AmazonRootCA1.pem'))constPORT=8883constHOST='mqttssl.xplatform.tranx.io'consttopic="XHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/XXXXX"constoptions= { port:PORT, host:HOST, key:KEY, cert:CERT, rejectUnauthorized:true,// The CA list will be used to determine if server is authorized ca:TRUSTED_CA_LIST, protocol:'mqtts'}constclient=mqtt.connect(options)let data =JSON.stringify({PowerUsage:0, Temperature:0, Motor:0, DutyManager:'John Doe'})client.publish(topic, data)client.on('connect',function () {console.log('Connected')})```