Community discussions

MikroTik App
 
Chiara
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 72
Joined: Thu Jul 23, 2015 3:47 pm

MQTT Publish Script

Mon Oct 24, 2022 12:39 pm

Dear Sirs,
can you please tell me why this script run fine if copy/pasted in terminal while won't do anything if started from "Run Script" push button ?

Thanks, BR
# RouterOS v. 7.6
# Required packages: iot
:global currentIP;

:global newIP [/ip address get [find interface="ether1"] address];

:if ($newIP != $currentIP) do={
    :put "ip address $currentIP changed to $newIP";
    :set currentIP $newIP;
}

:global broker "MYBroker"
:global topic "devices/mk/news"
:global message 
:set $message
    "{\
        \"clientId\":\"$[/iot mqtt brokers get value-name=client-id \
            [/iot mqtt brokers find name=$broker]]\",\
"$currentIP" \
            }\
        }]\
    }"
:log info "$message";
:put ("[*] Total message size: $[:len $message] bytes")
:put ("[*] Sending message to MQTT broker...")
/iot mqtt publish broker=$broker topic=$topic message=$message
:put ("[*] Done")
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: MQTT Publish Script

Mon Oct 24, 2022 1:48 pm

2 [
3 ]

1 {
3 }

is one big mess...

Who is online

Users browsing this forum: GoogleOther [Bot], pandared and 16 guests