FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

14455 questions

17168 answers

28195 comments

0 members

We are migrating to our new platform at https://community.teltonika.lt. Moving forward, you can continue discussions on this new platform. This current platform will be temporarily maintained for reference purposes.
0 votes
362 views 5 comments
by anonymous
Hello,

I would like to use the I/O juggler (digital input raising edge) action to trigger a MQTT publish. Can this be done with a simple shell script? Appreciate if someone could point me in the right direction.

Thank you, MF
by anonymous
Mark, did you ever get an answer on this? I have the same issue.

My script is:

/usr/bin/logger "MQTT Script Initiated"
mosquitto_pub -h localhost -p 1883 -t router/get -m uptime
/usr/bin/logger "MQTT Script Completed"

I get the first and last lines showing up in the logger. However the mosquitto line does not work. It does work if I simply type that line into an SSH session
by anonymous
Hi Graybricks

I followed the answer below and after some mucking around managed to get the DI raising edge to trigger and MQTT publish.

Regards

Mark
by anonymous
Mark,

Thanks for replying. It's the "mucking around" I'm interested in. What magic did you have to do in your script to get mosquitto_pub to start working? I've done my homework here, I have read the below, but can't get it. You can DM me if you don't want to broadcast the answer.
by anonymous
Well, figured out that if I make the script with notepad++, it doesn't work. If I go into WinSCP, open the script file on the modem, and edit it there, save it, the script works fine. Thanks.

1 Answer

0 votes
by anonymous

Hello,

You can find some useful information on MQTT in this wiki page.

Aside from that, You would indeed need a script to implement such a configuration.

The necessary steps to in perform include:

  • Configuring Script type action in Services -> Input/Output -> I/O juggler;
  • Configuring an instance execute the action on rising edge during input state change;
  • Downloading MQTT package from Package manager;
  • Configuring MQTT Broker and Publisher in Services -> MQTT section;
  • Loging to the router using SSH and downloading mosquitto_pub using the following commands: 
    • opkg update
    • opkg install mosquitto-client-nossl
  • Finally, the script should execute the command similar to the one below:
    •  mosquitto_pub -h 192.168.1.1 -p 1883 -u <user_name> -P <password> -t router/get -m <data_to_publish>

Best regards,

by anonymous

Thanks, they is good step by step instructions, however I have stumbled on a few problems detailed here: mqtt_publish_from_IOjuggler_details

Thank you for your assistance, very much appreciate it.