【问题标题】:Can't connect to SAP Server with MQTT over WSS无法使用 MQTT over WSS 连接到 SAP 服务器
【发布时间】:2017-05-16 13:27:09
【问题描述】:

我在 3 天后尝试通过 WSS 连接到 SAP MQTT (wss://iotmmsXXXXXXXXX.hana.ondemand.com/com.sap.iotservices.mms/v1/api/ws/mqtt)。

我使用的是 p12 客户端证书。

但它会卡在握手之后/之后(参见 Wireshark 图片)。

10.XX.XX.XXX是我的IP

155.XX.XX.XXX 是 SAP IP

30 秒后我收到此错误: 然后他尝试再次连接。

这里是来源:

const fs = require('fs');
const mqtt = require('mqtt');

// Parts of URL and Path
const hcp_account_id = 'WWWWWWWWW';
const hcp_landscape_host = '.hana.ondemand.com' // this is used on PROD with Client Certificate Authentication
const my_endpoint_url_path = '/com.sap.iotservices.mms/v1/api/ws/mqtt';

//Certificate
const client_p12 = "./YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY.p12";

// the following values need to be taken from the IoT Cockpit
const device_id = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
const message_type_id_From_device = 'ZZZZZZZZZZZZZZZZZZZZ';

// for down- upstream communication
var my_publish_topic = "iot/data/" + device_id;
var my_subscription_topic = "iot/push/" + device_id;

var my_endpoint = "iotmms" + hcp_account_id + hcp_landscape_host;

var wsoptions =
    {
        host: my_endpoint,
        port: 443,
        pfx: fs.readFileSync(client_p12),
        passphrase: 'AAAAA',
        checkServerIdentity: false,
        protocol: 'mqttv3.1',
        protocolVersion: 13,
        perMessageDeflate: true,
        client_max_window_bits: true
    }

var options =
    {
        wsOptions: wsoptions,
        clientId: device_id,
        protocolId: 'MQIsdp',
        protocolVersion: 3,
        protocol: 'wss',
        hostname: my_endpoint,
        port: 443,
        path: my_endpoint_url_path
    }

const mqttc = mqtt.connect(options);

mqttc.subscribe(my_subscription_topic, 0);

mqttc.on('connect', () => console.log('connected!'));

mqttc.on('error', (msg) => console.log('error: ' + msg));

mqttc.on('offline', (msg) => console.log('offline: ' + msg));

mqttc.on('close', (msg) => console.log('close: ' + msg));

// message is Buffer
mqttc.on('message', (topic, message) => console.log('message(' + topic + '): ' + message.toString()));

【问题讨论】:

    标签: node.js websocket sap mqtt iot


    【解决方案1】:

    我已将“mqtt/lib/client.js”中的“sendPacket”方法更改为

    function sendPacket (client, packet, cb) {
      client.emit('packetsend', packet)
      var result = false
      try {
        var buf = mqttPacket.generate(packet)
        result = client.stream.write(buf)
      } catch (err){
        client.emit('error', err)
        result = false
      }
      if (!result && cb) {
        client.stream.once('drain', cb)
      } else if (cb) {
        cb()
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-22
      • 1970-01-01
      • 2021-05-01
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      相关资源
      最近更新 更多