0

Why can't I begin Adafruit IO after the setup function
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Why can't I begin Adafruit IO after the setup function

by MaxMaeder on Thu Jan 04, 2018 8:16 pm

Why can't I begin Adafruit IO after the setup function? Every time I try to begin it with the code below, I cannot connect, but when I begin Adafruit IO before the setup function, it works perfectly. Why is this?

Code: Select all | TOGGLE FULL SIZE
Adafruit_MQTT_Client mqtt(&client, aioServer, aioPort, aioUsername, aioKey); // Setup Adafruit IO
Adafruit_MQTT_Publish gpg = Adafruit_MQTT_Publish(&mqtt, urlGpg);
Adafruit_MQTT_Publish ppm = Adafruit_MQTT_Publish(&mqtt, urlPpm);
Adafruit_MQTT_Publish alerts = Adafruit_MQTT_Publish(&mqtt, urlAlerts);
Adafruit_MQTT_Subscribe iqOnOffButton = Adafruit_MQTT_Subscribe(&mqtt, urlWateriq);

MaxMaeder
 
Posts: 3
Joined: Sun Oct 29, 2017 5:49 pm

Re: Why can't I begin Adafruit IO after the setup function

by abachman on Mon Jan 08, 2018 2:04 pm

hi Max,


This is speculation / superstition and coming from my experience as a developer, but in situations like this if one way of organizing the code works and the other doesn't, stick with the one that works :D

If I had to guess, the Arduino IDE's conversion of your .ino file to a proper C++ project before compilation and the Adafruit MQTT library's use of constructors are interacting in a way that produces the behavior you describe. Stick with the pre-setup MQTT declarations.


- adam

abachman
 
Posts: 212
Joined: Mon Feb 01, 2010 12:48 pm

Please be positive and constructive with your questions and comments.