Community
Participate
Working Groups
Created attachment 236692 [details] MQTT Client for Java ME + Demo App Finally I have found some time to work on the MQTT client for the Java ME. In my implementation I have been using the recent version of Paho Java SE MQTT client and the changes for Java ME posted in bug 411981. The zip file attached contains two eclipse projects and the binary of the demo app - PahoClientMqttV3JME - MQTT Java ME client - CBdemoApp - Demo App - Binary CBdemoApp.jar, CBdemoApp.jad (the app is preconfigured to be used with German Telekom SIM card) You would need to unzip the MQTT_Client_GTO_EHSx_v1.zip file and import the containing zip files one by one into your pre-configured eclipse environment (File-->Import-->Archive File). On the MQTT Client I have customized the TCP and SSL connection modules to work with the Gemalto/Cinterion 3G Module EHS5 and EHS6. The modules are featuring the Java ME v3.2 (CLDC-1.1/IMP-NG). Gemalto is going to release an easy to use Concept Board which is based on the EHS6 and which allows to plug the Arduino shields on it. The Arduino shields can be accessed with Java. In addition I have written a small demo app which is handling the cellular connection and using the MQTT client for sending the data to the internet. The app is monitoring the free available RAM and the AD-converter. As soon as some new values available, they will be sent to the MQTT broker powered by M2MGO (broker.m2mgo.com). The broker is linked with the free accessible display page also powered by M2MGO (display.m2mgo.com) where the values can be seen. The configuration of the demo app can be done in the JAD file. You will be able to configure the cellular data connection (APN, APN-User, APN-Password and the SIM-PIN) as well as the MQTT broker. In case the APN field is not available or empty in the JAD file, the app will use the apncfg.txt file (also attached). In this file the APN can be configured dynamically. The APN will be determined accordingly to the home MCCMNC. (Note: only 5 digits MCCMNC will be recognized). Default APN can be defined under dummy APN 00000. Please feel free to provide your feedback and submit the improvements.
Hi, I'm very interested to the JME porting. I would try your porting, and help to improve software reliability. I'm trying to import and execute (wtk simulator) your attached demo, but I always get the following exception: [wtkrun] DeviceID: XXX12345 [wtkrun] CBdemoApp:generateClientID()- [wtkrun] MQTTHandler:MQTTHandler()+ [wtkrun] MQTTHandler:MQTTHandler()- [wtkrun] Connecting to MQTT brocker... [wtkrun] MQTTHandler:connectToBrocker()+ [wtkrun] MQTT client ID: XXX12345 [wtkrun] Connecting to: tcp://broker.m2mgo.com:1883 [wtkrun] !Exception at connecting! [wtkrun] org.eclipse.paho.client.mqttv3.MqttException: [wtkrun] at org.eclipse.paho.client.mqttv3.internal.Token.waitForResponse(+287) [wtkrun] at org.eclipse.paho.client.mqttv3.internal.Token.waitForCompletion(+50) [wtkrun] at org.eclipse.paho.client.mqttv3.MqttToken.waitForCompletion(+8) [wtkrun] at org.eclipse.paho.client.mqttv3.MqttClient.connect(+19) [wtkrun] at com.myapp.MQTTHandler.connectToBrocker(+109) [wtkrun] at com.myapp.startUpApp(+76) Any idea how to solve the issue? Thanks! Valerio
Hallo Valerio, it seems like your module can not create the data connection. Does your SIM allow the data connection in general? Are you using the right APN? I also don't see any outputs about the network registration in your log. Are you using the demo app I provided? Could you provide the entire log. Could you describe your HW setup. Regards Oleg
Hi Oleg, I've found the issue, it is due to the WTK simulator, that don't allow to create a socket connection if the query string of the uri contain something like key1=;key2= Using your demo app the wtk simulator can't detect the APN so the querystring result corrupted. Now I can subscribe, send and receive messages, but If I keep the app open for some minutes it stop to receive messages. I'm investigating... any ideas? Maybe a tuning of the keepalive parameter? Thanks, Valerio
Hello Valerio, The demo app is a straight forward implementation. For doing this reliable some efforts need to be spent, debugging, testing... Please let me know if you find anything which can be improved. Regards Oleg
Moving this to Samples, it also needs a CQ and/or CLA from the author.
I have tried MQTT Client on ME 8.1 on Raspberry Pi board and I see below errors: TRACE: <at java.lang.NullPointerException>, startApp threw an Exception java.lang.NullPointerException - org/eclipse/paho/client/mqttv3/internal/MessageCatalog.getMessage(MessageCatalog.java:39) - org/eclipse/paho/client/mqttv3/MqttException.getMessage(MqttException.java:200) - org/eclipse/paho/client/mqttv3/MqttException.toString(MqttException.java:208) - java/lang/String.valueOf(), bci=11 - java/io/PrintStream.print(), bci=2 - java/io/PrintStream.println(), bci=2 - java/lang/Throwable.printStackTrace(), bci=2 - java/lang/Throwable.printStackTrace(), bci=4 - javameapp82/SimpleMqttClient.testMQTTClient(SimpleMqttClient.java:96) - javameapp82/JavaMEApp82.startApp(JavaMEApp82.java:50) - javax/microedition/midlet/MIDletTunnelImpl.callStartApp(), bci=1 - com/sun/midp/midlet/MIDletPeer.startApp(), bci=5 - com/sun/midp/midlet/MIDletStateHandler.startSuite(), bci=264 - com/sun/midp/main/AbstractMIDletSuiteLoader.startSuite(), bci=38 - com/sun/midp/main/CldcMIDletSuiteLoader.startSuite(), bci=5 - com/sun/midp/main/AbstractMIDletSuiteLoader.runMIDletSuite(), bci=132 - com/sun/midp/main/AppIsolateMIDletSuiteLoader.main(), bci=26 Thanks for the help. Ashok
I have fixed my problem and now able to run Java ME 8 MQTT client on Pi board. The problem is I have taken the source code of the demo project and extracted source files of MQTT Client. In my case in File TCPMicroNetworkModule.java file uri is passed is wrong. So I have changed/commented that part and now it is working okay. with below code uri is passed as socket://10.91.40.120:1883;bearer_type=gprs;access_point=internet;username=;password=;timeout=40 due to this SocketConnection throwing exception of IllegalArgument, so I have removed rest of things from uri and it worked. public TCPMicroNetworkModule(String host, int port) { connOptions = GPRSConnectOptions.getConnectOptions(); this.uri = "socket://" + host + ":" + port; // + ";bearer_type=" // + connOptions.getBearerType() // + ";access_point=" // + connOptions.getAPN() // + ";username=" // + connOptions.getUser() // + ";password=" // + connOptions.getPasswd() // + ";timeout=" // + connOptions.getTimeout(); } Thanks all for the source code reference. ~Ashok
(In reply to Ashok Athukuri from comment #7) > I have fixed my problem and now able to run Java ME 8 MQTT client on Pi > board. The problem is I have taken the source code of the demo project and > extracted source files of MQTT Client. In my case in File > TCPMicroNetworkModule.java file uri is passed is wrong. > > So I have changed/commented that part and now it is working okay. > with below code uri is passed as > socket://10.91.40.120:1883;bearer_type=gprs;access_point=internet;username=; > password=;timeout=40 > > due to this SocketConnection throwing exception of IllegalArgument, so I > have removed rest of things from uri and it worked. Could it be that the username and password are blank? Maybe you should not append connection options that are blank to the URI? Anyways, it's really great to see you've ported the current code to ME 8.1. Is there any chance you could contribute back to Paho the modifications you did? Thanks! Benjamin –
Benjamin, I checked on github https://github.com/eclipse/paho.mqtt.java/tree/master/org.eclipse.paho.jmeclient there the code is okay. public TCPMicroNetworkModule(String host, int port) { this.uri = "socket://" + host + ":" + port; } May be in demo project it was included for different purpose. Thanks, Ashok
(In reply to Oleg Pts from comment #0) > Created attachment 236692 [details] > MQTT Client for Java ME + Demo App > > Finally I have found some time to work on the MQTT client for the Java ME. > In my implementation I have been using the recent version of Paho Java SE > MQTT client and the changes for Java ME posted in bug 411981. > > The zip file attached contains two eclipse projects and the binary of the > demo app > - PahoClientMqttV3JME - MQTT Java ME client > - CBdemoApp - Demo App > - Binary CBdemoApp.jar, CBdemoApp.jad (the app is preconfigured to be used > with German Telekom SIM card) > You would need to unzip the MQTT_Client_GTO_EHSx_v1.zip file and import the > containing zip files one by one into your pre-configured eclipse environment > (File-->Import-->Archive File). > > On the MQTT Client I have customized the TCP and SSL connection modules to > work with the Gemalto/Cinterion 3G Module EHS5 and EHS6. > The modules are featuring the Java ME v3.2 (CLDC-1.1/IMP-NG). Gemalto is > going to release an easy to use Concept Board which is based on the EHS6 and > which allows to plug the Arduino shields on it. The Arduino shields can be > accessed with Java. > > In addition I have written a small demo app which is handling the cellular > connection and using the MQTT client for sending the data to the internet. > The app is monitoring the free available RAM and the AD-converter. As soon > as some new values available, they will be sent to the MQTT broker > powered by M2MGO (broker.m2mgo.com). > The broker is linked with the free accessible display page also > powered by M2MGO (display.m2mgo.com) where the values can be seen. > > The configuration of the demo app can be done in the JAD file. You will be > able to configure the cellular data connection > (APN, APN-User, APN-Password and the SIM-PIN) as well as the MQTT broker. > In case the APN field is not available or empty in the JAD file, the app > will use the apncfg.txt file (also attached). > In this file the APN can be configured dynamically. The APN will be > determined accordingly to the home MCCMNC. > (Note: only 5 digits MCCMNC will be recognized). Default APN can be defined > under dummy APN 00000. > > Please feel free to provide your feedback and submit the improvements. Hi Andy I have downloaded this and I have tested its operation, it's working good. But now I would like to connect to a broker with certificates, you could help me with this. I have saw something, I think it could be with mqttOptions.setSSLProperties(props); but I am not sure, you could give me some advice or some way to do this. Thanks in advance. Fer.