Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. Looking for detailed description for hacking a sonoff

Looking for detailed description for hacking a sonoff

Scheduled Pinned Locked Moved Hardware
45 Posts 12 Posters 49.3k Views 15 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • EfflonE Efflon

    Here is a working example of using Sonoff with MySensors and the mqtt gateway.
    No need to replace any flash etc...

    alexsh1A Offline
    alexsh1A Offline
    alexsh1
    wrote on last edited by
    #21

    @Efflon we were talking about a different software whereby more flash was required
    Besides 1mb flash is not much in the esp8566 world

    1 Reply Last reply
    0
    • dbemowskD Offline
      dbemowskD Offline
      dbemowsk
      wrote on last edited by
      #22

      So I have been debating on getting some of these sonoffs. I am assuming the WiFi gateway in the build section of the site is what I would need to build? Is there a better option for using these with my Vera Plus?

      Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
      Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

      alexsh1A 1 Reply Last reply
      0
      • dbemowskD dbemowsk

        So I have been debating on getting some of these sonoffs. I am assuming the WiFi gateway in the build section of the site is what I would need to build? Is there a better option for using these with my Vera Plus?

        alexsh1A Offline
        alexsh1A Offline
        alexsh1
        wrote on last edited by
        #23

        @dbemowsk no, the wifi gateway above is to connect nrf24l01+ via wifi. For Sonoff I just reflashed it with easyesp and it works via my normal router with Domoticz. You can have the MQTT setup with Sonoff - thats what @peterscargill did

        dbemowskD 1 Reply Last reply
        0
        • alexsh1A alexsh1

          @dbemowsk no, the wifi gateway above is to connect nrf24l01+ via wifi. For Sonoff I just reflashed it with easyesp and it works via my normal router with Domoticz. You can have the MQTT setup with Sonoff - thats what @peterscargill did

          dbemowskD Offline
          dbemowskD Offline
          dbemowsk
          wrote on last edited by dbemowsk
          #24

          @alexsh1 said in Looking for detailed description for hacking a sonoff:

          For Sonoff I just reflashed it with easyesp and it works via my normal router with Domoticz. You can have the MQTT setup with Sonoff - thats what @peterscargill did

          Will it work with Vera? I purchased one of these recently from WalMart which also runs on an esp8266 module. I wonder if I can run run the easyesp firmware on that one also?
          alt text

          Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
          Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

          alexsh1A 1 Reply Last reply
          0
          • dbemowskD dbemowsk

            @alexsh1 said in Looking for detailed description for hacking a sonoff:

            For Sonoff I just reflashed it with easyesp and it works via my normal router with Domoticz. You can have the MQTT setup with Sonoff - thats what @peterscargill did

            Will it work with Vera? I purchased one of these recently from WalMart which also runs on an esp8266 module. I wonder if I can run run the easyesp firmware on that one also?
            alt text

            alexsh1A Offline
            alexsh1A Offline
            alexsh1
            wrote on last edited by
            #25

            @dbemowsk Unfortunately, I am not familiar with Vera. Can you send http or json commands from Vera? If yes, it will work. On RPi this is easy to implement.

            Generally speaking you can flash many devices with easyesp if you find how to connect FTDI. I have ESP-01 and ESP-12 running easyesp. Again I am not familiar with the device you posted (the most important question is does it have FTDI or can you identify it by soldering corresponding pins?) and suggest to ask the same question on the easyesp forum.

            1 Reply Last reply
            0
            • dbemowskD Offline
              dbemowskD Offline
              dbemowsk
              wrote on last edited by
              #26

              @alexsh1 I think all the information I need to flash it is in this post that I found on Hackaday. It is a bit different than the sonoffs in that it does not have an unpopulated header port for programming, so you have to solder directly to the module to get it programmed, but what the heck, I'll give it a shot.

              As far a s controlling it from Domoticz, I am assuming that you just created a dummy switch that you used URLs for the on and off commands, correct? I will look into how to do that from Vera. Before I got my Vera (a month ago) I was using Domoticz.

              Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
              Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

              alexsh1A 1 Reply Last reply
              0
              • dbemowskD dbemowsk

                @alexsh1 I think all the information I need to flash it is in this post that I found on Hackaday. It is a bit different than the sonoffs in that it does not have an unpopulated header port for programming, so you have to solder directly to the module to get it programmed, but what the heck, I'll give it a shot.

                As far a s controlling it from Domoticz, I am assuming that you just created a dummy switch that you used URLs for the on and off commands, correct? I will look into how to do that from Vera. Before I got my Vera (a month ago) I was using Domoticz.

                alexsh1A Offline
                alexsh1A Offline
                alexsh1
                wrote on last edited by
                #27

                @dbemowsk yes, with Domoticz it is very straight forward, but you have to setup the Sonoff as well.
                Check this out- http://www.letscontrolit.com/wiki/index.php/Tutorial_Domoticz_Switch

                dbemowskD 1 Reply Last reply
                0
                • alexsh1A alexsh1

                  @dbemowsk yes, with Domoticz it is very straight forward, but you have to setup the Sonoff as well.
                  Check this out- http://www.letscontrolit.com/wiki/index.php/Tutorial_Domoticz_Switch

                  dbemowskD Offline
                  dbemowskD Offline
                  dbemowsk
                  wrote on last edited by
                  #28

                  @alexsh1 Excellent information. I may try flashing the module that I have today and see if I can get it to work.

                  Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                  Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                  1 Reply Last reply
                  0
                  • Mark SwiftM Offline
                    Mark SwiftM Offline
                    Mark Swift
                    wrote on last edited by
                    #29

                    I have a standard ethernet gateway (NRF) and my controller is the home automation system 'Homey'. I presume I cannot connect these directly to my controller?

                    alexsh1A 1 Reply Last reply
                    0
                    • Mark SwiftM Mark Swift

                      I have a standard ethernet gateway (NRF) and my controller is the home automation system 'Homey'. I presume I cannot connect these directly to my controller?

                      alexsh1A Offline
                      alexsh1A Offline
                      alexsh1
                      wrote on last edited by alexsh1
                      #30

                      @Mark-Swift the problem with home automation in general is a verity of controllers ;) I'm not familiar with Homey, but if it can handle MQTT, Sonoff will work with it.

                      A quick google found this:

                      https://forum.athom.com/discussion/858/published-mosquitto-mqtt-client-app

                      you are participating in this thread ;)

                      PS I have a standard Ethernet GW too. My controller Domoticz can handle JSON/http requests which makes it easy to handle devices like Sonoff connected to my home wifi and not requiring any further GW. Obviously, the setup can be more complicated with MQTT GW and Sonoff MQTT firmware

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mgaman
                        wrote on last edited by
                        #31

                        Please checkout my hack of the Sonoff

                        Apart from turning the relay on/off it offers the following features

                        The device is managed via a set of commands published from any MQTT client. Statuses are published by the device. Subscribe to them on your MQTT client.
                        SSID/Password management - The local SPIFSS file system is used to store an array of WiFI credentials.
                        Extra GPIO On/Off. There is an 'extra' GPIO available (next to the Ground pin on the UART breakout on the Sonoff.

                        https://github.com/mgaman/Sonoff-modified

                        EfflonE 1 Reply Last reply
                        0
                        • M mgaman

                          Please checkout my hack of the Sonoff

                          Apart from turning the relay on/off it offers the following features

                          The device is managed via a set of commands published from any MQTT client. Statuses are published by the device. Subscribe to them on your MQTT client.
                          SSID/Password management - The local SPIFSS file system is used to store an array of WiFI credentials.
                          Extra GPIO On/Off. There is an 'extra' GPIO available (next to the Ground pin on the UART breakout on the Sonoff.

                          https://github.com/mgaman/Sonoff-modified

                          EfflonE Offline
                          EfflonE Offline
                          Efflon
                          wrote on last edited by
                          #32

                          @mgaman Interesting code but I have a hard time understanding how you set ssid + passwd , through mqtt with your hard coded wifi user pass?

                          M 1 Reply Last reply
                          0
                          • EfflonE Efflon

                            @mgaman Interesting code but I have a hard time understanding how you set ssid + passwd , through mqtt with your hard coded wifi user pass?

                            M Offline
                            M Offline
                            mgaman
                            wrote on last edited by
                            #33

                            @Efflon
                            Did you read the PDF file? There I explain the methodology
                            From an MQTT client I publish commands which the Sonoff subscribes to.
                            These commands allow me to add to or delete from an array of SSID/Password pairs held in a file in the ESP8266 SPIFSS file system.
                            On power up I scan the local networks for SSID's and search the local file for matching SSID's.
                            If a match is found, I use it for connecting to the local WiFI network.
                            Does that help?

                            EfflonE ? 2 Replies Last reply
                            1
                            • M mgaman

                              @Efflon
                              Did you read the PDF file? There I explain the methodology
                              From an MQTT client I publish commands which the Sonoff subscribes to.
                              These commands allow me to add to or delete from an array of SSID/Password pairs held in a file in the ESP8266 SPIFSS file system.
                              On power up I scan the local networks for SSID's and search the local file for matching SSID's.
                              If a match is found, I use it for connecting to the local WiFI network.
                              Does that help?

                              EfflonE Offline
                              EfflonE Offline
                              Efflon
                              wrote on last edited by
                              #34

                              @mgaman Didn't read the pdf, but thanks for the explanation. Nice trick to make installation easier.

                              1 Reply Last reply
                              0
                              • M mgaman

                                @Efflon
                                Did you read the PDF file? There I explain the methodology
                                From an MQTT client I publish commands which the Sonoff subscribes to.
                                These commands allow me to add to or delete from an array of SSID/Password pairs held in a file in the ESP8266 SPIFSS file system.
                                On power up I scan the local networks for SSID's and search the local file for matching SSID's.
                                If a match is found, I use it for connecting to the local WiFI network.
                                Does that help?

                                ? Offline
                                ? Offline
                                A Former User
                                wrote on last edited by
                                #35

                                Hello @mgaman ,

                                Nice modified version. Because I can't flash it for now, can you tell me wether it's possible to use json commands together with MQTT features?
                                Let me explain : json requests sent from my home automation software are more reliable than MQTT, as they get acknowledgement via the HTTP response, so the sender immediately knows wether the device got the order or not. This is very important to me, as it may be necessary to send orders more than once if the sonoff device is far away from the wifi router. Maybe I'm not clear, your opinion will be appreciated.

                                dbemowskD 1 Reply Last reply
                                0
                                • ? A Former User

                                  Hello @mgaman ,

                                  Nice modified version. Because I can't flash it for now, can you tell me wether it's possible to use json commands together with MQTT features?
                                  Let me explain : json requests sent from my home automation software are more reliable than MQTT, as they get acknowledgement via the HTTP response, so the sender immediately knows wether the device got the order or not. This is very important to me, as it may be necessary to send orders more than once if the sonoff device is far away from the wifi router. Maybe I'm not clear, your opinion will be appreciated.

                                  dbemowskD Offline
                                  dbemowskD Offline
                                  dbemowsk
                                  wrote on last edited by
                                  #36

                                  @Foune What automation software are you using? I have a Vera Plus controller and use a firmware called ESP Easy with my sonoffs. The Vera plugin that I use sends an HTTP request something like this:

                                  http://192.168.1.36/control?cmd=GPIO,12,1
                                  

                                  That is to tell the sonoff to use GPIO pin 12 which is my relay, and send it a 1 or ON command. The sonoff sends an immediate JSON response like this:

                                  {
                                  "log": "GPIO 12 Set to 1",
                                  "plugin": 1,
                                  "pin": 12,
                                  "mode": "output",
                                  "state": 1
                                  }
                                  

                                  This tells me that GPIO pin 12 was successfully set to a 1 state.

                                  The Vera plugin will occasionally check the up status of the node by sending a ping and checking the response. On the Vera controller, the device will either show Online or Offline.

                                  Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                                  Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                                  1 Reply Last reply
                                  0
                                  • ? Offline
                                    ? Offline
                                    A Former User
                                    wrote on last edited by
                                    #37

                                    Thanks for your detailed answer. If your sonoff device is used in a scenario and the order is not received by it, your vera won't do anything to solve that. I'm looking for a synchronous protocol acknowledgement between the sender and the receiver so that I won't need to code a scheduled task to check whether the command was executed. I use eventghost together with domoticz : domoticz when its plugins are OK, eventghost if I want a fully customizable management, like for my 433 devices which are sometimes lazy to trigger.

                                    dbemowskD 1 Reply Last reply
                                    0
                                    • ? A Former User

                                      Thanks for your detailed answer. If your sonoff device is used in a scenario and the order is not received by it, your vera won't do anything to solve that. I'm looking for a synchronous protocol acknowledgement between the sender and the receiver so that I won't need to code a scheduled task to check whether the command was executed. I use eventghost together with domoticz : domoticz when its plugins are OK, eventghost if I want a fully customizable management, like for my 433 devices which are sometimes lazy to trigger.

                                      dbemowskD Offline
                                      dbemowskD Offline
                                      dbemowsk
                                      wrote on last edited by
                                      #38

                                      @Foune said in Looking for detailed description for hacking a sonoff:

                                      If your sonoff device is used in a scenario and the order is not received by it, your vera won't do anything to solve that.

                                      Correct, but that is coding that needs to be done on the controller side and has little to do with the device. If the device receives the request, it will send the JSON response back.

                                      I'm looking for a synchronous protocol acknowledgement between the sender and the receiver so that I won't need to code a scheduled task to check whether the command was executed

                                      As I said, that needs to be coded on the controller side. If the sonoff doesn't receive the request, how is it going to send anything back saying that it didn't receive it. In the example I gave above, it shows the JSON acknowledgement that the command was received. The only thing you can do is write into the code that if the response is not received within some specified period of time, then re-send the command.

                                      Your 433 devices as you say are sometimes lazy to trigger. They may not be triggering because they did not properly receive the command sent by the controller.

                                      Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                                      Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                                      ? 1 Reply Last reply
                                      0
                                      • dbemowskD dbemowsk

                                        @Foune said in Looking for detailed description for hacking a sonoff:

                                        If your sonoff device is used in a scenario and the order is not received by it, your vera won't do anything to solve that.

                                        Correct, but that is coding that needs to be done on the controller side and has little to do with the device. If the device receives the request, it will send the JSON response back.

                                        I'm looking for a synchronous protocol acknowledgement between the sender and the receiver so that I won't need to code a scheduled task to check whether the command was executed

                                        As I said, that needs to be coded on the controller side. If the sonoff doesn't receive the request, how is it going to send anything back saying that it didn't receive it. In the example I gave above, it shows the JSON acknowledgement that the command was received. The only thing you can do is write into the code that if the response is not received within some specified period of time, then re-send the command.

                                        Your 433 devices as you say are sometimes lazy to trigger. They may not be triggering because they did not properly receive the command sent by the controller.

                                        ? Offline
                                        ? Offline
                                        A Former User
                                        wrote on last edited by A Former User
                                        #39

                                        @dbemowsk All right, so we all agree about the superiority of the json over the MQTT in term of synchronous acknowledgement. This is why I'm asking to mgaman whether I can send commands to the sonoff using json, having in the same time the MQTT features : status report, command, and his new wifi features. I'm sorry if it is a native feature, having read the official doc It seems that chosing one protocol disable the others.

                                        EDIT : I have my answer, I read the source code, there is only the MQTT feature on mgaman's version. I wish I had this wifi MQTT management in addition to the original espeasy code.

                                        dbemowskD 1 Reply Last reply
                                        0
                                        • ? A Former User

                                          @dbemowsk All right, so we all agree about the superiority of the json over the MQTT in term of synchronous acknowledgement. This is why I'm asking to mgaman whether I can send commands to the sonoff using json, having in the same time the MQTT features : status report, command, and his new wifi features. I'm sorry if it is a native feature, having read the official doc It seems that chosing one protocol disable the others.

                                          EDIT : I have my answer, I read the source code, there is only the MQTT feature on mgaman's version. I wish I had this wifi MQTT management in addition to the original espeasy code.

                                          dbemowskD Offline
                                          dbemowskD Offline
                                          dbemowsk
                                          wrote on last edited by
                                          #40

                                          @Foune said in Looking for detailed description for hacking a sonoff:

                                          All right, so we all agree about the superiority of the json over the MQTT in term of synchronous acknowledgement.

                                          I never said that. I was merely commenting on how my setup works using the ESP Easy firmware which does send a return JSON response. I have never used MQTT, so I don't know if it sends a return response to a command or not. If it does, then I don't see any difference other than how you would process that response on the controller end.

                                          Also, with ESP Easy, I don't as you say "send commands to the sonoff using json". I send an HTTP request and receive the response in JSON format. If @mgaman has a way with MQTT to retrieve the status of a node, e.g. ON or OFF, then on your controller side code, you could send your ON/OFF command, and then right after send a status request command and check the response from that. Depending on the response, you could re-send the ON/OFF command if necessary.

                                          Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                                          Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          17

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular