kakopappa/arduino-esp8266-alexa-wemo-switch

Sonoff switch

shenery opened this issue · 91 comments

Do you think this code could modified to work with the sonoff switch. http://blog.squix.org/2016/01/esp8266-products-hitting-market.html

It has 1M of flash and uses esp8266

Or do you think it will just work? I'm getting one to test in the next couple of weeks.

It works fine on a sonoff. I just used the arduino ide software to program it - I used the nodemcu.9v on the arduino type - I use them with the alexa echo dot

Great pieces of software...

Joe

I received 4 today and had a quick go. Using arduino I had it on generic esp8266 board and 1m flash. I changed the relay pin to pin 12 in the code and was getting error esp com mem failed or something like that. Was the pin number all you changed? And do I have to change the board type to nodemcu 9v and that will be me sorted? Really excited about this. An Alexa switch for £5! :-)

I used a fdti 3.3v

I also use a ftdi 3.3v as the programmer.
I tried type as a generic 1meg flash but got reboot problems.
So I used the nodemcu.9 choice.

Change the ssid
Change password
Change device name to (your choice)

Pins
I use d6 for the relay and d7 for the led.(optional)

Joe

On Mon, Nov 14, 2016 at 6:12 PM, shenery notifications@github.com wrote:

I used a fdti 3.3v


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AWDpY8E2NrAWaVDSVncauzQh4zxYCaCKks5q-NzSgaJpZM4KoUCC
.

The esp mem code error -likely means your device is not in flash mode

TO flash:

Press and hold the button, do not release: while holding it down, plug in
the programmer, then release button.

Joe

On Mon, Nov 14, 2016 at 6:49 PM, joe basque joeman2116@gmail.com wrote:

I also use a ftdi 3.3v as the programmer.
I tried type as a generic 1meg flash but got reboot problems.
So I used the nodemcu.9 choice.

Change the ssid
Change password
Change device name to (your choice)

Pins
I use d6 for the relay and d7 for the led.(optional)

Joe

On Mon, Nov 14, 2016 at 6:12 PM, shenery notifications@github.com wrote:

I used a fdti 3.3v


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AWDpY8E2NrAWaVDSVncauzQh4zxYCaCKks5q-NzSgaJpZM4KoUCC
.

Ok thanks for the advice. I will give it a try today.

Cheers
Steven

I tried nodemcu 0.9 esp-12. 1m spiffs and I'm still getting error mem esp com failed. Also d6 doesn't work for me. Isn't the relay gpio 12? It doesn't even compile when I have it as d6 but when I change to 12 it compiles fine.

D6 not d6 - my mistake gpio12 is D6

Ok, mem esp error - well that is a serial comm problem which means unit is
not in pgm mode or your wire of the tx and rx pins on your ftdi may not be
correct to the sonoff.

I leave the nodemcu .9 at 3m spiffs but 1meg is fine... The error your
displaying is not related to those selections.

It is a communication issue related to wiring and or not in correct mode to
flash.

Joe

On Tue, Nov 15, 2016 at 3:46 AM, shenery notifications@github.com wrote:

I tried nodemcu 0.9 esp-12. 1m spiffs and I'm still getting error mem esp
com failed. Also d6 doesn't work for me. Isn't the relay gpio 12? It
doesn't even compile when I have it as d6 but when I change to 12 it
compiles fine.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AWDpY8mGgkHGQf1Je0eUjP13SLlFvtfmks5q-WNCgaJpZM4KoUCC
.

Ok so I've been spending a bit more time on this. I have all your settings loaded. I have a fT232RL ftdi like this on http://m.ebay.co.uk/itm/Latest-Version-FT232BL-FTDI-USB-to-TTL-Serial-Adapter-for-Arduino-UK-Seller-/181797979805?nav=SEARCH connected to the sonoff. All wires connected and have been checked numerous times. I have it plugged into my tablet via USB otg and I have also tried through a powered USB hub and I am still getting the espcomm mem failed error. I occasionally get a java lang nullpointerexception error as well. Do you think it could be a power supply issue? Kind regards
Steven

