vintlabs / fauxmoESP

Add voice control of your ESP32 and ESP8266 devices using Amazon Alexa
MIT License
383 stars 69 forks source link

Trying to use depricated sketch from <v2.4 #85

Closed pvint closed 3 years ago

pvint commented 5 years ago

Original report by Andrew Taylor (Bitbucket: taylortech, GitHub: taylortech).


I found this sketch to allow alexa to run a servo to push a button (from iliketomakestuff) on youtube. Since the update with OnMessage and SetState, It's not compliling.

Can you help to fix my code to work with the new version? I'm trying to make a tutorial on this.

Thank you!

Here's the code:

/**

*This example code is built from the library and example code below and is provided WITH NO SUPPORT

/ Network credentials /

define WIFI_SSID "$$$$$$"

define WIFI_PASS "$$$$$$"

define SERIAL_BAUDRATE 115200 //this is important to set in the Arduino IDE

bool resetMe=false; int beginVal=0;

/ Belkin WeMo emulation / fauxmoESP fauxmo; Servo myservo; // create servo object to control a servo

void setup() { Serial.begin(SERIAL_BAUDRATE); //setup and wifi connection wifiSetup(); pinMode(D4, OUTPUT); myservo.attach(2); beginVal = myservo.read(); // Device Names for Simulated Wemo switches fauxmo.addDevice("finger"); fauxmo.onSetState(callback); }

void loop() { if(resetMe){ delay(1000); Serial.println("reset the servo"); myservo.write(0); resetMe=false; } fauxmo.handle(); }

/ --------------------------------------------------------------------------- Device Callback ----------------------------------------------------------------------------/ 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"); } else { Serial.println("OFF"); }

//Switching action on detection of device name, useful for adding //multiple "devices" to a single ESP unit.

if ( (strcmp(device_name, "finger") == 0) ) { if (state) { int newVal = beginVal+15; myservo.write(newVal); resetMe=true; Serial.println("ok");
} else{ myservo.write(beginVal); }

}

}

void moveServo(int val){ Serial.println("moveServo"); //if you need to scale from a potentiometer to use it with the servo (value between 0 and 180) //val = map(val, 0, 1023, 0, 180);
myservo.write(val); }

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

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

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

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

pvint commented 5 years ago

Original comment by Jamie curtis (Bitbucket: [Jamie curtis](https://bitbucket.org/Jamie curtis), ).


Hi @{557058:f34549b7-88ca-4a74-8bd7-2fc8e49340fa}

Just wondering if you got anywhere with this. I have just stumbled upon the same code and would like to use it

I managed to get it compiled and uploaded to the board using old versions of this plugin and the board manager and I can discover it. However I'm getting errors in the Alexa app saying the device is not responding and there was a problem. Not sure how to look into this though.

pvint commented 5 years ago

Original comment by Andrew Taylor (Bitbucket: taylortech, GitHub: taylortech).


I did get it working with a bit of modification.

Here's a link to the video I ended up making: https://youtu.be/U4VhSzwqsxk

Hope that helps you!