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.
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.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
- brubell
- Learn User Page
- Posts: 2010
- Joined: Fri Jul 17, 2015 10:33 pm
Re: How to access feed using Eclipse Paho (Java)?
Please post your full code in between
Code: Select all
tags.
[quote]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)[/quote]
Please post the full error output from your compiler or console.
- xavz
- Posts: 2
- Joined: Sun May 23, 2021 12:23 pm
Re: How to access feed using Eclipse Paho (Java)?
Code: Select all
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
}
}
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)
- brubell
- Learn User Page
- Posts: 2010
- Joined: Fri Jul 17, 2015 10:33 pm
Re: How to access feed using Eclipse Paho (Java)?
I don't see your Adafruit IO username being used, only your Adafruit IO key.MqttClient client = new MqttClient("tcp://io.adafruit.com:1883", clientId);
Your Adafruit IO username is your username
Your adafruit io key is your password.
You do not need to specify a client id.
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.