We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I want to connect aws iot core like as mqtt client. But i don't know how config the tlsoptions, could anyone meet the same issue?
the source code is bellow:
` // MQTT 客户端选项 const options = { clientId: 'mqtt-client-' + (Math.floor((Math.random() * 100000) + 1)), reconnectPeriod: 30 * 1000, qos: 2, enableSsl: true, tls:{ caDer: this.fetchCaDer(), cert: this.fetchCert(), key: this.fetchPrivateKey(),
} }; const client = new Mqtt.Client("mqtt://xxx.iot.us-west-1.amazonaws.com:8883"); client.connect(options, err => { console.log("GrillUtils connect err = " + err.toString()) console.log("GrillUtils connect err = " + JSON.stringify(err)) }); client.on(Mqtt.Event.Message, (topic, message) => { console.log('Mqtt Message:', topic, message.toString()); console.log("GrillUtils message topic = " + topic + " data = " + data) this.subscribeState = true this.connected = true; this.selfCheck(CheckStatus.FOM_HEART_BEAT); if (data.value.hasOwnProperty("result")) { this.convertResultTopic(data); } else if (data.value.hasOwnProperty("heat")) { this.convertHeartbeatTopic(data); } else { //don't care other heartbeat data. this.convertSubscribeTopic(data) } }); client.on(Mqtt.Event.Connect, () => { console.log('MQTT Connect'); console.log("GrillUtils connect ") client.subscribe('heartbeat/' + this.grillID, (err) => { if (err) { console.log('Error subscribing to topic:', err); } else { console.log('Subscribed to topic'); } }); // 订阅主题 client.subscribe('result/' + this.grillID) client.subscribe('command/' + this.grillID) }); client.on(Mqtt.Event.Error, (error: string) => { console.log('MQTT Error:', error); }); client.on(Mqtt.Event.Disconnect, (cause: string) => { console.log('MQTT Disconnect:', cause); });
///tlsoptions fetchCaDer(){ const startLabel = "-----BEGIN CERTIFICATE-----"; const endLabel ="-----END CERTIFICATE-----" return ${startLabel} MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF ... ${endLabel} }
${startLabel} MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF ... ${endLabel}
fetchCert(){ const startLabel = "-----BEGIN CERTIFICATE-----"; const endLabel ="-----END CERTIFICATE-----" return ${startLabel} MIIDWjCCAkKgAwIBAgIVAKYgDNHgFHvnaJJhb9d0DmqOd0KwMA0GCSqGSIb3DQEB ... ${endLabel}
${startLabel} MIIDWjCCAkKgAwIBAgIVAKYgDNHgFHvnaJJhb9d0DmqOd0KwMA0GCSqGSIb3DQEB ... ${endLabel}
}
fetchPrivateKey(){ const startLabel = "-----BEGIN RSA PRIVATE KEY-----"; const endLabel ="-----END RSA PRIVATE KEY-----" return ${startLabel} MIIEowIBAAKCAQEAtTA7FQ2Yopw3aQ3w0EBzQj0nmERQGW5FYRTsSlEBBijx9/ge ... Ew18DGPwHBLDhC9FrlHAcXsLOrESj6V+WCshz45nLbe2E+3T9MB0 ${endLabel} } `
${startLabel} MIIEowIBAAKCAQEAtTA7FQ2Yopw3aQ3w0EBzQj0nmERQGW5FYRTsSlEBBijx9/ge ... Ew18DGPwHBLDhC9FrlHAcXsLOrESj6V+WCshz45nLbe2E+3T9MB0 ${endLabel}
The text was updated successfully, but these errors were encountered:
I got the error from console GrillUtils connect err = Error: mqtt://xxxx.iot.us-west-1.amazonaws.com/mqtt:8883
GrillUtils connect err = Error: mqtt://xxxx.iot.us-west-1.amazonaws.com/mqtt:8883
Sorry, something went wrong.
use tcp to replace mqtt, use ssl to replace mqtts, new Mqtt.Client('ssl://domain.com:port')
tcp
mqtt
ssl
mqtts
new Mqtt.Client('ssl://domain.com:port')
No branches or pull requests
I want to connect aws iot core like as mqtt client. But i don't know how config the tlsoptions, could anyone meet the same issue?
the source code is bellow:
` // MQTT 客户端选项
const options = {
clientId: 'mqtt-client-' + (Math.floor((Math.random() * 100000) + 1)),
reconnectPeriod: 30 * 1000,
qos: 2,
enableSsl: true,
tls:{
caDer: this.fetchCaDer(),
cert: this.fetchCert(),
key: this.fetchPrivateKey(),
///tlsoptions
fetchCaDer(){
const startLabel = "-----BEGIN CERTIFICATE-----";
const endLabel ="-----END CERTIFICATE-----"
return
${startLabel} MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF ... ${endLabel}
}
fetchCert(){
const startLabel = "-----BEGIN CERTIFICATE-----";
const endLabel ="-----END CERTIFICATE-----"
return
${startLabel} MIIDWjCCAkKgAwIBAgIVAKYgDNHgFHvnaJJhb9d0DmqOd0KwMA0GCSqGSIb3DQEB ... ${endLabel}
}
fetchPrivateKey(){
const startLabel = "-----BEGIN RSA PRIVATE KEY-----";
const endLabel ="-----END RSA PRIVATE KEY-----"
return
${startLabel} MIIEowIBAAKCAQEAtTA7FQ2Yopw3aQ3w0EBzQj0nmERQGW5FYRTsSlEBBijx9/ge ... Ew18DGPwHBLDhC9FrlHAcXsLOrESj6V+WCshz45nLbe2E+3T9MB0 ${endLabel}
}
`
The text was updated successfully, but these errors were encountered: