Has anyone got MQTT to work without using #define keys

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
niyer
 
Posts: 2
Joined: Mon Feb 07, 2022 1:42 am

Has anyone got MQTT to work without using #define keys

Post by niyer »

How do I save my MQTT Client user name and key as variables, instead to placing them as "#define" preprocessor. Has anyone done this? I have tried making the declaration as pointer but it keeps crashing.

Adafruit_MQTT_Client *mqtt = NULL;
mqtt = new Adafruit_MQTT_Client(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME1, AIO_KEY1);
This above method crashes when I publish, seems like I have to modulate the WiFiclient along with MQTT.

Is there a simpler solution for this? Would moving to rest api (io) solve this problem?

The motivation to store the keys as variables is so that I can encrypt them and save them in a private location.
I am using a Huzzah ESP8266 Board.

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Has anyone got MQTT to work without using #define keys

Post by brubell »

you may want to take a look at this sketch for using a WiFiManager to dynamically set the parameters, https://github.com/adafruit/Adafruit_IO ... meters.ino

User avatar
niyer
 
Posts: 2
Joined: Mon Feb 07, 2022 1:42 am

Re: Has anyone got MQTT to work without using #define keys

Post by niyer »

Thank you, brubell. Yep I ended up going with "io".

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”