ITEAD Sonoff switches and sockets - cheap ESP8266 Wifi+MQTT hardware

It works. Your wiring is wrong. On the photo the GREEN is not on GPIO0. Here’s the correct wiring.

Nevertheless… Thank you.

Next I try ESP_Easy. Be patient. :slight_smile:

Awesome.

Actually the first time I programmed it was with temp wires.

You are right! I didn’t realise I flipped the gpio0 second time around. Thanks!!!

I wonder if esp-easy is too big.

As an FYI I couldn’t flash esp-easy onto a sonoff S22 socket (my first device), some posts I came across seem to inidcate it’s because of an upgrade to the chip used, it needs to have the flashmode set to DOUT and the esp-easy packages are set to DIN? Apparently the 8285 packages did have DOUT set and worked, but I couldn’t get it to flash on mine after multiple attempts and hours wasted.
Note that this was over the course of the last few weeks, it may well have been rectified now, but I’ve since jumped ship to tasmota because I could actually get it to flash and work. esp-easy sounded, well, easier, but I guess I’m in the tasmota camp now.

The ESP-Easy guys told me to flash the pre-compiled bin file using DOUT.
I have not tried since I had it mis-wired one of the pins.

Success…

First I tried to flash with a flash-tool for LINUX, no success.

Then I made an OTA-Update from Tasmota with ESP_EASY.bin (Version 120, 1MB size), which is running now on the faked SONOFF.

After that I tried to make OTA-Update inside ESP_EASY to the latest version, no success

Tasmota, then using Tasmota to upload ESP_EASY.bin version 120 worked?
I think upload to latest ESP_EASY from ESP_EASY is impossible due to the high space needed since ESP v2.

Did you re-try Arduino build and upload of ESP_EASY directly?
Did you try the ESP8265 build instead? I think that is designed for lower memory.

I feel we are getting closer.

Cool.

By the way - did you try the DOUT mode when using the linux flash too?
What tool was it? esptool.py?

Thanks.

How did you get TASMOTA on it first? Arduino OR flash tool.

Tasmota I flashed with platformIO, but I think Arduino should also work.
The flashtool is a script for ESP_Easy https://www.letscontrolit.com/wiki/index.php/Flash_script_linux

To be honest; I’ll not spend more time in it, because Tasmota is working fine for me and ESP_Easy is overloaded for a relay-switch.

Yeah. My mind is same as yours but I want to document want we succeeded.

I flashed tasmora via Arduino so at least 2 methods worked.

I finally got the 1MB ESP-Easy to flash!!!

I finally got it to work.

I do not know why, but it seems I hard to start the flash within a short window of powering it on:

