0

Feather Huzzah32 and Adafruit IO
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather Huzzah32 and Adafruit IO

by DrDetroit on Tue Aug 07, 2018 10:45 pm

Oddly enough, I can't find an example of a sketch that puts the Huzzah32 onto Adafruit IO. The wifi library is different, and that's confusing the mqtt library (apparently).

Any hints?

DrDetroit
 
Posts: 16
Joined: Thu Aug 02, 2018 2:57 pm

Re: Feather Huzzah32 and Adafruit IO

by brubell on Wed Aug 08, 2018 10:09 am

Are you using the Adafruit IO Arduino Library (https://learn.adafruit.com/welcome-to-a ... -based-6-2)?

Could you paste the output (including errors) from the Arduino IDE?

brubell
 
Posts: 99
Joined: Fri Jul 17, 2015 10:33 pm

Re: Feather Huzzah32 and Adafruit IO

by DrDetroit on Wed Aug 08, 2018 11:27 am

I did manage to get it to work with this code literally 15m ago. It was snagged from Adel Kassah's related Youtube video. I combined publish and subscribe, and here's what I ended up with.

/////////////////////////////////
// Generated with a lot of love//
// with TUNIOT FOR ESP32 //
// Website: Easycoding.tn //
// Minor Modifications by Robert Jones
/////////////////////////////////
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <WiFi.h>

#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "DrDetroit"
#define AIO_KEY "shh..It's a secret"
WiFiClient client;

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

Adafruit_MQTT_Subscribe onoff = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/onoff");
//Added 9:56AM
Adafruit_MQTT_Publish test = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/test");
boolean MQTT_connect();

boolean MQTT_connect() { int8_t ret; if (mqtt.connected()) { return true; } uint8_t retries = 3; while ((ret = mqtt.connect()) != 0) { mqtt.disconnect(); delay(2000); retries--;if (retries == 0) { return false; }} return true;}

void setup()
{
Serial.begin(115200);


mqtt.subscribe(&onoff);
WiFi.disconnect();
delay(3000);
Serial.println("START");
WiFi.begin("ATT4aky3rk 2.4Ghz","8#jus4vvu37r");
while ((!(WiFi.status() == WL_CONNECTED))){
delay(300);
Serial.print("..");

}
Serial.println("Connected");
Serial.println("Your IP is");
Serial.println((WiFi.localIP()));

}


void loop()
{

if (MQTT_connect()) {
Adafruit_MQTT_Subscribe *subscription_name;
while ((subscription_name = mqtt.readSubscription(1000))) {
if (subscription_name == &onoff) {
Serial.println("New value on onoff");
Serial.println(((char *)onoff.lastread));

}

}
//this just sends out the number '4'
if (test.publish("4")) {
Serial.println("Published");

}

}
delay(2000);
}

DrDetroit
 
Posts: 16
Joined: Thu Aug 02, 2018 2:57 pm

Re: Feather Huzzah32 and Adafruit IO

by DrDetroit on Fri Aug 10, 2018 2:27 pm

Solved.

DrDetroit
 
Posts: 16
Joined: Thu Aug 02, 2018 2:57 pm

Please be positive and constructive with your questions and comments.