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