Hello,
I’m trying to create a script which automatically connects to a MQTT broker and sends a MQTT Publish. Connecting to broker works fine, but I have problem with MQTT Publish, where I don’t know how to enter the message itself. When the script executes the Publish command it result in Error, because if I understand it correctly, it requires input from user. Is it possible to somehow specify the message it should send inside a script? I’m a beginner so this might be a stupid question, but I’m a bit lost here.
Here’s the script for MQTT Publish:
/interface ppp-client at-chat ppp-out input=“AT”
:delay 1s
/interface ppp-client at-chat ppp-out input=“AT+QMTOPEN=0,"broker.emqx.io",1883”
:delay 3s
/interface ppp-client at-chat ppp-out input=“AT+QMTCONN=0,"mikrotikKNOT_1932003","",""”
:delay 1s
/interface ppp-client at-chat ppp-out input=“AT+QMTPUB=0,1,1,0,"testtopic","30"”
:delay 5s
/interface ppp-client at-chat ppp-out input=“AT+QMTDISC=0”
I also tried using a different approach through IoT - MQTT where I created broker, but when I tried connecting to it, it failed. Could it be because I’m using a SIM card which connects to a NB-IoT mobile network and whole configuration for it is done through /system serial-terminal port=modem channel=2 ? Command AT+QPING=1,“8.8.8.8” in serial-terminal works fine, but ping 8.8.8.8 outside of serial-terminal results in “no route to host”. When I entered the commands for MQTT manually in serial-terminal they worked fine:
Here are the commands I used:
AT+QMTOPEN=0,“broker.emqx.io”,1883
AT+QMTCONN=0,“mikrotikKNOT_1932003”,“”,“”
AT+QMTPUB=0,1,1,0,“testtopic”,30
test message
AT+QMTDISC=0
Here are the commands I used for connecting to MQTT broker through IoT - MQTT:
/iot mqtt brokers add name=“emqx” address=“broker.emqx.io” ssl=no client-id=“KNOT_193” auto-connect=no keep-alive=60
/iot mqtt connect broker=“emqx”
failure: Connection failed
Thanks for all of your help
