0

I want to setup a MQTT client on my Raspberry Pi. My goal is to first use my Pi to send a 'hello world' message to the Mosquitto broker I have set up on my Mac, and second, hook up my Pi to some sensors and send the data I collect to the same broker. I am currently considering the Paho javascript client: https://github.com/eclipse/paho.mqtt.javascript.

Now I am stuck trying to use maven to build and run the tests included in the Paho repository. When I ran mvn -e it produced these messages:

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for org.eclipse.paho:paho.javascript:pom:1.0.2
[WARNING] 'version' contains an expression but should be a constant. @ org.eclipse.paho:paho.javascript:${paho.version}, /home/pi/projects/paho.mqtt.javascript/pom.xml, line 7, column 11
[WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.codehaus.mojo:templating-maven-plugin @ org.eclipse.paho:paho.javascript:${paho.version}, /home/pi/projects/paho.mqtt.javascript/pom.xml, line 114, column 12
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building paho.javascript 1.0.2
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- minify-maven-plugin:1.7.4:minify (default-minify) @ paho.javascript ---
[WARNING] The source file [mqttws31.js] has the same name as the final file.
[INFO] Starting CSS task:
[INFO] Starting JavaScript task:
[INFO] Processing source file [mqttws31.js].
[INFO] Creating the merged file [mqttws31.js].
[INFO] Creating the minified file [mqttws31.min.js].
Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:200: WARNING - Parse error. invalid param name "ERROR.KEY"
     * @param {error} ERROR.KEY value above.
                      ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:737: WARNING - Parse error. Non-JSDoc comment has annotations. Did you mean to start it with '/**'?
    /*
    ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1667: WARNING - Parse error. invalid param name "connectOptions.timeout"
         * @param {number} connectOptions.timeout - If the connect has not succeeded within this 
                           ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1670: WARNING - Parse error. invalid param name "connectOptions.userName"
         * @param {string} connectOptions.userName - Authentication username for this connection.
                           ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1671: WARNING - Parse error. invalid param name "connectOptions.password"
         * @param {string} connectOptions.password - Authentication password for this connection.
                           ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1672: WARNING - Parse error. invalid param name "connectOptions.willMessage"
         * @param {Paho.MQTT.Message} connectOptions.willMessage - sent by the server when the client
                                      ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1674: WARNING - Parse error. invalid param name "connectOptions.keepAliveInterval"
         * @param {Number} connectOptions.keepAliveInterval - the server disconnects this client if
                           ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1677: WARNING - Parse error. invalid param name "connectOptions.cleanSession"
         * @param {boolean} connectOptions.cleanSession - if true(default) the client and server 
                            ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1679: WARNING - Parse error. invalid param name "connectOptions.useSSL"
         * @param {boolean} connectOptions.useSSL - if present and true, use an SSL Websocket connection.
                            ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1680: WARNING - Parse error. invalid param name "connectOptions.invocationContext"
         * @param {object} connectOptions.invocationContext - passed to the onSuccess callback or onFailure callback.
                           ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1811: WARNING - Parse error. invalid param name "subscribeOptions.qos"
         * @param {number} subscribeOptions.qos - the maiximum qos of any publications sent 
                           ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1813: WARNING - Parse error. invalid param name "subscribeOptions.invocationContext"
         * @param {object} subscribeOptions.invocationContext - passed to the onSuccess callback 
                           ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1828: WARNING - Parse error. invalid param name "subscribeOptions.timeout"
         * @param {number} subscribeOptions.timeout - which, if present, determines the number of
                           ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1859: WARNING - Parse error. invalid param name "unsubscribeOptions.invocationContext"
         * @param {object} unsubscribeOptions.invocationContext - passed to the onSuccess callback 
                           ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: mqttws31.js:1874: WARNING - Parse error. invalid param name "unsubscribeOptions.timeout"
         * @param {number} unsubscribeOptions.timeout - which, if present, determines the number of seconds
                           ^

Aug 15, 2016 5:25:42 AM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 0 error(s), 15 warning(s)
[INFO] Uncompressed size: 80699 bytes.
[INFO] Compressed size: 29283 bytes minified (7714 bytes gzipped).
[INFO] 
[INFO] 
[INFO] --- maven-antrun-plugin:1.3:run (generate-js-output) @ paho.javascript ---
[INFO] Executing tasks
     [copy] Copying 1 file to /home/pi/projects/paho.mqtt.javascript/target
   [delete] Deleting: /home/pi/projects/paho.mqtt.javascript/target/mqttws31-min-2.js
   [delete] Deleting: /home/pi/projects/paho.mqtt.javascript/target/mqttws31.min.js
[INFO] Executed tasks
[INFO] 
[INFO] --- exec-maven-plugin:1.2.1:exec (install-jsdoc-modules) @ paho.javascript ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.702 s
[INFO] Finished at: 2016-08-15T05:25:44+00:00
[INFO] Final Memory: 6M/16M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (install-jsdoc-modules) on project paho.javascript: Command execution failed. Cannot run program "npm" (in directory "/home/pi/projects/paho.mqtt.javascript"): error=2, No such file or directory -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (install-jsdoc-modules) on project paho.javascript: Command execution failed.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Command execution failed.
    at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:367)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
Caused by: java.io.IOException: Cannot run program "npm" (in directory "/home/pi/projects/paho.mqtt.javascript"): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at java.lang.Runtime.exec(Runtime.java:620)
    at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
    at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:254)
    at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:319)
    at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:610)
    at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:352)
    ... 22 more
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:248)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 29 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

My questions are how do I fix these errors and how can I use maven to build and run tests?

Additionally, Paho requires me to install maven and JDK. Are there any other lighter and easier MQTT clients suitable for Raspberry Pi?

varimax
  • 111
  • 1
  • 13

2 Answers2

1

Looks like you don't have npm installed

Caused by: java.io.IOException: Cannot run program "npm" (in directory "/home/pi/projects/paho.mqtt.javascript"): error=2, No such file or directory

Install node.js and npm

mvn and the JDK are just required to build the code from src. There are binary packages available that do not require the build re-preqs available from here

And a nearly full list of available clients can be found on the mqtt.org website here

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • Hooray that worked! but I still don't quite understand the point of running `mvn` and then `mvn test -Dtest.server=iot.eclipse.com -Dtest.server.port=80 -Dtest.server.path=/ws` as suggested by Paho's github page. Does the first command compile the tests and the second one run them? How does maven know which test to run since there are 7 or 8 javascript files in src/test? What is -Dtest.server.path? I am assuming it is where my mosquitto broker is? – varimax Aug 15 '16 at 07:36
  • `mvn` builds the code and documentation, `mvn test -Dtest.server=iot.eclipse.com -Dtest.server.port=80 -Dtest.server.path=/ws` runs all the tests against the iot.eclipse.com broker by starting a webserver on port `80` and the test index file is servered from `/ws` on that server – hardillb Aug 15 '16 at 07:55
-1

Regarding easier/simpler to use MQTT clients you may get away with using the mosquitto_pub and mosquitto_pub command line clients and script your logic around them. If this is a viable approach will of course completely depend on your use case. In any case these tools are great for ad-hoc testing purposes.