Gemalto is now part of the Thales Group, find out more.

You are here

Paho project 1.1.0 - July 2016 - MQTT 3.1.1

Showcase, December 2, 2016 - 6:00pm, 4296 views

Summary
This showcase is a Java ME 3.2 example of the Paho 1.1.0 project for sending MQTT 3.1.1 messages.

https://www.eclipse.org/paho/clients/java/

MQTT is a light weight wide area comms protocol useful for M2M / IoT device communications with headend systems / cloud services and brokers.

.

This release is based on the July 2016 Paho project code. Ported to Java ME 3.2 for the EHSx modules in the ZIP file below. 

These patched PAHO library sources have been refactored slightly to avoid a naming conflict and Java error 137 on some newer Gemalto module platforms such as PLS62-W, ELS61 rel 2 and EHSx rel 4.

The .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 (see bottom of that page for example source code.)

.

Ported to Java ME 3.2 for the EHSx modules in the ZIP file below.

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

-- end

d

web sockets client

See also (Java MQTT X-Nucleo) https://developer.gemalto.com/showcase/cinterion-ehs6ehs8-concept-board-and-st-x-nucleo-iks01a1-shield-java-demo-mqtt

See also: Using the new JAT (Java AT command) extention interface here.

The demo shows how to use our Java MQTT client via AT^SJMQTT :)

https://developer.gemalto.com/showcase/command-mqtt-client

cido_felix's picture
cido_felix

Hello,

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? 

mullengers's picture
mullengers

Hi,

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:

https://developer.gemalto.com/showcase/concept-board-connection-amazon-a...

Best regards

Simon

mangatrai's picture
mangatrai

Hello Simon,

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

import com.sun.midp.io.BufferedOutputStream;

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

mullengers's picture
mullengers

Hello mangatrai

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.

silvia's picture
silvia

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?

Thanks dude!

mullengers's picture
mullengers

Hello,

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.

Best regards

Simon

okanakbay's picture
okanakbay

Hello,

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 times).

mullengers