Also I press the button on the sonos and keep holding it until I plug it in to the tablet and there is no blinking led. I assume that's me in flash mode?

It still appears your system is not in flash mode.
Your steps look fine.

  1. Make sure you have selected the correct serial port.. Check windows
    system manager under com ports.
    2 Make sure the serial monitor is not open.

Joe

On Thu, Nov 17, 2016, 1:52 PM shenery notifications@github.com wrote:

Also I press the button on the sonos and keep holding it until I plug it
in to the tablet and there is no blinking led. I assume that's me in flash
mode?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AWDpY0zIb6cBhDdvoGljj60zVHc_wmI5ks5q_JRYgaJpZM4KoUCC
.

The powersupply will not usually be a problem when doing a flash
It mostly acts up when the esp8266 is running and using the sotware and
wifi.

For your programmer, tx am rx are the typical error area. If all fails
revese the tx and rx wires
Programming note:
Vcc 3.3v
Gnd
Tx
Rx
Are the only wires required.

Joe

On Thu, Nov 17, 2016, 2:20 PM joe basque joeman2116@gmail.com wrote:

It still appears your system is not in flash mode.
Your steps look fine.

  1. Make sure you have selected the correct serial port.. Check windows
    system manager under com ports.
    2 Make sure the serial monitor is not open.

Joe

On Thu, Nov 17, 2016, 1:52 PM shenery notifications@github.com wrote:

Also I press the button on the sonos and keep holding it until I plug it
in to the tablet and there is no blinking led. I assume that's me in flash
mode?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AWDpY0zIb6cBhDdvoGljj60zVHc_wmI5ks5q_JRYgaJpZM4KoUCC
.

I've tried all of that. Jumper is on the 3.3v. Vcc is the 3.3v. Checked in device manager which com port is recognised when I connect. Serial monitor window not opened. I saw on this forum that some people were getting the same error and fixed it with clearing the flash with esptool before flashing the new firmware? Do you have any experience with this? I can't see esptool in the programmer of arduino ide.

Well all sounds good
I have used esptool to clear mem. Esptool is another program. Just google
and download

Sometimes an esp wont work so i use the esptool to refresh it.

Wish you had another regular esp nodemcu to see if you could flash it.
Since they have the programmer builtin, this would establish your serial
programmer is good.
Have you ever successfully flashed any esp8266?

On Fri, Nov 18, 2016, 3:06 PM shenery notifications@github.com wrote:

Sorry forgot to post the forum.
http://tech.scargill.net/itead-slampher-and-sonoff/


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AWDpYxSfyV16Id-rc1LAeQNYue3kkh_xks5q_fcqgaJpZM4KoUCC
.

ok so I got a bit further today. I got this.
83936 bytes from C:\Users\Shenery\AppData\Local\Temp\arduino_build_786479/sinric.ino.bin to flash at 0x00000000
erasing flash
size: 045520 address: 000000
first_sector_index: 0
total_sector_count: 70
head_sector_count: 16
adjusted_sector_count: 54
erase_size: 036000
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
setting serial port timeouts to 15000 ms
setting serial port timeouts to 1000 ms
espcomm_send_command: receiving 2 bytes of data
writing flash
................................................................................ [ 28% ]
................................................................................ [ 57% ]
................................................................................ [ 86% ]
...................................... [ 100% ]
starting app without reboot
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
espcomm_send_command: receiving 2 bytes of data
closing bootloader
flush start
setting serial port timeouts to 1 ms
setting serial port timeouts to 1000 ms
flush complete
I plugged in a lamp and I get nothing though.

when I bring up serial monitor it says f5, fo, f5 f0 and there is no indication that the esp is connected to my network. when scan my network there is no esp device

I set up esptool but not 100% of the command to use to clear the flash. Tried a few but didn't work. I have a blank.bin file saved in the esptool directory. I have installed team viewer and could maybe try that over the weekend if you have time. If you have a command to use in esptool though I could try that?

Kind regards
Steven

And when I try the erase flash command in esptool I get esptool error: argument --port/-p: expected one argument

