为啥程序发送出去的mqtt消息没有相应,我手动用工具模拟发出的又有相应?

bobshipwood

我是用workerman的mqtt和laravel发送的,请问publish的内容是不是2进制的?

protected function sendBinary($device, $start, $registerNum, $byteNum)
    {
        $str = $device->address . $device->deviceModel->read_code . $start . $registerNum;
        $data = strToBinary($str); // 字符串转2进制
        $crc = calculateModbusCRC($data); // 算出modbus rtu的crc码
        $binaryData = hex2bin($str.$crc);  // 将16进制字符串转换为二进制数据
        $this->mqttClient->publish('/whd1/network/test/r/1234', $binaryData);
    }
47 0 0
0个回答

×
🔝