Telit Cinterion IoT Developer Community
Paho project 1.1.0 - July 2016 - MQTT 3.1.1
Showcase, December 2, 2016 - 6:00pm, 13438 views
This showcase is a Java ME 3.2 example of the PAHO 1.1.0 project for sending MQTT 3.1.1 messages.
First, we send a typical "Hello World!" message followed, secondly by a JSON style "sensor message" with the module's PCB temperature.
MQTT is a lightweight wide-area comms protocol useful for M2M / IoT devices, that communicate via brokers, with their head-end systems or cloud services. https://www.eclipse.org/paho/clients/java/
This release is based on the July 2016 PAHO project code. Ported to Java ME 3.2 for the Thales IoT BGS5, EHSx, ELS61, and PLS62 modules - all sources are included in the ZIP file(s) below.
During 2018 the patched PAHO library sources were slightly "refactored" to avoid a naming conflict and a "Java error 137" on Thales IoT modules PLS62-W and ELS61 rel 2.
The distribution's .JAD file can be modified to take parameters such as broker, setAPN, setUser and setPass.
Please refer to Main.java to see what each of the does.
PAHO 1.1.0 - Getting Started Java SE sample code originally from here:
https://github.com/eclipse/paho.mqtt.java (for example source code, please see bottom of that page)
In the J2ME 3.2 port of the PAHO 1.1.0 MQTT 3.1.1 (from July 2016) there are 74 original PAHO classes
Of these we had to patch 25 of them:
14/10/2016 17:32 47,823 MqttAsyncClient.java
14/10/2016 15:06 21,711 MqttClient.java
14/10/2016 11:17 21,751 MqttConnectOptions.java
14/10/2016 17:38 8,745 MqttException.java
14/10/2016 11:44 10,503 MqttTopic.java
14/10/2016 11:45 2,577 TimerPingSender.java
14/10/2016 12:07 27,324 ClientComms.java
14/10/2016 14:02 57,903 ClientState.java
14/10/2016 14:03 15,907 CommsCallback.java
14/10/2016 14:04 5,080 CommsSender.java
14/10/2016 14:34 8,066 CommsTokenStore.java
14/10/2016 14:40 4,584 DisconnectedMessageBuffer.java
18/10/2016 09:04 2,095 ExceptionHelper.java
14/10/2016 15:22 3,328 FileLock.java
14/10/2016 15:17 3,582 LocalNetworkModule.java
18/10/2016 09:13 2,585 MessageCatalog.java
14/10/2016 14:58 3,121 ResourceBundleCatalog.java
14/10/2016 15:01 2,953 MqttOutputStream.java
14/10/2016 17:36 6,309 EmptyLogger.java
14/10/2016 17:24 8,184 JSR47Logger.java
14/10/2016 17:07 25,966 Logger.java
14/10/2016 17:15 6,170 LoggerFactory.java
14/10/2016 17:27 3,011 SimpleLogFormatter.java
14/10/2016 12:21 5,918 Debug.java
14/10/2016 11:42 5,649 Strings.java
See also (Java MQTT X-Nucleo) https://iot-developer.thalesgroup.com/showcase/cinterion-ehs6ehs8-concept-board-and-st-x-nucleo-iks01a1-shield-java-demo-mqtt
See also: Using the new JAT (Java AT command) extension interface. The demo shows how to use our Java MQTT client via AT^SJMQTT https://iot-developer.thalesgroup.com/showcase/command-mqtt-client
Netbeans 7.2 offline install: https://iot-developer.thalesgroup.com/tutorial/netbeans-72-offline-insta...
thanks for sharing! Connecting via tcp is working fine, unfortunately I cannot connect via tls. My guess is that I need to supply the brokers certificate. Is there a way to do this with this release?
edit: I was able to import the certificate but still cannot establish an encrypted connection. Most of the time I am getting a EOFException. I am guessing, that the socket gets closed either by the client or the server. Is there any way I can verify this?
This is only a basic demo. Also, ensure your module is using the latest firmware, for example EHSx modules need to be on at least "release 3 arn 51" firmware.
For a really good guide to using TLS security please see the related article for Amazon AWS and this MQTT library, here:
thank you very much for posting this sample, really helpful.
I am facing two issues. One i am not able to resolve dependancy for statement
in file org.eclipse.paho.client.mqttv3.internal.wire.MqttOutputStream.java
second, i am blocked on what API settings or Security settings to setup on application descriptor level for Java Me project in eclipse\netbeans.
I tried socketProtocol and http protocol and both are not liking when i pass tcp address as broker.
i will really appreciate any pointers\help
The BufferedOutputStream issue sounds like you have a too old or wrong Java SDK or Platform selected. Please read our Java Users Guide section 10 on the Java developer CDROM. Available from our extranet.
The API settings - please see this example and the .JAD file. I have enclosed an example where you can easily use the JAD file to select APNs and MQTT Broker info. Also discussed in the attached PDF file.
I do hope this helps.
Thanks so much for sharing! :)
I have a question though, I hope you can help me.
How can I change the MQTT topic and message? I've tried hardcoding it in the 'main.java' (changing the pubTopic and pubContent strings on lines 36 and 37), and then re-installing the MqttClient2016.jad MIDlet on the EHS6, but it seems to ignore my changes :S Any ideas about what I'm doing wrong?
Please see Main.java and this line:
String pubTopic = "testtopic"; // see http://www.mqtt-dashboard.com/
You would need to rebuild the JAD and JAR file, after making this change, with either Eclipse or Netbeans.
Thanks for the library and sample.
What to do to run this application at BGS5T. Do you plan to make this update?
(For BGS5T) I can succesfully run the Jar and Jad file(in dist file) manual(run AT^SJAM=1,"a:/MqttClient2016.jad",""<cr>).
When I try to debug source codes through Eclipse, I get the following error.
Exception in thread "Object Server Connection - Handle JMX Notification Thread" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
at java.util.ArrayList$Itr.next(Unknown Source)
at com.sun.jme.toolkit.remoting.client.rmiimpl.ObjectServerConnectionImpl$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
But I can succesfully debug when I try to debug it for the second time.
The current status for Debug is the same in run mode (I see it as successful when I run it 2 *****).
Please see the work we have been doing with Amazon AWS and ESEYE.
The here was to offer a virtually Zero Touch experience onboarding to AWS with ESEYE SIMs.
It will work on all PLS62-W rel 1, ELS61 rel 2 and EHSx rel 4 modules.
I am trying to include this MQTT library to my modem.
I tried using AT ^ SJMQTT modifying the .jad, installing and running, and the modem started to reboot constantly, so I had to freeze the execution and uninstall the application. I did the same with "MqttClient2016", it did not cause the module to restart, but it ends the execution a few seconds after starting it.
I have included the MqttClient2016.jar file as a library to my java midelt project. I make the connection with the example of the main class.
Imports did not give me a problem, but when executing the midlet, it throws me an exception in this line of code:
even removing the settings leaving it like this:
the exception is the following:
[Main]: MqttException system error:
msg [ResourceBundleCatalog.java] MqttException
loc [ResourceBundleCatalog.java] MqttException
cause java.lang.IllegalArgumentException: BearerType Invalid
exception [ResourceBundleCatalog.java] MqttException (0) - java.lang.IllegalArgumentException: BearerType Invalid
What could it be? I understand that it has to do with the parameters that I set in:
MqttClient sampleClient = new MqttClient (broker, clientId, persistence);
the broker contains the ip of my server: tcp: // ip: 1883
clientId the same as the main class, the device imei.
Thanks a lot.
I have an EHS6:
Good morning, sorry it was my mistake, I did not pass the parameters of the sim connection well. the user, password and apn. I already connect without problem.
Thanks for the contribution from the library!