Adafruit_MQTT_Library
Adafruit_MQTT_Library copied to clipboard
mqtt_ethernet.ino example code not working
When using the code available in the example, modifying the required fields, Arduino Uno with ethernet shield always return "Connection failed".
Hi marcoracer,
Which fields did you modify?
lines 35 and 36 for AIO_USERNAME and AIO_KEY respectively, of course. I did not change the feed name because I know that it will create one if it does not exists .
Can you double check that you put in your username and key correctly?
If it's in there correctly, try manually assigning an ip address and dns server by doing the following:
- uncomment lines 25 and 27
- (change the IP address in line 25 to a valid one for your subnet if necessary)
- change line 68 from "Ethernet.begin(mac);" to "Ethernet.begin(mac, iotIP, dnsIP);"
If you're still having trouble, double check your connection, and if the WebClient example (under Examples for any board -> Ethernet) doesn't successfully connect to google.com, then you've got an issue with maybe your network or hardware.
Yes, username and keys are correct and working on a NodeMCU. I'm sure that the dhcp is working because I can ping the Arduino+EtherShield. I'm sure that Arduino+EtherShield has a Internet connection because, in another debug version, I add DNS and HTML get method verifications! I also tried in two different hardwares (a second arduino and a second shield) to exclude the possibility of hardware problems! Right now I'm I'm confident that there is a problem with the library, maybe regarding Adafruit_MQTT_Client and EthernetClient.
I am also having trouble getting Arduino Uno + Ethernet Shield working.
In the tutorial, it describes storing the server name, username, password etc as flash strings (PROGMEM): https://learn.adafruit.com/mqtt-adafruit-io-and-you/intro-to-adafruit-mqtt
However in commit 7886b724, it switches from strcpy_P
to strcpy
- so the server name is no-longer expected to be a flash string.
Elsewhere there are still references to pgm_read_byte.
I have this same problem, and it cannot be fixed by working back to an older version of the library, Anyone ever come up with a solution? I'm using a Feather 32u4 with the associated Ethernet add-on.