fauxmo.onMessage

So i was working on a project with alexa and I got this error message

Arduino: 1.8.6 (Mac OS X), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

/Users/akohanteb2022/Downloads/ESP8266-Wemo-master/ESP8266-Alexa/ESP8266-Alexa.ino: In function 'void setup()':
ESP8266-Alexa:79:10: error: 'class fauxmoESP' has no member named 'onmessage'
   fauxmo.onmessage(callback);
          ^
exit status 1
'class fauxmoESP' has no member named 'onmessage'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

and I dont know how to fix it. Here is the code:

#include <Arduino.h>
#include <Adafruit_ESP8266.h>
#include <fauxmoESP.h>

// -----------------------------------------------------------------------------
// Wifi Credentials
// -----------------------------------------------------------------------------

#define WIFI_SSID "xx"
#define WIFI_PASS "xx"

#define SERIAL_BAUDRATE 115200

fauxmoESP fauxmo;

// -----------------------------------------------------------------------------
// Wifi
// -----------------------------------------------------------------------------


void wifiSetup() {
  // Set WIFI module to STA mode
  WiFi.mode(WIFI_STA);

  // Connect
  Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  // Wait
  while (WiFi.status() != WL_CONNECTED) {
      Serial.print(".");
      delay(100);
  }
  Serial.println();

  // Connected!
  Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}

// -----------------------------------------------------------------------------
// Initilize Pins
// -----------------------------------------------------------------------------

#define RELAY_PIN1 13
#define RELAY_PIN2 2
#define RELAY_PIN3 14
#define RELAY_PIN4 15

void setup() {
  //initialize relay pins
  pinMode(RELAY_PIN1, OUTPUT);
  digitalWrite(RELAY_PIN1, LOW);
  pinMode(RELAY_PIN2, OUTPUT);
  digitalWrite(RELAY_PIN2, LOW);
  pinMode(RELAY_PIN3, OUTPUT);
  digitalWrite(RELAY_PIN3, LOW);
  pinMode(RELAY_PIN4, OUTPUT);
  digitalWrite(RELAY_PIN4, LOW);
  
    // Init serial port and clean garbage
    Serial.begin(SERIAL_BAUDRATE);
    Serial.println();
    Serial.println();
    Serial.println("FauxMo demo sketch");
    Serial.println("After connection, ask Alexa/Echo to 'turn pixels on' or 'off' or 'turn relay on' or 'off'");

  // Wifi
  wifiSetup();

// -----------------------------------------------------------------------------
// Alexa Device Names
// -----------------------------------------------------------------------------

  // Fauxmo
  fauxmo.addDevice("TV");
  fauxmo.addDevice("GregsNetflix");
  fauxmo.addDevice("Sleep");
  fauxmo.addDevice("Office");
//  fauxmo.onMessage(callback);
}

// -----------------------------------------------------------------------------
// Alexa Operation Calls
// -----------------------------------------------------------------------------

void callback(uint8_t device_id, const char * device_name, bool state) {
  Serial.printf("[MAIN] %s state: %s\n", device_name, state ? "ON" : "OFF");
  
  if ( (strcmp(device_name, "TV") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(RELAY_PIN1, HIGH);
    } else {
      digitalWrite(RELAY_PIN1, HIGH);
    }
  }
  
  if ( (strcmp(device_name, "GregsNetflix") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(RELAY_PIN2, HIGH);
    } else {
      digitalWrite(RELAY_PIN2, LOW);
    }
  }
  
  if ( (strcmp(device_name, "Sleep") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(RELAY_PIN3, HIGH);
    } else {
      digitalWrite(RELAY_PIN3, LOW);
    }
  }

  if ( (strcmp(device_name, "Office") == 0) ) {
    // adjust the relay immediately!
    if (state) {
      digitalWrite(RELAY_PIN4, HIGH);
    } else {
      digitalWrite(RELAY_PIN4, LOW);
    }
  }
}

void loop() {
  fauxmo.handle();
  delay(500);
  digitalWrite(RELAY_PIN1, LOW);
  digitalWrite(RELAY_PIN2, LOW);
  digitalWrite(RELAY_PIN3, LOW);
  digitalWrite(RELAY_PIN4, LOW);
}

ANY HELP IS APPRECIATED!!!

Where did you get the idea that the library has a method called onmessage ?

Look in the fauxmoESP.h file to see which methods are available

Hello!

Have the same issue and I have no clue how to solve the issue:

#include <Arduino.h>
#include <fauxmoESP.h>
#include <ESP8266WiFi.h>

#define WIFI_SSID "******"
#define WIFI_PASS "******"
#define SERIAL_BAUDRATE 115200

fauxmoESP fauxmo;

// -----------------------------------------------------------------------------
// Wifi
// -----------------------------------------------------------------------------

void wifiSetup() {

// Set WIFI module to STA mode
WiFi.mode(WIFI_STA);

// Connect
Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);

// Wait
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
Serial.println();

// Connected!
Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}

void callback(uint8_t device_id, const char * device_name, bool state) {
Serial.print("Device "); Serial.print(device_name); 
Serial.print(" state: ");
if (state) {
Serial.println("ON");
digitalWrite(D2,HIGH);
} else {
Serial.println("OFF");
digitalWrite(D2,LOW);
}
}

