Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

IO Output 'handleMessage' problem
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.

IO Output 'handleMessage' problem

by Buddyboy75 on Sun Jul 26, 2020 6:23 am

Im trying to construct a WIFI switch using the IO dashboard and linking with IFTTT for google home commands.

once I have uploaded the sketch to the ESP8266, it connects fine, it will receive the current state of the switch on the dashboard. But when I change the state of the switch, nothing happens, there is no change in the serial monitor. But if I reset the ESP8266, it will then receive the changed state once it has reconnected to Adafruit IO.

I was playing around with this about a year ago, and it worked fine. I haven't changed anything since then. Have Adafruit changed anything their end??

Any help would be great.

Buddyboy75
 
Posts: 4
Joined: Wed Jan 29, 2020 6:35 am

Re: IO Output 'handleMessage' problem

by brubell on Tue Jul 28, 2020 9:22 am

once I have uploaded the sketch to the ESP8266, it connects fine, it will receive the current state of the switch on the dashboard. But when I change the state of the switch, nothing happens, there is no change in the serial monitor. But if I reset the ESP8266, it will then receive the changed state once it has reconnected to Adafruit IO.


Does the sketch initially connect to Adafruit IO?

Could you post your code - please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials..

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

Re: IO Output 'handleMessage' problem

by Buddyboy75 on Sun Aug 02, 2020 3:42 am

Hi Brubell

Im using the standard adafruit Digital Output sketch:-

For Connection:-

#define IO_USERNAME "My_username"
#define IO_KEY "My_key"

#define WIFI_SSID "My_ssid"
#define WIFI_PASS "My_password"

#include "AdafruitIO_WiFi.h"
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);

Main Sketch-:

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

#include "config.h"

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

// digital pin 0
#define RELAY4 0

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

void setup() {

pinMode(RELAY4, 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 'digital' feed.
// the handleMessage function (defined below)
// will be called whenever a message is
// received from adafruit io.
EntranceLight->onMessage(handleMessage);

// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}

// we are connected
Serial.println();
Serial.println(io.statusText());
EntranceLight->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 'digital' feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {

Serial.print("received <- ");

if(data->toPinLevel() == HIGH)
Serial.println("HIGH");
else
Serial.println("LOW");


digitalWrite(RELAY4, data->toPinLevel());
}

I just cant seem to pinpoint what im doing wrong.

Buddyboy75
 
Posts: 4
Joined: Wed Jan 29, 2020 6:35 am

Re: IO Output 'handleMessage' problem

by Buddyboy75 on Sun Aug 02, 2020 4:37 am

Yes it connects with adafruit IO fine, the serial monitor shows me what state the dashboard is in ie. "High" or "Low".

But when I click the button on the IO dashboard, nothing happens with the 8266, also no change on the serial monitor. But if I press the reset on my relay, the 8266 then receives the change state from adafruit IO.

For some reason, its not continuously refreshing, so will not recieve a change of state from adafruit IO, not with out pressing reset on my relay.,

Buddyboy75
 
Posts: 4
Joined: Wed Jan 29, 2020 6:35 am

Re: IO Output 'handleMessage' problem

by brubell on Mon Aug 03, 2020 9:41 am

Buddyboy75 wrote:Yes it connects with adafruit IO fine, the serial monitor shows me what state the dashboard is in ie. "High" or "Low".

But when I click the button on the IO dashboard, nothing happens with the 8266, also no change on the serial monitor. But if I press the reset on my relay, the 8266 then receives the change state from adafruit IO.

For some reason, its not continuously refreshing, so will not recieve a change of state from adafruit IO, not with out pressing reset on my relay.,

Is the toggle button on your dashboard set up similar to this page: https://learn.adafruit.com/adafruit-io- ... -2236585-7

Note that the Button On Text is 1 and the Button Off Text is 0

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

Re: IO Output 'handleMessage' problem

by Buddyboy75 on Mon Aug 03, 2020 6:37 pm

Hi Brubell

Yes, i have made sure that the switch sends 1 & 0. I have updated all files on the IDE, when I get home tonight im gonna go through everything again, see if I can nut this out, its such a simple setup, shouldnt be too hard to sort.
Attachments
Screenshot_20200804-082216_Chrome.jpg
Screenshot_20200804-082216_Chrome.jpg (184.46 KiB) Viewed 8 times

Buddyboy75
 
Posts: 4
Joined: Wed Jan 29, 2020 6:35 am

Please be positive and constructive with your questions and comments.