A few days ago, I flashed some Sonoff switches with a Raspberry Pi. If I decide to use Theo Arends Sonoff-MQTT-OTA-Arduino firmware, that would be all there would be to it. But I have been investigating using NodeMCU and I have found it cumbersome to use the Raspberry Pi to upload scripts to the Sonoff. I do wish that the USB-TTL cable would arrive. In the meantime I have decided to emulate a Sonoff with a D1 mini which is connected directly to the desktop with a USB cable.
Basically, there are three things to be setup: the tactile switch, the relay and the build in LED. All that is required are a normally open push button switch, a red and green LED and a couple of resistors. Their values are not too critical, I used what I found lying about.
The switch connects pin D3 of the D1 Mini to ground. The internal pull up resistor of the the GPIO is enabled to read a 1 from the pin when the switch is not pressed.
The red LED represents the state of the relay. Its cathode is connected to ground through a current limiting resistor, the anode is connected to pin D6 of the Wemos D1 mini. To turn the red LED on, which represents closing the relay and turning an appliance connected to the Sonoff on, a 1 must be written to D6. A 0 written to D6 turns the red LED off.
The green LED represents the built-in Sonoff LED. Its anode is connected to 3.3V, its cathode is connected to pin D7 through a current limiting resistor. Because of this configuration, a 1 written to pin D7 turns the LED off, a 0 turns the LED on. This "unnatural" connexion is what is found on the Sonoff.