Ok so I've been having fun getting this going. I found the right command for esptool and have cleared the flash, I was then able to upload the firmware again. I've realised that there is a certain way that you have to wire the lamp in to so that the sonoff is powered via the mains. I scanned devices in alexa and it found my lamp. I asked Alexa to turn on box and she replied ok. But nothing happens the light stays off. I have tested the fuse the bulb and tried in another lamp but it doesn't turn on and I've no idea why.
I'm nearly there but not sure what to do next.

Scrap that last post. I forgot to change the gpio pin again and now it works. If anyone's having bother esptool helped out a lot. Basically in my experience you have to use esptool to clear flash before you upload this code. Thank you joeman for all your help it works perfect no :-)

Yeah it works really good.
My wifis been down all day. What a coincidence eh? Lol. This happening has gave me anurgancy to try and work out how to override the relay with say a hardware switch or maybe you can use the program button?
Has anyone done this that you know of?

Kind
Regards

You can use a push button.
https://www.arduino.cc/en/tutorial/switch

when HIGH call turnOnRelay();
when LOW call turnOffRelay();

I'm not very good with adding code so not sure where to put it in the script. Where would it go? And would I be able to use the program button on gpio 0 for this? If not would the switch go at the mains side or the lamp side?

Kind regards
Steven

I have found this piece of code from sonoff boilerplate firmware. Looks like the code to use the button on gpio 0 to switch the relay.
Can I just add this somewhere in the code?
//delay(200);
//Serial.println(digitalRead(SONOFF_BUTTON));
switch (cmd) {
case CMD_WAIT:
break;
case CMD_BUTTON_CHANGE:
int currentState = digitalRead(SONOFF_BUTTON);
if (currentState != buttonState) {
if (buttonState == LOW && currentState == HIGH) {
long duration = millis() - startPress;
if (duration < 1000) {
Serial.println("short press - toggle relay");
toggle();
} else if (duration < 5000) {
Serial.println("medium press - reset");
restart();
} else if (duration < 60000) {
Serial.println("long press - reset settings");
reset();
}
} else if (buttonState == HIGH && currentState == LOW) {
startPress = millis();
}
buttonState = currentState;
}
break;
}

}

https://github.com/tzapu/SonoffBoilerplate/blob/master/SonoffBoilerplate.ino

I tried out this code last night. It works fine for tactile switches. I tried it with one of those cheapo switches with a spring. It worked but there was a lot of rapid turn on / off because there is no debounce in the code.

Hello,

I need the compiled bin file of sinric.ino. Can please someone send it to my mail? burhant@gmail.com

So where dose this code go in order to make the button work?

//delay(200);
//Serial.println(digitalRead(SONOFF_BUTTON));
switch (cmd) {
case CMD_WAIT:
break;
case CMD_BUTTON_CHANGE:
int currentState = digitalRead(SONOFF_BUTTON);
if (currentState != buttonState) {
if (buttonState == LOW && currentState == HIGH) {
long duration = millis() - startPress;
if (duration < 1000) {
Serial.println("short press - toggle relay");
toggle();
} else if (duration < 5000) {
Serial.println("medium press - reset");
restart();
} else if (duration < 60000) {
Serial.println("long press - reset settings");
reset();
}
} else if (buttonState == HIGH && currentState == LOW) {
startPress = millis();
}
buttonState = currentState;
}
break;
}

}

I'm not sure either I haven't had time to try and get it working. Not sure if @joeman2116 might have it working. I'm sure he said some thing about having the led working but not sure about the button.

If you or any1 else manages to sort it please let me know. Thank you

Been finishing a 4 channel multiswitch with the new code, been busy.. But it all working now.

As for adding switch control,
Have not looked at the best place for the code
But expect one could make it a declared as a void routine and then call the routine inside void setup.
I will try to test later

Joe

Any luck Joe?

He Joe. Hope you've had a good Christmas. Did you manage to get any further with the switch on the sonoff. I have worked out a way to attach a switch to the relay but it's a bit clumsy. Utalising the button on the sonoff would be a lot better.

