I'm trying to connect to a MQTT broker over TLS in react-native with MQTT.js . Based on the doc I tried this code:
const options = {
port: PORT,
host: HOST,
protocol: 'mqtts',
secureProtocol: 'TLS_method',
username: USERNAME,
password: PASSWORD,
ca: CA_FILE
}
const client = mqtt.connect(options);
client.on('error', (error) => {
console.log("error", error);
});
client.on('connect', () => {
console.log("connected");
});
The options object will be passed through tls.connect()
, so I specified the certificate file.
The connection doesn't return an error, but the client is not connected. What did I do wrong?
Try to use that fork of React native MQTT https://github.com/FrozenPyrozen/rn-native-mqtt it worked with TLS connection on Android and IOS
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.