void setup() {
// Init serial port and clean garbage
Serial.begin(SERIAL_BAUDRATE);
Serial.println("FauxMo demo sketch");
Serial.println("After connection, ask Alexa/Echo to 'turn <devicename> on' or 'off'");

pinMode(D2,OUTPUT);

// Wifi
wifiSetup();

// Fauxmo
fauxmo.addDevice("Fish Tank");
fauxmo.onMessage(callback);
}

void loop() {
fauxmo.handle();
}

Do you really have the same error?
The other guy seems to have had a problem with camelCase.

Please post your error message(s)

As per reply #1 there is no onMessage method in the faxuMoESP library.

It looks like you and the original poster are both borrowing code from this guide at the Adafruit website.

I don't know what happened for sure, but it looks like the library has changed and the Adafruit website is out of date.

Maybe you can get hold of an old version of the library that still has the onMessage method.

Hello!

Here is the error message:

Arduino: 1.8.7 (Windows 7), Board: "WeMos D1 R2 & mini, 80 MHz, 115200, 4M (3M SPIFFS)"

C:\Users\616320\Desktop\Fish_TANK\Fish_TANK.ino: In function 'void setup()':

Fish_TANK:62:16: error: 'class fauxmoESP' has no member named 'onMessage'

fauxmo.onMessage(callback);

^

Multiple libraries were found for "fauxmoESP.h"
Used: C:\Users\616320\Documents\Arduino\libraries\fauxmoesp
Not used: C:\Users\616320\Documents\Arduino\libraries\xoseperez-fauxmoesp-3b05b7b7f111
Not used: C:\Users\616320\Documents\Arduino\libraries\fauxmoesp.h
exit status 1
'class fauxmoESP' has no member named 'onMessage'

Invalid library found in C:\Users\616320\Documents\Arduino\libraries\Arduino-master: no headers files (.h) found in C:\Users\616320\Documents\Arduino\libraries\Arduino-master
Invalid library found in C:\Users\616320\Documents\Arduino\libraries\ESP8266: no headers files (.h) found in C:\Users\616320\Documents\Arduino\libraries\ESP8266
Invalid library found in C:\Users\616320\Documents\Arduino\libraries\Arduino-master: no headers files (.h) found in C:\Users\616320\Documents\Arduino\libraries\Arduino-master
Invalid library found in C:\Users\616320\Documents\Arduino\libraries\ESP8266: no headers files (.h) found in C:\Users\616320\Documents\Arduino\libraries\ESP8266

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Fish_TANK:62:16: error: 'class fauxmoESP' has no member named 'onMessage'

As previously noted the fauxmoESP library has no function named onMessage, hence the error message.

Please post the fauxmoESP.h file here

/*

FAUXMO ESP

Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*/

#pragma once

#define UDP_MULTICAST_IP IPAddress(239,255,255,250)
#define UDP_MULTICAST_PORT 1900
#define TCP_MAX_CLIENTS 10
#define TCP_PORT 1901

#ifdef DEBUG_FAUXMO
#define DEBUG_MSG_FAUXMO(fmt, ...) { static const char pfmt[] PROGMEM = fmt; DEBUG_FAUXMO.printf_P(pfmt, ## __VA_ARGS__); }
#else
#define DEBUG_MSG_FAUXMO(...)
#endif

#ifndef DEBUG_FAUXMO_VERBOSE
#define DEBUG_FAUXMO_VERBOSE false
#endif

#include <Arduino.h>

#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <AsyncTCP.h>
#else
#error Platform not supported
#endif

#include <WiFiUdp.h>
#include <functional>
#include <vector>
#include <templates.h>

typedef std::function<void(unsigned char, const char *, bool, unsigned char)> TSetStateCallback;

typedef struct {
char * name;
bool state;
unsigned char value;
} fauxmoesp_device_t;

class fauxmoESP {

public:

unsigned char addDevice(const char * device_name);
bool renameDevice(unsigned char id, const char * device_name);
char * getDeviceName(unsigned char id, char * buffer, size_t len);
void onSetState(TSetStateCallback fn) { _setCallback = fn; }
void enable(bool enable);
void handle();

private:

AsyncServer * _server;
bool _enabled = true;
std::vector<fauxmoesp_device_t> _devices;
#ifdef ESP8266
WiFiEventHandler _handler;
#endif
WiFiUDP _udp;
AsyncClient * _tcpClients[TCP_MAX_CLIENTS];
TSetStateCallback _setCallback = NULL;

String _deviceJson(unsigned char id);

void _handleUDP();
void _onUDPData(const IPAddress remoteIP, unsigned int remotePort, void *data, size_t len);
void _sendUDPResponse();

void _onTCPClient(AsyncClient *client);
void _onTCPData(AsyncClient *client, void *data, size_t len);
void _onTCPDescription(AsyncClient *client, void *data, size_t len);
void _onTCPList(AsyncClient *client, void *data, size_t len);
void _onTCPControl(AsyncClient *client, void *data, size_t len);
void _sendTCPResponse(AsyncClient *client, const char * code, char * body, const char * mime);

};

Here's an extract from the changelog in that library.

## [2.3.0] 2017-11-08
...
### Deprecated
- Use onSetState callback instead of onMessage callback
- Use onGetState callback instead of setState method

I can't tell if it's a straight name change, but it looks like the onMessage has been replaced by onSetState.

{edit - date of changelog entry added}

1 Like

As suspect the library has no function named onMessage() so it looks like it has either been changed or there is more than one version of it