0

error: 'handleMessage' was not declared in this scope
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

error: 'handleMessage' was not declared in this scope

by Loddepus on Wed Jun 26, 2019 12:25 pm

Im new in Adafruit IO and have just got a digital input "command"-feed-tutorial from Instructables to work with NodeMCU and send message to my android.
Now I have made a new analog feed in Adafruit IO called "HjemmeTemperatur".
I copied a code from this tutorial :
https://learn.adafruit.com/adafruit-io- ... duino-code.
I changed the feed name references ("command") in the original code as shown below, but i get this error:

"Wifi_Tempsensor_ERROR:47:31: error: 'handleMessage' was not declared in this scope
HjemmeTemperatur->onMessage(handleMessage);
exit status 1
'handleMessage' was not declared in this scope
"
Tutorial does not show where to declare this. Is it wrong to substitute the feed name !? Please help me...

Code: Select all | TOGGLE FULL SIZE
/************************ Adafruit IO Configuration *******************************/

// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME    ""
#define IO_KEY         ""

/******************************* WIFI Configuration **************************************/

#define WIFI_SSID       ""
#define WIFI_PASS       ""

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

/************************ Main Program Starts Here *******************************/
#include <ESP8266WiFi.h>
#include <AdafruitIO.h>
#include <Adafruit_MQTT.h>
#include <ArduinoHttpClient.h>

// analog pin 0
#define TEMP_PIN A0

// button state
int current = 0;
int last = -1;

// set up the 'HjemmeTemperatur' feed
// adapted from https://learn.adafruit.com/adafruit-io-basics-analog-output/arduino-code
AdafruitIO_Feed *HjemmeTemperatur = io.feed("HjemmeTemperatur");

void setup() {

  // start the serial connection
  Serial.begin(115200);
 
  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();


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


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

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

  // grab the current state of the Temp-sensor
  current = analogRead(TEMP_PIN);
  // return if the value hasn't changed
  if (current == last)
    return;

  // save the current state to the 'HjemmeTemperatur' feed on adafruit io
  Serial.print("sending value -> ");
  Serial.println(current);
  HjemmeTemperatur->save(current);

  // store last Temp-sensor value
  last = current;
  delay(1000);
}


Thank you for helping me !

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

Re: error: 'handleMessage' was not declared in this scope

by abachman on Wed Jun 26, 2019 1:27 pm

hi Loddepus,


The code you pasted makes reference to "the handleMessage function". In the learn guide code, that function is defined in the block of code that looks like this:
Code: Select all | TOGGLE FULL SIZE
// this function is called whenever an 'analog' message
// is received from Adafruit IO. it was attached to
// the analog feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {
 
  // convert the data to integer
  int reading = data->toInt();
 
  Serial.print("received <- ");
  Serial.println(reading);
  analogWrite(LED_PIN, reading);
 
}


You can seen the whole example sketch by using the Arduino app File menu, going to Examples, finding the Adafruit_IO_Arduino library, and clicking on `adafruitio_09_analog_out`.


- adam b.

(PS - i edited your post to insert
Code: Select all | TOGGLE FULL SIZE
[code][/code]
tags around the code sample)

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

Re: error: 'handleMessage' was not declared in this scope

by Loddepus on Thu Jun 27, 2019 2:57 am

Thank you abachman for guiding to the right tutorial. I have missed something there.

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

Re: error: 'handleMessage' was not declared in this scope

by Loddepus on Thu Jun 27, 2019 6:10 am

Hi again abachman.
Now I had time to look in the code you guided me to. To me it seems that I basicly miss this declaration:
Code: Select all | TOGGLE FULL SIZE
void handleMessage(AdafruitIO_Data *data) {....
.
Is that right ?
The rest of my proposed code could be used with minor changes according to "Adafruit IO Analog Out Example" code ?
I wonder if the part of code that referes to ESP32 will work when I use NodeMCU-board ?

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

Re: error: 'handleMessage' was not declared in this scope

by brubell on Thu Jun 27, 2019 10:43 am

Is that right ?
The rest of my proposed code could be used with minor changes according to "Adafruit IO Analog Out Example" code ?

It should work after you add the handlemessage function.

I wonder if the part of code that referes to ESP32 will work when I use NodeMCU-board ?

The code you posted uses the ESP8266 WiFi library, it won't work with an ESP32 as it'll need to use the ESP32 WiFi library.

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

Re: error: 'handleMessage' was not declared in this scope

by Loddepus on Thu Jun 27, 2019 3:56 pm

Hi brubell.
I did follow the "Adafruit IO Analog Out Example" exactly today , and it worked. I also added a servo and made to control it from my phone.
Thanks to both of you !

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

Re: error: 'handleMessage' was not declared in this scope

by calimacaco on Mon Jul 08, 2019 1:42 am

Im new in Adafruit,
I have a nodemcu ver.3 and a fingerprint, I use the liberira circuitpython, I follow the instructions to be able to enrrolar using:
https://learn.adafruit.com/adafruit-opt ... cuitpython

but when I download it to nodemcu it shows me the following error:

ValueError: Pin U0RXD in use
you can guide me

Thank you.

calimacaco
 
Posts: 1
Joined: Thu Oct 03, 2013 7:14 pm

Re: error: 'handleMessage' was not declared in this scope

by brubell on Mon Jul 08, 2019 10:21 am

calimacaco wrote:Im new in Adafruit,
I have a nodemcu ver.3 and a fingerprint, I use the liberira circuitpython, I follow the instructions to be able to enrrolar using:
https://learn.adafruit.com/adafruit-opt ... cuitpython

but when I download it to nodemcu it shows me the following error:

ValueError: Pin U0RXD in use
you can guide me

Thank you.


Please open an issue on the CircuitPython library for this sensor: https://github.com/adafruit/Adafruit_Ci ... int/issues

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

Please be positive and constructive with your questions and comments.