vintlabs / fauxmoESP

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

ESP restart from eeprom name #21

Closed pvint closed 7 years ago

pvint commented 7 years ago

Original report by Julian Kuhn (Bitbucket: [Julian Kuhn](https://bitbucket.org/Julian Kuhn), ).


Hi there,

First: thanks for this Great Library

Actually i Write the alexaname to eeprom, then read the string and insert by "const char* alexaname = eepromname.c_str();" to "fauxmo.addDevice(alexaname);"

The printed String is like the string i write to eeprom...

But: if i Start Scanning for Smart home devices on alexa my ESP crashes... every time :(

Whats wrong?

pvint commented 7 years ago

Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).


Could you please paste the code here or in a gist? I guess eepromname is a String object and it should not be relevant where it comes from...

pvint commented 7 years ago

Original comment by Julian Kuhn (Bitbucket: [Julian Kuhn](https://bitbucket.org/Julian Kuhn), ).


Hi Xose, thanks for your reply.

maybe i am doing something wrong but... if i dont know what...

#!arduino

const char* alexaName = "Doorlamp";

// alexaName
// ========================================
String eAlexaName = "";
eAlexaName = eepromRead(100,119,"Alexaname");
if( eAlexaName != "" ) {
    alexaName = eAlexaName.c_str();
}

// eepromRead
// =============================================
String eepromRead( byte from, byte to, String name ) {
    String value;
    for (int i = from; i < to; ++i) {
        if( EEPROM.read(i) != NULL ) {
            value += char(EEPROM.read(i));
        }
    }
    return value;
}

// addDevice
fauxmo.addDevice( alexaName );

KR

pvint commented 7 years ago

Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).


Without testing it I see you are trying to modify a "const char " which is not ment for that since it's "const". You are trying to do it by assigning a new value, that doesn't work for char. And even if you could that variable is 9 bytes long and the string from EEPROM is 10 bytes long (both including the tail \0). Why don't you just:

#!cpp
String alexaName = eepromRead(100,119,""); // the final parameter is not used, could be removed
if (alexaName.length() == 0) alexaName = String("Doorlamp");
fauxmo.addDevice(alexaName.c_str());

Please review code, I have not tested it.

pvint commented 7 years ago

Original comment by Julian Kuhn (Bitbucket: [Julian Kuhn](https://bitbucket.org/Julian Kuhn), ).


I i just... stupid ahhhwwww...

thanx for your reply, i solved it with your help. The vars are now Strings and i insert them with alexaName.c_str()

It works fine now... thx ;)

#!arduino

String alexaName = "Doorlamp";

// alexaName
// ========================================
String eAlexaName = "";
eAlexaName = eepromRead(100,119,"Alexaname");
if( eAlexaName != "" ) {
    alexaName = eAlexaName;
}

// eepromRead
// =============================================
String eepromRead( byte from, byte to, String name ) {
    String value;
    for (int i = from; i < to; ++i) {
        if( EEPROM.read(i) != NULL ) {
            value += char(EEPROM.read(i));
        }
    }
    return value;
}

// addDevice
fauxmo.addDevice( alexaName.c_str() );

You did a great job with this library!!! Will there be an update for asking status of a device or adding google home?

pvint commented 7 years ago

Original comment by Julian Kuhn (Bitbucket: [Julian Kuhn](https://bitbucket.org/Julian Kuhn), ).


solved

pvint commented 7 years ago

Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).


The status of the device is already implemented in the dev branch, using the same protocol the wemo switches use. The integration with Google Home will not likely be part of the library, but I recently wrote a post about how to do it with a device that supports HTTP requests: http://tinkerman.cat/using-google-assistant-control-your-esp8266-devices/

pvint commented 7 years ago

Original comment by Julian Kuhn (Bitbucket: [Julian Kuhn](https://bitbucket.org/Julian Kuhn), ).


Ok perfect so i will update the library, thank you.

You mean the way via IFTTT? Hm thats not my favorite... :(

pvint commented 7 years ago

Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).


Yeah, I know what you mean, but it's the suggested way by google.