Please note: Friday June 18 is a holiday celebrating Juneteenth, please allow extra time for your order to arrive and plan accordingly.
0

How to access feed using Eclipse Paho (Java)?
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

How to access feed using Eclipse Paho (Java)?

by xavz on Mon May 31, 2021 4:57 pm

Hello, I am currently learning Java and am doing a very basic IoT project. Here is my code so far:

https://imgur.com/a/j4i77Yn

When I use the full adafruit Key as my clientID, I get an error saying invalid clientID. For some reason, when I shorten it it seems to bypass that error, but now I get the following error:
Exception in thread "main" Bad user name or password (4)

If anybody could guide me in the right direction it would be much appreciated.

xavz
 
Posts: 2
Joined: Sun May 23, 2021 12:23 pm

Re: How to access feed using Eclipse Paho (Java)?

by brubell on Tue Jun 01, 2021 9:55 am

Please post your full code in between [code] tags.

When I use the full adafruit Key as my clientID, I get an error saying invalid clientID. For some reason, when I shorten it it seems to bypass that error, but now I get the following error:
Exception in thread "main" Bad user name or password (4)


Please post the full error output from your compiler or console.

brubell
 
Posts: 1381
Joined: Fri Jul 17, 2015 10:33 pm

Re: How to access feed using Eclipse Paho (Java)?

by xavz on Tue Jun 01, 2021 12:44 pm

Code: Select all | TOGGLE FULL SIZE
public class MQTTest {

    public static void main(String args[]) throws MqttException {

       System.out.println("Starting Program Test");

       final String clientId = "aio_DMEg79mPQXngoY";
       //MemoryPersistence persistence = new MemoryPersistence();
       MqttClient client = new MqttClient("tcp://io.adafruit.com:1883", clientId);
       client.setCallback(new SimpleMqttCallBack());
       client.connect();

       MqttConnectOptions mqOptions=new MqttConnectOptions();
       mqOptions.setCleanSession(true);
       client.connect(mqOptions);      //connecting to broker
       client.subscribe("xavz/feeds/distance"); //subscribing to the topic name  test/topic

    }


}


Error:
Exception in thread "main" Bad user name or password (4)
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:28)
at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:1053)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:151)
at java.lang.Thread.run(Thread.java:748)

xavz
 
Posts: 2
Joined: Sun May 23, 2021 12:23 pm

Re: How to access feed using Eclipse Paho (Java)?

by brubell on Fri Jun 04, 2021 9:36 am

MqttClient client = new MqttClient("tcp://io.adafruit.com:1883", clientId);


I don't see your Adafruit IO username being used, only your Adafruit IO key.

Your Adafruit IO username is your username
Your adafruit io key is your password.

You do not need to specify a client id.

brubell
 
Posts: 1381
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.