esp32 won't run an Adafruit IO sketch

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
aidan_the_tinkerer
 
Posts: 50
Joined: Fri Nov 01, 2019 2:48 pm

esp32 won't run an Adafruit IO sketch

Post by aidan_the_tinkerer »

Hi,

I have spent the past six hours trying to do the following.

I modified the Adafruit IO subscribe example to control some devices for my hydroponic garden. The example works on my esp32, but what I wrote doesn't–I get something like a brownout error.

This works perfectly:

Code: Select all

// Adafruit IO Subscription Example
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/

// set up the 'counter' feed
AdafruitIO_Feed *counter = io.feed("counter");

void setup() {

  // start the serial connection
  Serial.begin(115200);

  // wait for serial monitor to open
  while(! Serial);

  Serial.print("Connecting to Adafruit IO");

  // start MQTT connection to io.adafruit.com
  io.connect();

  // set up a message handler for the count feed.
  // the handleMessage function (defined below)
  // will be called whenever a message is
  // received from adafruit io.
  counter->onMessage(handleMessage);

  // wait for an MQTT connection
  // NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
  // method to check on MQTT connection status specifically
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // Because Adafruit IO doesn't support the MQTT retain flag, we can use the
  // get() function to ask IO to resend the last value for this feed to just
  // this MQTT client after the io client is connected.
  counter->get();

  // we are connected
  Serial.println();
  Serial.println(io.statusText());

}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();

  // Because this sketch isn't publishing, we don't need
  // a delay() in the main program loop.

}

// this function is called whenever a 'counter' message
// is received from Adafruit IO. it was attached to
// the counter feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {

  Serial.print("received <- ");
  Serial.println(data->value());

}
But this:

Code: Select all

// Adafruit IO Subscription Example
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/

// set up the 'test' feed
AdafruitIO_Feed *waterinletonoff = io.feed("waterinletonoff");//12
AdafruitIO_Feed *phuppumponoff = io.feed("phuppumponoff");//16
AdafruitIO_Feed *drainpumponoff = io.feed("drainpumponoff");//17
AdafruitIO_Feed *heateronoff = io.feed("heateronoff");//2
AdafruitIO_Feed *circpumponoff = io.feed("circpumponoff");//7
AdafruitIO_Feed *fansonoff = io.feed("fansonoff");//4
AdafruitIO_Feed *uvlightonoff = io.feed("uvlightonoff");//22
AdafruitIO_Feed *aeratoronoff = io.feed("aeratoronoff");//10
AdafruitIO_Feed *bloomlight = io.feed("bloomlight");//19
AdafruitIO_Feed *humidifieronoff = io.feed("humidifieronoff");//5
AdafruitIO_Feed *veglight = io.feed("veglight");//18


int FILL = 4;//12
int PHUP = 16;//21
int DRAIN = 17;//15
int HEAT = 5;//2
int CIRC = 18;//7
int FANS = 19;//4
int UV = 21;//22
int AER = 3;//10
int BLOOM = 1;//18
int HUM = 22;//5
int VEG = 23;//17


