|
Post by papa on Aug 15, 2017 14:53:54 GMT
Program Itead S20 ECOPlug (ESP8266) Thread Updated April 13, 2019 for At Least openHAB 2.5.0.M1, MQTT 2.x Binding, & the Embedded MQTT Broker
What I've seen & tested on a U.S. version of the Itead S20 ECOPlug confirms most of what Tinkerman wrote & showed about a non-U.S. version. Here are my pics. I did not look at the circuit board's other side. Since the male appliance plug is firmly in my device's case, that would take serious dismantling. The ruler gives you some idea of dimensions. The S20 has a green LED (wifi indicator) left of the push button & a red LED (indicates female appliance plug at the bottom is powered) right of the push button. Different from Tinkerman's pics: My circuit board covers the whole inside of the case, including the male & female mains plug. For the mains, large circuit board traces are used instead of actual wires. For those of us wanting to program our preferred firmware, Itead has made it relatively convenient so far. As with other Itead devices that I've covered in this forum: The case opens & closes fairly easily. A .1 inch spaced row of holes provides programming connections (see the strip of vcc, rx, tx, gnd holes just below the push button.) As with a Sonoff Single, holding the push button down before powering the device puts it into programming mode. I encourage you to see jimkernsjr's info-filled documentation of programming Sonoff Singles upon which this thread builds.
|
|
|
Post by papa on Aug 15, 2017 14:59:32 GMT
Preparing to Program the Itead S20 ECOPlug Expose the S20's circuit board: Opposite from the MALE mains plug, remove or puncture the small seal with Chinese characters. That exposes the S20 case's one screw. Remove that screw. From the case's end near the screw hole, work your way towards the other end, prying open the case at the seam. (No parts, except maybe the easily-oriented power button, should fall out.) These (besides an S20) are needed: an FTDI programmer with its USB cable which must be able to function in 3.3 volts (much more will damage the S20's processor). I use this one. jimkernsjr uses this one. Short dupont cables (4 colors including redish & black or brown), male on one end for the S20 programming holes & on the other end male or female to connect to FTDI programming device. Preparations continue below
|
|
|
Post by papa on Aug 15, 2017 15:07:58 GMT
Preparing to Program the Itead S20 ECOPlug, ContinuedAlso needed: a computer running the Arduino IDE (at least version 1.6.8). Adapted from what jimkernsjr said here, Install support for the ESP8266-related boards. Instructions here: ... but stop at the heading "Selecting the ESP8266 Thing Board", you don't need to go any further. After installing support for ESP8266-related boards ... make the proper settings in the Arduino environment. Open Arduino IDE. -In Tools menu, under boards, scroll down to the ESP8266 boards section, and select "Generic ESP8266 Board". This will give you all options! -Don't touch Flash Mode, Frequency, and CPU frequency, leave the default values. ... -Select 1M(128K SPIFFS) from the flash size.
|
|
|
Post by papa on Aug 15, 2017 15:22:10 GMT
Preparing to Program the Itead S20 ECOPlug, ContinuedCautions: Make sure the FTDI programmer is in 3.3 volt mode. NEVER EVER connect your FTDI programmer while the S20 is in a powered mains outlet!!! Using the dupont cables, create a DIY 4-wire cable ready to create the following connections (& like the pics below): In order, starting at "square" hole, S20 holes on strip to be connected to FTDI VCC 3V3 Rx Tx Tx Rx GND GND In the pics, see how I used color-coded male to male dupont cables (VCC is red, GND is black, etc). I taped together the S20 header cable ends in the needed order & labelled the pins. right: FTDI programmer left: cable ends for Slampher programming header
|
|
|
Post by papa on Aug 15, 2017 15:38:45 GMT
Connecting the Programming Cable to the S20 Circuit Board & Programming the S20 with ANY New FirmwareIt looks like you could solder breakaway female header sockets on the S20 programming holes ( See this post about using breakaways.) However ... Though awkward, you could avoid soldering with a method like jimkernsjr used: (Again, the S20 is NOT in a powered socket & FTDI is in 3.3 volt mode.)Have the new firmware programming opened in Arduino IDE. (This could be any new firmware. Below, I'll provide the firmware we use on this forum). cable connected closeup of cable connected Have the circuit board's push button side facing up, push button on the left (see left pic) & female mains plug on the right. Matching the connections listed above, insert your cable's pins into the S20 board. With your left hand's index ("pointer") finger, steadily "lean" the pins in their holes. << WHILE doing this with your left hand, plug the FTDI programmer's USB cable into the computer with your right hand. In the Arduino IDE tools/port menu, select the (Com) port your FTDI programmer uses when connected to USB. Put the cursor over the IDE's upload button. Unplug the FTDI programmer from USB. The next step starts like the last step, but goes further: Again have the circuit board's push button side facing up, push button on the left & female mains plug on the right. Matching the connections listed above, have your cable's pins inserted into the S20 board. With your left hand's index finger, steadily "lean" the pins in their holes AND with your left hand's middle finger hold the push button down. << WHILE doing these 2 things with your left hand, plug the FTDI programmer's USB cable into the computer with your right hand. If successful, this will GND GPIO0 & the LED will NOT (faintly) flash & the device will be in programming mode. Maintain steady pressure on the board to keep programming pins connected, but you can release the push button. While maintaining pressure on the leaning pins, start the Arduino IDE compiling & uploading the sketch. Repeat this process until uploading is successful. Once successful, you can reassemble the case. When the device is in a powered outlet, you should be able to use its Over the Air programming ability.
|
|
|
Post by papa on Aug 15, 2017 15:54:39 GMT
Get This Forum's Firmware to Program the S20 ESP82xx_Devices.ino (23.04 KB) ECOplgS20Study71.h (1.76 KB) << Download & install so these two files are in the same sketch folder. ^^ Updated Feb. 11, 2018. Some Arduino IDE versions choked on how the errorblink & wifiOTAcheck functions were previously handled. ^^ Updated April 13, 2019: moved WiFi configurations from .h files to ESP82xx_Devices.ino
I renamed jimkernsjr's ESP_SonoffAndEcoPlug.ino to ESP82xx_Devices.ino & added a commented, NOT-active-yet #include (ECOplgS20Study71.h) for an S20 device customization. In ECOplgS20Study71.h, I set node 71, OnAtPowerup,etc. EnToggle is UNdefined since an S20 probably does not have a motion light. See jimkernsjr's thread for more about this & also more GitHub files for other devices. So far, for the Sonoff type devices, Itead seems to use the same GPIOs for button (0), relay (12), & LED (13). Thus the S20 uses the same pins as Sonoff Singles. BTW for a helpful data base of smart devices & their pins for button, relay, & LED, see here AND here. Note: For access, Bitbucket requires registration.
|
|
|
Post by papa on Aug 15, 2017 16:02:10 GMT
Programming the S20 with This Forum's Firmware, Continued Updated April 13, 2019
Open ESP82xx_Devices.ino (downloaded above) with Arduino IDE. ECOplgS20Study71.h should also open in another tab. Customize ESP82xx_Devices.ino with your WiFI SSID, WiFi password, & IP of the computer running your MQTT broker/server.
Also in ESP82xx_Devices.ino, UNcomment (delete the initial // of) the line #include ECOplgS20Study71.h
After the upload finishes successfully, momentarily release the pressure on the board & dupont pins in the programming strip (de-power the board). Then reapply pressure (power the board). The green LED should flash once & then stay on steady indicating the S20 has connected to your local WiFi network & MQTT. You should not need to program the S20 this way any more. You can now remove the FTDI programmer & dupont cable connections & reassemble the S20 in its case. Via my local network router's settings, I give my S20s permanent IP addresses. That might make them more likely to reconnect automatically after a power outage.
|
|
|
Post by papa on Aug 15, 2017 16:09:15 GMT
If the Arduino IDE completed uploading new firmware, BUT the reprogrammed S20 does NOT connect to your WiFi ...
1) Remove the S20 from power. Turn off your WiFi router for at least 30 seconds & then restart the router. Attach the S20 to power again & see if it connects to WiFi.
2) If trying 1) a couple times does not help, recheck & (if necessary) fix the WiFi network information you uploaded to the S20 with the firmware.
3) Especially if you edited the WiFi information in 2) or if 1) did not help, use the S20's strip of programming holes to upload firmware again as you did in the last post.
|
|
|
Post by papa on Aug 15, 2017 16:12:07 GMT
Once Uploading New Firmware Is Completed AND the S20 Connects to your WiFi ...
To reprogram this S20 "Over the Air" (via the WiFi connection), the outlet holding the S20 must be powered. Also for the following to work, you'll likely need to close & reopen the Arduino IDE. In the IDE's tools/port menu, see & select this node's OTA name (ECOplgS20Study71). Make your desired changes in the header file for this node (ECOplgS20Study71.h). Upload the changed package.
To reprogram firmware on other S20s, use an editor like Notepad++) to copy, customize (node ID, etc), & rename the ECOplgS20Study71.h file accordingly. Edit ESP82xx_Devices.ino: Comment out (//) #include "ECOplgS20Study71.h" AND add a new UNcommented include line for the next S20's .h header file. Repeat the steps above for flashing the firmware on the next S20.
|
|
|
Post by papa on Aug 15, 2017 16:34:09 GMT
The following assumes a computer (possibly a Raspberry Pi) that hosts MQTT & OpenHAB. Updated April 15, 2019.
Needed in order for the following to work: See this thread on installing openHAB/MQTT on a local network-connected computer. Except, the channel topic will somewhat differ from one for an RFM69 node. (See blue text in topics below.) As above, you might program an S20 as Node71 & use it to control an AC appliance in the study (as long as the appliance uses no more than 10 amperes current, according to the device's specifications.) Here are OpenHAB configurations to accomplish that: (The outlet holding the S20 must be powered for these to work.)
At PaperUI\configuration\Things, Add Thing (click + in blue disc) click MQTT Binding Add Manually Generic MQTT Thing Node71 Location (arbitrary physical location) LR MQTT Broker - mqtt:systemBroker:embedded-mqtt-broker save (click check mark in blue disc)
PaperUI\Configuration\Things\Node71 Add channel (click + in blue disc), fill the fields: Channel type On/Off switch < choose type according to the item data type we want Channel id Node71Channel16 < arbitrary ? as long as we match in a linked item later Label Node71_Switch < arbitrary ?
MQTT State Topic home/esp_gw/nb/node71/dev16 Command Topic home/esp_gw/sb/node71/dev16
The following had been omitted, but was restored on April 15, 2019:
In OpenHAB's \conf\items folder, create a file named Node71.items & within Node71.items create this entry & save the file: Switch Act_Node71 { channel="mqtt:embedded-mqtt-broker:topic:mything:Node71Channel16" }
Important: Link the above item to the above matching channel.
Next, OpenHAB Configurations, Continued
|
|
|
Post by papa on Aug 15, 2017 16:40:05 GMT
OpenHAB Configurations, Continued
Add to a .rules file in openHAB's \conf\rules folder: rule "Random timer for Output ON around 9:16pm" // Study Activity on (Node71) when Time cron "0 11 21 * * ?" then // Schedule a random ON event up to 15 minutes from now createTimer(now.plusMinutes((new java.util.Random).nextInt(15)) ) [| sendCommand(Act_Node71, ON) ] end
rule "Random timer for Output OFF around 9:32pm" // Study Activity done (Node71) when Time cron "0 27 21 * * ?" then // Schedule a random OFF event up to 15 minutes from now createTimer(now.plusMinutes((new java.util.Random).nextInt(15)) ) [| sendCommand(Act_Node71, OFF) ] end
Add to a .sitemap file in openHAB's \conf\sitemaps folder: Switch item=Act_Node71 label="Study71"
Given the preparations above AND that an appliance's OWN switch is on ... To toggle the appliance on or off, one can use the S20 push button OR use the virtual switch on the OpenHAB User Interface. The first rule will turn on the appliance semi-randomly between 9:11pm & 9:26pm. The second rule will turn off the appliance semi-randomly between 9:27pm & 9:42pm.
|
|
|
Post by papa on Feb 11, 2018 15:47:47 GMT
I just used the above instructions again to set up another EcoPlug. It all still worked as before, except I had to tweak ESP82xx_Devices.ino, the main sketch in this post. Some Arduino IDE versions choked on how the errorblink & wifiOTAcheck functions were previously handled.
|
|
|
Post by papa on Apr 13, 2019 19:30:18 GMT
I have updated the above thread for at least openHAB 2.5.0.M1, MQTT 2.x Binding, & the Embedded MQTT Broker.
|
|