Go Down

Topic: fauxmo.onMessage (Read 472 times) previous topic - next topic

ArshiaKO

Oct 12, 2018, 06:48 am Last Edit: Oct 12, 2018, 06:50 am by ArshiaKO
So i was working on a project with alexa and I got this error message
Code: [Select]

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:
Code: [Select]

#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!!!

UKHeliBob

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
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up