adafruit / Adafruit_IO_Arduino

Arduino library to access Adafruit IO from WiFi, cellular, and ethernet modules.
Other
210 stars 107 forks source link

Fix ESP32 Groups Crash #115

Closed brentru closed 4 years ago

brentru commented 4 years ago

Fixes crash on group subscription and publishing:

Explanation: The comparison if (strcmp(cur_cb->feed, d->feedName()) == 0 || cur_cb->feed == NULL{ fails due to the callback attempting to obtain the feed's name (cur_cb->feed) because the _groupCallback callback was never properly init'd since the setup() in adafruitio_11_group_pub.ino never calls onMessage, which is used to initialize the _groupCallback (https://github.com/adafruit/Adafruit_IO_Arduino/blob/master/src/AdafruitIO_Group.cpp#L309).

The _groupCallback is never NULL, so the check within onMessage which initializes _groupCallback also fails. This is why the subscribe example fails in the same part of the code, while it properly sets up the message handler.

Tested on Adafruit Feather HUZZAH32 examples/adafruitio_12_group_sub/adafruitio_12_group_sub.ino

Connecting to Adafruit IO
..
Adafruit IO connected.
received example.count-1 <- 3
received example.count-2 <- 4
received example.count-1 <- test!
received example.count-2 <- Test two!

examples/adafruitio_11_group_pub/adafruitio_11_group_pub.ino

Adafruit IO connected.
sending example.count-1 -> 0
sending example.count-2 -> 0
...
sending example.count-1 -> 8
sending example.count-2 -> 16
bborncr commented 4 years ago

I tested this fix and it works for me. No more crashes.