0

Connected to Adafruit IO, but nothing else
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Connected to Adafruit IO, but nothing else

by Lbkulinski on Thu Aug 01, 2019 7:02 pm

Hi. I am experimenting with Adafruit IO and my HUZZAH32 using the following code:

Code: Select all | TOGGLE FULL SIZE
#include "AdafruitIO_WiFi.h"
#include "AdafruitIO_Feed.h"
#include "AdafruitIO_Data.h"

#define CONNECTED_LED 13

#define LED_PIN 5

#define USERNAME "Lbkulinski"
#define KEY "my-key"
#define SSID "my-ssid"
#define PASSWORD "my-password"

#define FEED_NAME "LED Toggle"

AdafruitIO_WiFi io(USERNAME, KEY, SSID, PASSWORD);
AdafruitIO_Feed* feed;

void setup() {
  pinMode(CONNECTED_LED, OUTPUT);
 
  pinMode(LED_PIN, OUTPUT);
 
  Serial.begin(115200);

  while (!Serial);

  io.connect();

  while (io.status() != AIO_CONNECTED);

  digitalWrite(CONNECTED_LED, HIGH);

  Serial.println();
 
  Serial.println("Connected to Adafruit IO...");

  feed = io.feed(FEED_NAME);

  feed->onMessage(handleMessage);

  feed->get();
} //setup

void loop() {
  io.run();
} //loop

void handleMessage(AdafruitIO_Data* data) {
  int pinLevel = data->toPinLevel();
 
  if (pinLevel == HIGH) {
    Serial.println("HIGH");
  } else {
    Serial.println("LOW");
  } //end if

  digitalWrite(LED_PIN, pinLevel);
} //handleMessage


My Serial Monitor says that I connected to Adafruit IO, but nothing occurs after that. I tried to use the example. Where am I going wrong?

Thank you!

Lbkulinski
 
Posts: 116
Joined: Wed May 07, 2014 4:41 pm

Re: Connected to Adafruit IO, but nothing else

by franklin97355 on Thu Aug 01, 2019 8:03 pm

Have you set up your Adafruit IO account and the config file or are you adding your personal info directly into the program?

franklin97355
 
Posts: 20974
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Connected to Adafruit IO, but nothing else

by Lbkulinski on Thu Aug 01, 2019 8:11 pm

My account is set up, and the Monitor tab says my board did connect. I decided not to use the config.h file. May that be the issue?

Lbkulinski
 
Posts: 116
Joined: Wed May 07, 2014 4:41 pm

Re: Connected to Adafruit IO, but nothing else

by brubell on Fri Aug 02, 2019 10:24 am

I found a few issues with your code which may be related


Your feed name should be set to your Feed Key: (it's probably led-toggle, not LED Toggle)
Code: Select all | TOGGLE FULL SIZE
#define FEED_NAME "LED Toggle"


You can check this value on Adafruit IO's feeds page
IO_-_Feed__Feed_Name.png
IO_-_Feed__Feed_Name.png (36.83 KiB) Viewed 166 times


You should also define your feed at the top of the file, like this:
Code: Select all | TOGGLE FULL SIZE
AdafruitIO_Feed *feed = io.feed(FEED_NAME);

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

Re: Connected to Adafruit IO, but nothing else

by Lbkulinski on Fri Aug 02, 2019 11:28 am

I’ve tried those before, and they haven’t worked.

Lbkulinski
 
Posts: 116
Joined: Wed May 07, 2014 4:41 pm

Re: Connected to Adafruit IO, but nothing else

by abachman on Fri Aug 02, 2019 11:46 am

hi Lbkulinski!

My Serial Monitor says that I connected to Adafruit IO, but nothing occurs after that. I tried to use the example.


What output from the serial monitor are you expecting? Are you publishing any data to the feed you're subscribing to?


- adam b.

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

Re: Connected to Adafruit IO, but nothing else

by Lbkulinski on Fri Aug 02, 2019 12:14 pm

After it prints that it connected successfully, I expect it to print HIGH or LOW depending on the value of the toggle. And I’m not publishing anything.

Lbkulinski
 
Posts: 116
Joined: Wed May 07, 2014 4:41 pm

Re: Connected to Adafruit IO, but nothing else

by abachman on Fri Aug 02, 2019 12:50 pm

Ah!


I see you're calling .get() correctly, but you will have to use the proper feed key that brubell mentioned, the name will not work. It's on the feed page and in the feed listing table.

Besides the .get call, are you able to see any data while running this sketch and publishing from a dashboard or the "LED Toggle" page?


- adam

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

Re: Connected to Adafruit IO, but nothing else

by Lbkulinski on Fri Aug 02, 2019 1:11 pm

It's working now! Thank you! I had tried all of those things recommended, but just not all at once.

As a side question, after uploading to the board through Arduino IDE, I need to press the reset button in order to get any sort of connection. Is that the expected behavior?

Lbkulinski
 
Posts: 116
Joined: Wed May 07, 2014 4:41 pm

Re: Connected to Adafruit IO, but nothing else

by brubell on Fri Aug 02, 2019 3:57 pm

Lbkulinski wrote:It's working now! Thank you! I had tried all of those things recommended, but just not all at once.


Fantastic!

As a side question, after uploading to the board through Arduino IDE, I need to press the reset button in order to get any sort of connection. Is that the expected behavior?

By connection, do you mean connection to the serial monitor or connection to Adafruit IO? Are you using a HUZZAH32 breakout or Feather HUZZAH32? These boards have different behaviors.

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

Re: Connected to Adafruit IO, but nothing else

by Lbkulinski on Fri Aug 02, 2019 5:53 pm

Connection to Adafruit IO. I am using the HUZZAH32 Feather.

Lbkulinski
 
Posts: 116
Joined: Wed May 07, 2014 4:41 pm

Re: Connected to Adafruit IO, but nothing else

by brubell on Fri Aug 02, 2019 6:12 pm

Lbkulinski wrote:Connection to Adafruit IO. I am using the HUZZAH32 Feather.

This line in your code waits for the serial monitor to open before executing the rest of the code:
Code: Select all | TOGGLE FULL SIZE
  while (!Serial);


This includes waiting for the serial monitor to open before calling io.connect().

Could you try removing or commenting out this line?

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

Re: Connected to Adafruit IO, but nothing else

by Lbkulinski on Fri Aug 02, 2019 6:23 pm

I have the serial monitor open when uploading revisions. Could that be an issue? And with my Arduino Mega, while(!Serial) won't block when I'm not using the serial monitor. Is that not the case with the Feater?

Lbkulinski
 
Posts: 116
Joined: Wed May 07, 2014 4:41 pm

Re: Connected to Adafruit IO, but nothing else

by brubell on Mon Aug 05, 2019 9:42 am

Lbkulinski wrote:I have the serial monitor open when uploading revisions. Could that be an issue? And with my Arduino Mega, while(!Serial) won't block when I'm not using the serial monitor. Is that not the case with the Feater?


The MEGA has a USB->Serial bridge, so this line does nothing.

Feather boards have a direct USB connection, so this line works as expected (waiting for the serial monitor to open).

- brent r

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

Re: Connected to Adafruit IO, but nothing else

by Lbkulinski on Mon Aug 05, 2019 1:38 pm

Thank you for the info! I haven't had much time to look into it.

When I have the serial monitor already open, should I have to reset after I upload? That's the issue I am having at the moment. There are also question marks being printed when I open it. I can attached a screenshot if you need.

Lbkulinski
 
Posts: 116
Joined: Wed May 07, 2014 4:41 pm

Please be positive and constructive with your questions and comments.