无法通过WSS与MQTT连接到SAP Server

时间:2017-05-16 13:27:10

标签: node.js websocket sap mqtt iot

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

我正在使用p12客户端证书。

但它仍然停留在握手之后(参见Wireshark图片)。

wireshark 10.XX.XX.XXX是我的IP

155.XX.XX.XXX是SAP IP

30秒后我收到此错误: output 他试图再次联系。

这是来源:

function xmlToArray($xml){
    $xml = str_replace(array("\n", "\r", "\t"), '', $xml);
    // $xml = trim(str_replace('"', "'", $xml));
    $xml = trim($xml);
    $start_tree = (array) simplexml_load_string($xml);

    $final_tree = array();
    loopRecursivelyForAttributes($start_tree, $final_tree);
    return $final_tree;
}

function loopRecursivelyForAttributes($start_tree, &$final_tree){
    foreach($start_tree as $key1 => $row1){
        if(!array_key_exists($key1, $final_tree)){
            $final_tree[$key1] = array();
        }

        // If there is only one sub node, then there will be one less
        // array - ie: $row1 will be an array which has an '@attributes' key
        if(array_key_exists('@attributes', $row1)){
            $row1 = (array) $row1;
            getValues($start_tree, $final_tree, $key1, $row1);
        }
        else{
            foreach ($row1 as $row2){
                $row2 = (array) $row2;
                getValues($start_tree, $final_tree, $key1, $row2);
            }
        }
    }
}

function getValues($start_tree, &$final_tree, $key1, $row2){
    foreach ($row2 as $key3 => $val3){
        $val3 = (array) $val3;

        if($key3 == '@attributes'){
            $final_tree[$key1][] = $val3;
        }
        else{
            $temp_parent = array();
            $temp_parent[$key3] = $val3;
            loopRecursivelyForAttributes($temp_parent, $final_tree[$key1][count($final_tree[$key1]) - 1]);
        }
    }
}

//usage
$xml = xmlToArray('xml as string');

1 个答案:

答案 0 :(得分:0)

我已经通过将“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()
  }
}