kamilfb / mqtt-spy

Please use the new Eclipse Paho GitHub repo instead.
https://github.com/eclipse/paho.mqtt-spy/wiki
346 stars 68 forks source link

Documentation: Scripting Subscriptions #94

Closed ddeletic closed 8 years ago

ddeletic commented 8 years ago

The Subscriptions Scripting page could be expanded with more details. A couple of issues I came across so far are:

kamilfb commented 8 years ago

@ddeletic, I've updated the wikis to address your first point: https://github.com/kamilfb/mqtt-spy/wiki/Scripting & https://github.com/kamilfb/mqtt-spy/wiki/ScriptingSubscriptions

kamilfb commented 8 years ago

@ddeletic, for your second point - could you explain your use case further? What would you use this continuously running script for?

ddeletic commented 8 years ago

Thank you for the quick response.

As for the second point, I'm trying to write a script that would transfer a file to the remote device in several chunks. The idea is for the script to publish a chunk, wait for an acknowledgement from the device, send the next chunk and so on. The script would subscribe to ACK topic and run onMessage() on each acknowledgement, until the file transfer is complete.

I think I have a workaround: At the end of my onMessage() fuction I just re-subscribe to the same topic. It is not elegant, nor it is efficient, but it seems to work - it keeps the script running.

kamilfb commented 8 years ago

@ddeletic, you could possibly run a normal script (from Scripted publications), that would subscribe to the topic you want, and then in a loop keep checking if there are any new messages. Possibly something like this: https://github.com/kamilfb/mqtt-spy/blob/development/mqtt-spy/src/test/resources/test_cases/test1/tc.js (although the example is a test case, not an ordinary script).