0

Multiple feeds to remote ESP-12E
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.
Please be positive and constructive with your questions and comments.

Multiple feeds to remote ESP-12E

by Loddepus on Mon Mar 22, 2021 6:14 pm

Hi people.
I have struggled through forums, examples and testing different codes to remote to dig outputs on my ESP-12E from Adafruit dashboard through 2 feeds.
It works fine to remote from dashboard with one feed as in "basics-digital-output/code"-example (toggeling the block on-off). I proceeded with the example "Adafruit IO Multiple Feed Example" and there its stated in the end of code: " ...// since we are using the same function to handle messages for two feeds, we can use feedName() in order to find out which feed the message came from.
Serial.print(data->feedName());
Serial.print(" ");...
So I assume that I simply substitute "feedName()" with my actual feed name in 2 IF-statement too, to sort which feed toggled on & which corresponding LED-output pin to toggle?
See attached code which give error when compiling : "'feedName' was not declared in this scope".

Thanks for taking your time and helping me.

Code: Select all | TOGGLE FULL SIZE
// Adafruit IO Digital Output Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-digital-output
// 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";
/************************ Prog Starts Here *******************************/

// digital pin 16 = D0. pin 13 =D7. Board ESP8266 based on ESP-12E.
#define BLUE_PIN 16   //BLUE LED run from AdafruitIO dashboard
#define RED_PIN 13    //RED LED run from AdafruitIO dashboard
XXX feedName();    // WHAT VARIBLE XXX TYPE TO SET FOR "feedName"  ???

// set up the 'digital' feed
AdafruitIO_Feed *digitalblue = io.feed("digitalblue");
AdafruitIO_Feed *digitalred = io.feed("digitalred");

void setup() {
  pinMode(BLUE_PIN, OUTPUT);
  pinMode(RED_PIN, OUTPUT);

  // start the serial connection
  Serial.begin(115200);
  // wait for serial monitor to open
  while (! Serial);
  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();
  // set up a message handler for the 2 feeds.
  // the handleMessage function (defined below)
  // will be called whenever a message is
  // received from adafruit io.
  digitalblue->onMessage(handleColor);
  digitalred->onMessage(handleColor);

  // wait for a connection
  while (io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  // we are connected
  Serial.println();
  Serial.println(io.statusText());
  digitalblue->get();
  digitalred->get();
}

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();
}

// this function is called whenever an 'digital' feed message
// is received from Adafruit IO. it was attached to
// the 2 feeds in the setup() function above.
void handleColor(AdafruitIO_Data *data) {
   (data->feedName());
   if (feedName() == digitalblue) {          // assume we can use feedName() in order to find out which feed the message came from ?
    Serial.println("Blue=ON");
    digitalWrite(BLUE_PIN, HIGH);     
  }
  else
    Serial.println("Blue=OFF");
}
void handleColor(AdafruitIO_Data *data) {
  (data->feedName()):
  if (feedName() == digitalred) {          // assume we can use feedName() in order to find out which feed the message came from ?
    Serial.println("Red=ON");
    digitalWrite(RED_PIN, HIGH);       
  }
  else
    Serial.println("Red=OFF");
}

Loddepus
 
Posts: 9
Joined: Wed Jun 26, 2019 11:32 am

Re: Multiple feeds to remote ESP-12E

by brubell on Wed Mar 24, 2021 10:42 am

See attached code which give error when compiling: "'feedName' was not declared in this scope".


Could you include your full error output? Copy and paste it from the Arduino IDE.

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

Re: Multiple feeds to remote ESP-12E

by Loddepus on Wed Mar 24, 2021 1:35 pm

Here is the original error message. (I did some changes in code afterwards to reduse error message to the final "'feedName' was not declared in this scope").

Arduino:1.8.13 (Windows 7), Kort"NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

SLETT-_2_feeds:12:1: error: 'XXX' does not name a type

XXX feedName(); // WHAT VARIBLE XXX TYPE TO SET FOR "feedName" ???

^

C:\Users\Trond\Documents\Arduino\SLETT-_2_feeds\SLETT-_2_feeds.ino: In function 'void handleColor(AdafruitIO_Data*)':

SLETT-_2_feeds:61:17: error: 'feedName' was not declared in this scope

if (feedName() == digitalblue) { // assume we can use feedName() in order to find out which feed the message came from ?

^

C:\Users\Trond\Documents\Arduino\SLETT-_2_feeds\SLETT-_2_feeds.ino: In function 'void handleColor(AdafruitIO_Data*)':

SLETT-_2_feeds:68:6: error: redefinition of 'void handleColor(AdafruitIO_Data*)'

void handleColor(AdafruitIO_Data *data) {

^

SLETT-_2_feeds:59:6: error: 'void handleColor(AdafruitIO_Data*)' previously defined here

void handleColor(AdafruitIO_Data *data) {

^

SLETT-_2_feeds:69:21: error: expected ';' before ':' token

(data->feedName()):

^

SLETT-_2_feeds:74:3: error: 'else' without a previous 'if'

else

^

exit status 1

'XXX' does not name a type

Thanks for the reply :-)

Loddepus
 
Posts: 9
Joined: Wed Jun 26, 2019 11:32 am

Re: Multiple feeds to remote ESP-12E

by Loddepus on Thu Mar 25, 2021 4:22 am

Hi brubell.
I changed my code in end of void loop, to the original Adafruit IO Multiple Feed Example :

void handleColor(AdafruitIO_Data *data) {
// char whichFeed =(data->feedName());
// if (whichFeed == digitalblue) {
// Serial.println("Blue=ON");
// digitalWrite(BLUE_PIN, HIGH);
// }
// Serial.println("Blue=OFF");

// if (whichFeed == digitalred) {
// Serial.println("Red=ON");
// digitalWrite(RED_PIN, HIGH);
// }
// Serial.println("Red=OFF");
Serial.println(data->feedName());
Serial.println(data->value());
Serial.println("--------");
}

This works fine to see in serial monitor which feed is toggled on/off :

08:50:38.059 -> digitalblue
08:50:38.059 -> 1
08:50:38.059 -> --------
08:50:43.699 -> digitalblue
08:50:43.699 -> 0
08:50:43.699 -> --------
08:50:51.819 -> digitalred
08:50:51.819 -> 1
08:50:51.819 -> --------
08:50:54.059 -> digitalred
08:50:54.059 -> 0
08:50:54.059 -> --------

So my main question is : What are hidden in the "data"-string (or payload message) from AdafruitIO feed ?
- and where is the library that define and calls these different commands
as data->feedName(), data->value() and so on ?
I appreciate to understand how to convert those varibles to use in logic statments in void loop.

Thanks , regards Loddepus.

Loddepus
 
Posts: 9
Joined: Wed Jun 26, 2019 11:32 am

Re: Multiple feeds to remote ESP-12E

by brubell on Fri Mar 26, 2021 9:46 am

So my main question is : What are hidden in the "data"-string (or payload message) from AdafruitIO feed ?
- and where is the library that define and calls these different commands
as data->feedName(), data->value() and so on ?
I appreciate to understand how to convert those varibles to use in logic statments in void loop.


The library which manipulates this data is Adafruit IO Arduino

Take a look at the type conversion example for information on how to convert the variables: https://github.com/adafruit/Adafruit_IO ... conversion

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

Re: Multiple feeds to remote ESP-12E

by Loddepus on Fri Mar 26, 2021 9:50 am

Thanks for the advice.
I will lock into that.
Have a nice weekend.

Loddepus
 
Posts: 9
Joined: Wed Jun 26, 2019 11:32 am

Please be positive and constructive with your questions and comments.