Does anyone know if this code will work with the sonoff dual switch. It looks like the dual has two places to upload code. I was wondering if this is just two device put on one board. Does anyone know?

@shenery How did you clear the flash using esptool? I am having similar issues you had before clearing flash.

Thanks in advance.

@yaydogan if you have python set up in Windows I used this code to get it to working changing the port number. CD in to the location where ESP tool is and enter this. python esptool.py -p com6 erase_flash

@shenery

I've modified the sketch to add a momentary switch to D2, and to send the state to the serial port. The code is rudimentary, but it works and is stable.

The only problem I have is that the initial connection to WiFi is not reliable - it times-out - so then have to manually reset. I've increased the loop count from 10 to 20, to try to give it more time to connect.

I don't know how to save this in a proper GitHub repository. If it helps, sketch is below...

Best
Abdul-Khaliq

UPDATE 18 Jan 2017 - Posted Sketch removed due to Github Markdown rendering introducing errors in the text. Please see subsequent messages below.

thank you TCRAKN for looking at the code, but im having problems with it.
it will not verify.
Arduino: 1.6.13 (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, 115200, 4M (1M SPIFFS)"

new_sonoff:11: error: #include expects "FILENAME" or

#include

      ^

exit status 1
#include expects "FILENAME" or

can you help me out please.

Hi @Shooter66six

I’ve been compiling successfully for Wemos and NodeMCU with Arduino IDE 1.6.12 (Mac OS X):
Board: NodeMCU 1.0 (ESP-12E Module) 80 MHz, 115200, 4M (3M SPIFFS)

There are a couple of warnings relating to line 163, but it compiles and uploads successfully.

I have since modified the sketch for the Sonoff to take into account Sonoff pin designations for the Relay, Switch and Green LED, but have yet to test it. Once I locate my USB-Serial module, I’ll get right to it. This version also compiles successfully.

Having looked closer at the error you’re experiencing suggests that I may have accidentally deleted part of the #include statement! It should read:

#include < functional > // Note, remove spaces inside <>

Though, omitting this line completely should pose no problems, as this library is part of the ESP8266 Aurduino core toolchain.

My apologies to everyone who might be pulling their hair out!

Abdul-Khaliq

UPDATE
The Github text editor seems to be removing the < functional > portion of the line when displaying the sketch. Editing the post, the full line reappears.

i added then got this
Arduino: 1.6.13 (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, 115200, 4M (1M SPIFFS)"

C:\Users\Scott\Documents\Arduino\sketch_with_switch\sketch_with_switch.ino: In function 'void startHttpServer()':

sketch_with_switch:197: error: expected '}' before ';' token

Serial.println("Got Request index.html ...\n");

                                           ^

sketch_with_switch:197: error: expected ')' before ';' token

C:\Users\Scott\Documents\Arduino\sketch_with_switch\sketch_with_switch.ino: At global scope:

sketch_with_switch:199: error: expected unqualified-id before ')' token

});

^

sketch_with_switch:201: error: 'HTTP' does not name a type

HTTP.on("/upnp/control/basicevent1", HTTP_POST, {

^

sketch_with_switch:225: error: expected unqualified-id before ')' token

});

^

sketch_with_switch:227: error: 'HTTP' does not name a type

HTTP.on("/eventservice.xml", HTTP_GET, {

^

sketch_with_switch:258: error: expected unqualified-id before ')' token

});

^

sketch_with_switch:260: error: 'HTTP' does not name a type

HTTP.on("/setup.xml", HTTP_GET, {

^

sketch_with_switch:295: error: expected unqualified-id before ')' token

});

^

sketch_with_switch:297: error: 'HTTP' does not name a type

HTTP.begin();

^

sketch_with_switch:298: error: 'Serial' does not name a type

Serial.println("HTTP Server started ..");

^

sketch_with_switch:300: error: expected declaration before '}' token

}

^

exit status 1
expected '}' before ';' token

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

@Shooter66six

I'm beginning to think that that wasn't the only change the Github editor has made!