python esptool.py -p /dev/ttyUSB0 write_flash --flash_mode dout -ff 20m 0x0 ESP_Easy_v2.0-20180116_normal_ESP8266_1024.bin 
esptool.py v2.3-dev
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 1MB
Flash params set to 0x0322
Compressed 574976 bytes to 378527...
Wrote 574976 bytes (378527 compressed) at 0x00000000 in 33.5 seconds (effective 137.4 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting...

When I tried to do it while taking my time, this always happened:

python esptool.py -p /dev/ttyUSB0 write_flash --flash_mode dout -ff 20m 0x0 ESP_Easy_v2.0-20180116_normal_ESP8266_1024.bin 
esptool.py v2.3-dev
Connecting........_____....._____....._____....._____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header

Hi Jerome

Re-Firmware Update status, Query the Sonoff’s etc…

Im following your setup here and also the one on the Tasmota Github… I cannot get it to work.

Are you doing this in OpenHAB 1… or is this in OpenHAB 2?

As I see some discussion with people about getting the “publish” command to work in OpenHAB 2.

Thanks

Did you install the “MQTT Action”? No one uses openHAB 1.x anymore (you shouldn’t should :wink: )

@Confectrician do you still remember to put this function up on the wiki?

I am using openHAB 2.2.0 Stable.

Maybe you can post your configuration for it here, so we can have a look at it?

Believe it or not, it was on my TODO list for today. :smile:

1 Like

Thanks for the quick reply! I am on OH 2 (latest build I believe). Ill tidy up my code as Ive got multiple code snippets laying around, and post back here shortly!

1 Like

I have added it to the wiki meanwhile, so we don’t have to search in this topic here all the time. :slight_smile:

1 Like

My MQTT broker, is called “mybroker”. If I publish from an MQTT client, the sonoff recieves the commands. All other actions within my setup seems to work (switch on/off lights etc). e.g. heres the ITEM for my working powerextention:

Switch	POWEREXTENSION	"Power Extension" <light1> {mqtt=">[mybroker:cmnd/PowerExtension/power:command:ON:1],>[mybroker:cmnd/PowerExtension/power:command:OFF:0],<[mybroker:stat/PowerExtension/POWER:state:MAP(binary.map)]", autoupdate="false"}

And heres what I have for you to look at (Ive simplified it to 1 device):

ITEMS

String Sonoff_Action "Sonoff Action" (Maintenance)
String Sonoff_FW_Available "Current Release [%s]" 	  (Maintenance) { http="<[tasmotaRelease:10000:JSONPATH($[0].name)]"}
Switch POWEREXTENSION_LWT "Status POWEREXTENSION" 	  (Maintenance) { mqtt="<[mybroker:tele/PowerExtension/LWT:state:MAP(reachable.map)]" }
String POWEREXTENSION_FW  "Firmware POWEREXTENSION [%s]"  (Maintenance) { mqtt="<[mybroker:stat/PowerExtension/STATUS2:state:JSONPATH($.StatusFWR.Version)"}

SITEMAP

Switch item=Sonoff_Action      mappings=[restart="Restart", queryFW="Query FW", upgrade="Upgrade FW"]
Text item=Sonoff_FW_Available
Switch item=POWEREXTENSION_LWT
Text item=POWEREXTENSION_FW

RULES (tried both rulesets I could find for pulling updates)

val sonoff_device_ids = newArrayList("PowerExtension")
rule "Update Sonoff Status"
when
    Time cron "0 0 0 ? * * *" // Update once a day
then
    for (String device_id : sonoff_device_ids) {
        logInfo("sonoff.rules", "Updating FW Item for Device: " + device_id )
        publish("mybroker", "cmnd/" + device_id + "/STATUS", "2")
    }
end
rule "Sonoff Maintenance"
when
    Item Sonoff_Action received command
then 
    logInfo("sonoff.rules", "Sonoff Maintenance on all devices: " + receivedCommand)
    for (String device_id : sonoff_device_ids) {
        switch (receivedCommand) {
            case "restart" :
                publish("mybroker", "cmnd/" + device_id + "/restart", "1") 
            case "queryFW" :
                publish("mybroker", "cmnd/" + device_id + "/status, "2")
            case "upgrade" : {
                publish("mybroker", "cmnd/" + device_id + "/otaurl", "http://sonoff.maddox.co.uk/tasmota/sonoff.ino.bin")
                publish("mybroker", "cmnd/" + device_id + "/upgrade", "1")
            }
        }
    }
    Sonoff_Action.postUpdate(NULL)
end

What I get is the following:

And hitting the query button doesnt show a hit when I look in the console of the Sonoff Tasmota Basic.

Oh and I have only 1 other thing I dont know about yet… I dont have a file called “sonoff.rules”… but I assume thats just the name of the entry it would show in the OpenHAB.log file for loginfo…Im guessing.

Thanks for taking a look

Can i send the values from the ESP only with MQTT or also with http?

I want to do this with the Openhab Rest API. Is this possible with Tasmota-firmware?

Hi Jerome

Dumped my code just below (or above?) this entry, but I forgot to reply to you directly! So just thought Id msg here to let you know its on this forum now.

Thanks