Closed NicolSpies closed 8 years ago
Hi @NicolSpies, could you attach your configuration file and the mqtt-spy logs?
Hi Kamil, this problem relates to #99 as I am trying to accomplish the same. The solution in #99 is actually better suited as I need to do it for all the subscribed topics, hundreds of them. It will however be great to link an external .js file similar as what is done for the individual subscriptions.
I will attach the files when I get back to that test platform. Thanks
@NicolSpies, have you now got the onMessage being called properly or still not? I'm asking because I've seen the other issues you raised where it seems it is fine. Please advise.
@kamilfb, I have tried the onMessage and could not get it working, hence I tried the formatter as a workaround.
@NicolSpies, I see. I will need your config and logs to help further though...
I appreciate your help, to make it simple I will quickly create a fresh log with the javascript referenced in a subscription. Thanks
The clean log file is: mqtt-spy.txt
The absolute path of the javascript file containing the onMessage function is : C:\Program Files (x86)\MQTTSpy\scripts\subscriptions\message.js
The onMessage function is as detailed in the first entry of this issue
Rest of the config files
The received JSON message payload:
{"type":"test","name":"Oos-Moot","cfg3":{"monthly":{"monthly":0,"time":"2016-08-15T23:00:00Z","deltp":0},"daily":{"daily":0,"time":"2016-08-15T23:00:00Z","deltp":0},"weekly":{"time":"2016-08-15T23:00:00Z","weekly":0,"deltp":0},"hourly":{"hourly":0,"time":"null","deltp":0}},"customer":"Oasis","time":"2016-08-15T23:51:11Z"}
and the messages log indicating that the onMessage did not modify the message payload: log1messages.txt
I'd recommend deleting the following from the config:
<BackgroundScript autoStart="false" repeat="false">
<File>put your script location here...</File>
</BackgroundScript>
I have tried it, still the same, the message in the log still the same with no modifications as expected
Yay - I was able to reproduce it. Indeed, the payload in the log doesn't get modified. Also, the "All" tab doesn't get updated with the modified payload either. However, the specific subscription tab has payloads with the modified value! Clearly a bug :)
I have closed mqtt spy and reopened, get the error that the configuration file cannot be processed. mqtt-spy - Copy (2).txt
@NicolSpies, delete the whole BackgroundScript
tag
Thanks, it is running again
@NicolSpies, I will start working on a fix for setting the payload... - thanks for reporting it!
Thank you for all your effort and an excellent product
Could you try the latest beta? http://tinyurl.com/mqtt-spy-download/mqtt-spy-0.6.0-beta-b52-jar-with-dependencies.jar
Will gladly do
Hi Kamil, from the testing so far, the onMessage method not triggers correctly and the script linked is executed. Using a script the JSON payload is converted to XML wrapped in CDATA tags which I remove using post processing. Thank you
@NicolSpies - thank you for confirming it's fine now! Cheers
Hi, @kamilfb, thank you for an excellent tool which I am starting to explore. The message payloads I receive is in JSON and I need to reformat it to XML before it is saved in the log1.messages file. I have started by trying to get the example in the ScriptingSubscriptions Wiki to run.
I have saved the example javascript
function onMessage() { receivedMessage.setPayload("<tag>" + receivedMessage.getPayload() + "- modified :)</tag>"); return true; }
in a file message.js in the MQTTSpy directory and entered the file name in the script column of the subscriptions tab of the topic of my connection. I saved, closed and re-opened the connection.
I am expecting the payload message to be modified in the browser and the log1.messages file. When a message is received it nothing appears to happen and the json payload is unchanged. I am using version 0.52.
What am I doing wrong, please point me in the right direction. Regards