You can download my latest sketch from here:
https://expirebox.com/download/dbeb85ad9b91ebd846e797e59efc2fea.html

It'll expire in a couple of days.

Best
Abdul-Khaliq

that was the problem. the new sketch flashed on first time.
however asking alexa or pressing the switch only momentarily turns off the power, it flicks back on after a second. is that how you did it or is that a fault? also could you make it so it says off insted of flicking off then back on.

also thank you for this Abdul-Khaliq your a top man.

@Shooter66six

It's working fine on my Wemos D1 setup, and the Sonoff isn't much different.

The power-on state of the relay is ON. This is by design, in the instance if power is removed from the Sonoff and reinstated, the relay switches on; e.g. if used with a room light. You can change this by deleting or commenting out line 102 - turnOnRelay(); This is right after void loop()

I don't have my test units with me at the moment, so can't re-flash and re-test.

Can you launch the serial monitor from the Arduino IDE to see what's being reported, and post here?

I've moved around a couple of variable settings for switchState to how it is in my Wemos Sketch, so it may be worth testing this version...
https://expirebox.com/download/53ee16aa62d1a70fadec19b1208b927f.html

Best
Abdul-Khaliq

http://www.filedropper.com/wemoswimo-single-01-sonoff-github

**UPDATE - I see where I've introduced the re-switching-on error. Either remove line 102, or move it into the end of the void setup() function just before the last curly brace! I'm sure that'll fix it. Download above is fixed version. **

I was wondering. Is there a way to control this with a wifi app like Belkin Wemos do so I can also set timers? and.... Is there a way to program it so you can change the Wifi password and SSID by wireless like the Sonoff does before we changed the code? Basically if it were possible, it would be nice if this would emulate the wemo (wemo clone). BTW.... Thanks for your posting and help. This is really awesome!!!!!

@MacGyver1rjq104

@joeman2116 mentions further up this thread that a more configurable version is in the works. Any updates? #6 (comment)

As for an App, I'm not sure if the existing Belkin apps for iOS or Android will recognise broadcasts from this firmware. Can someone report? Maybe all you'd need to issue is a properly framed xml stream to a device via a URL. Perhaps something here might help: https://github.com/issackelly/wemo

An interesting piece of development can be found here: https://bitbucket.org/xoseperez/espurna and could answer many questions. I've not had the chance to test it...

Regards
Abdul-Khaliq

@TCRAKN

Thanks... The https://bitbucket.org/xoseperez/espurna site was the first one I looked at. I didn't understand his methods because he insists on using other programs NOT Arduino which is the one I am familiar with. I spent days trying to figure out what he was doing then I found your version. It's much more direct in explaining the process. Thank you. I am new to C++ so I am struggling to learn. I can usually figure out how to modify bits and pieces but I want to get to a level where I can program from scratch. The best way to learn is to dive in and get familiar with the code and how it works. I am looking forward to seeing the development from @joeman2116

@MacGyver1rjq104

There is a very good Wiki linked to it here: https://bitbucket.org/xoseperez/espurna/wiki/ArduinoIDE.md

It's somewhat thorough, but you're right - there is too much to follow. I will give it a go, but that might be some time away.

I hope my modified version works out for you in the meantime. I can't take any credit to the real work that's behind it working. Yes, I'm looking forward to seeing what @joeman2116 is working on too!

@joeman2116 any teasers?

Best wishes
Abdul-Khaliq

the new sketch works very well as it should. thank you for your hard work Abdul

@Shooter66six

That's great to hear! Sounds like I don't need to do any of my own testing!

Best wishes
Abdul-Khaliq

@Shooter66six So we have a working switch on the sonoff then? Does the black button on the sonoff turn the relay on and off bypassing the WiFi?

@shenery

The sketch posted here:#6 (comment) does this:

  1. On power up, the relay is on, and the green LED is also on.
  2. Invoking Alexa to change the state will also change the state on the LED as per on/off request.
  3. Pressing and releasing the button will change the current state of the LED and relay.
  4. Only on the release of the button will the change take effect.
  5. WiFi connectivity isn't necessary for the button to work.

