Publishing MQTT messages from serial commands

I am using the BG95 modem and MQTT protocol to publish messages to a broker server. I have no problem publishing using the Qcom tool, but I need to publish using only serial commands and no physical pressing of Control+Z. Does anyone know how this can be done?

I have tried to send:
Serial2.write(“AT+QMTPUBEX=1,0,0,0,“motorbeta”\r\n”);
Serial2.write(“test”);
Serial2.write((char)26);

which should be attempting replicate what the Qcom tool is doing, but I just get “ERROR”.

That syntax doesn’t look right to me. Maybe instead:

Serial2.write(char(26));