void setup() {

  // start the serial connection
  Serial.begin(115200);

  // wait for serial monitor to open
  while(! Serial);

  pinMode(FILL, OUTPUT);//12
  pinMode(PHUP, OUTPUT);//21
  pinMode(DRAIN, OUTPUT);//15
  pinMode(HEAT, OUTPUT);//2
  pinMode(CIRC, OUTPUT);//7
  pinMode(FANS, OUTPUT);//4  
  pinMode(UV, OUTPUT);//22
  pinMode(AER, OUTPUT);//10
  pinMode(BLOOM, OUTPUT);//18
  pinMode(HUM, OUTPUT);//5
  pinMode(VEG, OUTPUT);//17

  Serial.print("Connecting to Adafruit IO");
  delay(1000);

  // start MQTT connection to io.adafruit.com
  io.connect();

  // set up a message handler for the count feed.
  // the handleMessage function (defined below)
  // will be called whenever a message is
  // received from adafruit io.
waterinletonoff->onMessage(handleMessage12);//12
phuppumponoff->onMessage(handleMessage16);
drainpumponoff->onMessage(handleMessage17);
heateronoff->onMessage(handleMessage2);//2
circpumponoff->onMessage(handleMessage7);//7
fansonoff->onMessage(handleMessage4);//4
uvlightonoff->onMessage(handleMessage22);
aeratoronoff->onMessage(handleMessage10);//10
bloomlight->onMessage(handleMessage19);
humidifieronoff->onMessage(handleMessage5);//5
veglight->onMessage(handleMessage18);


  // wait for an MQTT connection
  // NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
  // method to check on MQTT connection status specifically
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(1000);
  }

  // Because Adafruit IO doesn't support the MQTT retain flag, we can use the
  // get() function to ask IO to resend the last value for this feed to just
  // this MQTT client after the io client is connected.
  waterinletonoff->get();//12
  phuppumponoff->get();//16
  drainpumponoff->get();//17
  heateronoff->get();//2
  circpumponoff->get();//7
  fansonoff->get();//4
  uvlightonoff->get();//22
  aeratoronoff->get();//10
  bloomlight->get();//19
  humidifieronoff->get();//5
  veglight->get();//18
  
  // we are connected
  Serial.println();
  Serial.println(io.statusText());

}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();
  // Because this sketch isn't publishing, we don't need
  // a delay() in the main program loop.

}

// this function is called whenever a 'test' message
// is received from Adafruit IO. it was attached to
// the test feed in the setup() function above.
void handleMessage12(AdafruitIO_Data *data) {
  digitalWrite(FILL, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}

void handleMessage16(AdafruitIO_Data *data) {
  digitalWrite(PHUP, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}

void handleMessage17(AdafruitIO_Data *data) {
  digitalWrite(DRAIN, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}

void handleMessage2(AdafruitIO_Data *data) {
  digitalWrite(HEAT, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}

void handleMessage7(AdafruitIO_Data *data) {
  digitalWrite(CIRC, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}

void handleMessage4(AdafruitIO_Data *data) {
  digitalWrite(FANS, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}

void handleMessage22(AdafruitIO_Data *data) {
  digitalWrite(UV, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}

void handleMessage10(AdafruitIO_Data *data) {
   digitalWrite(AER, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}

void handleMessage19(AdafruitIO_Data *data) {
  digitalWrite(BLOOM, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}

void handleMessage5(AdafruitIO_Data *data) {
  digitalWrite(HUM, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}

void handleMessage18(AdafruitIO_Data *data) {
  digitalWrite(VEG, data->toPinLevel());
  Serial.print("received <- ");
  Serial.println(data->value());

}
Produces the following when uploaded:

Code: Select all

18:25:19.169 -> ets Jun  8 2016 00:22:57
18:25:24.739 -> 
18:25:24.739 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
18:25:24.739 -> configsip: 0, SPIWP:0xee
18:25:24.739 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
18:25:24.739 -> mode:DIO, clock div:2
18:25:24.777 -> load:0x3fff0030,len:1344
18:25:24.777 -> load:0x40078000,len:13836
18:25:24.777 -> load:0x40080400,len:3608
18:25:24.777 -> entry 0x400805f0
18:25:25.093 -> 
The config.h files are the exact same as I copied and pasted. Any ideas about this?

Best,

Aidan

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: esp32 won't run an Adafruit IO sketch

Post by mikeysklar »

Hi Aidan,

I added tags around your code to keep the post more readable.

I don't see an actual error in the Arduino IDE output your provided. Please make sure you have verbose output setting checked under Arduino --> Preferences which might help with locating the problematic code.

Since you have a working stock example and a failing custom example it would probably be best to start a third script based on the working code and slowly integrate each feed and associated pin (data source) one at a time until failure occurs.

User avatar
aidan_the_tinkerer
 
Posts: 50
Joined: Fri Nov 01, 2019 2:48 pm

Re: esp32 won't run an Adafruit IO sketch

Post by aidan_the_tinkerer »

Hi mikeysklar,

It looks like if I interrupt any of the setup stuff for connection to Adafruit IO, I get the problem that I mentioned. After moving the lines that set all of the pins as outputs to the bottom of the setup script, I had success. Thank you so much for your help.

Best,

Aidan

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: esp32 won't run an Adafruit IO sketch

Post by mikeysklar »

Well done. You solved that quickly.

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”