The link above will expire tomorrow, I think. I'm not sure how to add/fork the original repository into a new one containing this sketch. So, if anyone wants it after the link expires, just drop me a line here.

Best
Abdul-Khaliq

@TCRAKN
Everything is looking great... Quick question.... Do you have a solution for the Sonoff Dual relay? I tried your WeMo multi relay firmware. It finds the device and Identifies two switches on alexa but will not control the relays. I am assuming that I need to identify the D6 pin and what ever the 2nd relay is tied to but I am still learning how to do things like this. Any help, insight is appreciated!!!

@TCRAKN It sounds really good I will try it tomorrow. I have the download saved. On an unrelated post. Do you know if this code could be manipulated by openhab in some way?

Could the sketch be made so it starts as off and turns on momentarily on a click of the switch or alexa command? This could then be flashed onto the 12v sonoff and used to turn on your pc

@MacGyver1rjq104
All my current requirements are for single-relay Sonoffs, so I've had no ned to look into the multi-relay code. I must add, the code is by @kakopappa, so it might be worth dropping Aruna a line.

Sorry I cant help any further.
Abdul-Khaliq

@Shooter66six

Yes, just remove the line turnOnRelay(); at the end of the void setup() { function and change int switchState = 1; to int switchState = 0; just before void setup() {

Best
Abdul-Khaliq

@shenery

I'm not familiar with OpenHab, though suspect it'll need to communicate with it via some version of MQTT.

Check out posts by Peter Scargill at http://tech.scargill.net/ and Tinkerman http://tinkerman.cat/
They have done some great work with ESP8266 and ITead devices. Peter Scargill has interfaced various devices to Node Red, something similar to OpenHab.

Hope this helps
Abdul-Khaliq

@TCRAKN Hey thanks for getting back. Yeah I've seen those sites before. Would there be a way to incorporate MQTT into this code as well?

@shenery

I wouldn't know where to begin with MQTT. I have seen a number of repositories related to Sonoff and MQTT, but can't recall which ones.

I now need to find a way to control WS2812 LEDs with an ESP, and maybe with a Sonoff too. There are plenty of accessible I/O pins to do so. Any ideas anyone? Oh, with Alexa commands too...

Ciao for now.
Abdul-Khaliq

@shenery
Thank you for sharing, however, my experience with xoseperez stuff is not great. He wrote the code and only tells us to use PlatformIO which I am not wanting to learn. Ardunio does not work with his code so I can't get it to load up.

@MacGyver1rjq104

Xose has an Arduino Wiki here that looks quite clear:
https://bitbucket.org/xoseperez/espurna/wiki/ArduinoIDE.md

You can choose which "modules" you want to include in your build, compile and upload.
He uses the Fauxmo library for Amazon Echo control. I've no experience of it, so can't comment.

By the way, Itead Studio have hinted that they're going to release a firmware update for the Sonoff that'll include Amazon Echo control. What that entails is anyone's guess!
http://support.iteadstudio.com/support/discussions/topics/11000009015/page/2?url_locale=

Best
Abdul-Khaliq

@TCRAKN, can you post a link to the Sonoff version? Your link has expired.

@TCRAKN Thanks for uploading this....great piece of work and functions well. I had to move one of the functions before it would compile...might be an issue with 1.6.6 of the IDE and will upgrade to test.

I've mounted my Sonoff into an external/waterproof housing and have it controlling pool lights. I see you have enabled the relay to be enabled using the push button. Can this be wired up to an external momentary switch to allow the relay to be triggered? Would like to mount this on my case.

F

@TCRAKN also, forgot to say. I tested this with the official WeMo app and it doesn't detect this device. I wasn't expecting it to, but thought I'd verify. Any chance this could be implemented?

@farsonic
Sure, you can wire up a switch in parallel to the existing one.

I'm not familiar with the WeMo protocols, but it shouldn't be too difficult to implement by someone that knows how to.

I've updated the sketch (below) to correctly illuminate the LED. I'd assumed that a HIGH would illuminate it! Not so. And also, to switch on the relay before attempting WiFi connectivity, rather than after, which caused the switch-on to be somewhat delayed after applying power to the Sonoff.

Sonoff_WeMo_Alexa_Single-Github.ino.zip

Best
Abdul-Khaliq

Thanks, I'll look to get some time this week to look into programming an alternate switch for the relay. Shouldn't be to difficult. I'll do some snooping on the WeMo protocols. Already with your code running it is simple to trigger on/off from the command line using something like this

curl --data "request:"1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetBinaryState xmlns:u="urn:Belkin:service:basicevent:1">1</u:SetBinaryState></s:Body></s:Envelope>" http://192.168.0.173/upnp/control/basicevent1

I have to make it clear that I've only added the rudimentary switch and LED functionality to Aruna's original code in this repo. Kudos is his! @kakopappa

Abdul-Khaliq

I've modified the code enough now that it can be discovered by the third party WeMo app called QuickConnect. Seems Quickconnect uses port 49152 which is the standard Wemo port number for its web server. However Alexa will only communicate to it on port 80?

Is there a way to have the ESP8266WebServer listening on two ports?

F

1rvy commented

farsonic, its easy enough to run multiple web servers, I have mine with three, one for manual toggling of GPIO and two for Alexa to turn on two different GPIO connected devices.

//define the webserver ports

const unsigned int portMulti = 1900;
const unsigned int webserverPort = 9876;
const unsigned int webserverPort2 = 9877;
const unsigned int webserverPort3 = 49153;

//define the webservers

ESP8266WebServer webserver(80); //Manual web page
ESP8266WebServer server(webserverPort); //Alexa GPIO4
ESP8266WebServer server2(webserverPort2); //Alexa GPIO5
ESP8266WebServer server3(webserverPort3); //testing with app

//In loop enable service

webserver.handleClient(); //Webserver on port 80
server.handleClient(); //Webserver for Alexa Discovery of Study Lamp
server2.handleClient(); //Webserver for Alexa Discovery of Study LED
server3.handleClient(); //Webserver for Wemo App Discovery

// Then for every instance of the following:

server.
HandleNotFound.
handleUpnpControl.
handleSetupXml.
handleRoot.
responseToSearchUdp.

you need to replicate the contents of original one and I simply add a number to the end for each new webserver (find and replace is your friend here!)

e.g.

server2.
HandleNotFound2.
handleUpnpControl2.
handleSetupXml2.
handleRoot2.
responseToSearchUdp2.

I've been playing with the "Wemo Widgets" app to try and add control for the devices on another webserver listening on 49153 but no joy. What have you had to edit to get the app to work with XML/SOAP?

@farsonic It works with Alexis as well? When you get it finish, would you be willing to share it? My wife is wanting me to get rid of Alexia because she is so soft spoken and it doesn't work well with her, so I told her I would reprogram all the relays with the ability of an app on her phone once one comes out. This will save my project! Thank you!

@farsonic I can't find Quick Connect. Is it the samsung app?

Any progress? I have struggle to find solutions. Is there a way to download Wemo's firmware and mod it to work with Sonoff? I believe it works with both the app and Alexa

i had a thought, can this be flashed onto the esp 8285 ?

Hi @TCRAKN,

I can't get the nodemcu to connect to my wifi with your edited code, tried increasing the time but still fails.

Any pointers?

With best regards

Hi, sorry, my comment wasn't directed at you.

I've got it to work now, by copying the additional switch elements into the original code that worked.

Interestingly my device did not like being discovered with my circuit connected.

Hi team, sorry if I ask in the wrong place. Does anyone know where to find a code for the sonoff dual with interlocking method and to work with echo dot? I need for controll electrical shutters.
I chose sonoff because it is complete for connection to 220V. Dual because one relay could be used to open and another to close shutter.
The interlocking mode for security reasons. Thank you

I think I found the error that generated the restart on ESP12.
I edited switch.cpp, on line 109, i replaced this
server->send(200, "text/plain", eventservice_xml.c_str());
with
server->send(200, "text/xml", eventservice_xml.c_str());
Now works ok with nodemcu1.0