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

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.
Locked
User avatar
MaxMaeder
 
Posts: 4
Joined: Sun Oct 29, 2017 5:49 pm

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

Post by MaxMaeder »

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

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);

User avatar
abachman
 
Posts: 352
Joined: Mon Feb 01, 2010 12:48 pm

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

Post by abachman »

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

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”