Sonoff SC with MQTT and Domoticz support

Last December Itead Studio updated their Home Automation product line with a new and different product. The main difference is that it doesn’t have a relay and it’s mainly sensors and no actuator (if we don’t define a notifying LED as an actuator). The Sonoff SC is a sensor station that packs a DHT11 temperature and humidity sensor, a GM55 LDR, an electret microphone with an amplifier circuit and a Sharp GP2Y1010AU0F [Aliexpress] dust sensor in a fancy case that looks like it was originally meant for a speaker.

The device is packs an ESP8266 as expected and is compatible with the eWeLink app. But, such a collection of sensors, with 3 of them having analog interfaces, cannot be run from the single-ADC ESP8266 so Itead has thrown in a good old ATMega328P to drive the sensors and report the Espressif with the data.

The outside

The first thing that draw your attention about the Sonoff SC is it’s casing. It’s kind of a truncated hexagonal-ish pyramid with a round grid on top and a rounded bottom. Seriously, somebody had a good time designing this. It looks a lot like a intricate speaker and actually that’s what it is. The reset/flash button sticks out shamelessly from a hole labelled “Audio” on one side of the enclosure.


Side by side with the fake audio hole there is an microUSB connector that’s only for powering the device (no data lines connected) and a microSD slot. The microSD reader is connected to the ATMega328P and I’m not sure what original purpose it has but I can think on a couple of good things to do with it.

On the bottom you have 4 black screws. Remove them to gain access to the insides of the device.

20170105_125942sThe insides


Once the 4 screws are removed it can still be a little tricky to take the PCB out from the enclosure since the button shaft leaves little room to lift the PCB from the plastic holders. Meanwhile you try to remove it, take a look at the components on that bottom side of the PCB. There you can find the controllers and programming headers.


The ATMega328P microcontroller with a 16MHz crystal. The SO-8 IC is a SGM358 dual op-amp used to amplify the electret signal. You can also see a header with 5V, TX, RX, GND and RST.


On the opposite site you have the ESP8266 IC with a Winbond 1Mbyte flash memory. You can see the PCB WiFi antena and the programming header with all the needed pins plus the SDA pin. The button is attached to GPIO0 so press it while powering the board to get into flash mode.


A perspective view fo the bottom side of the PCB. Three more things to note: the jumpers in the center-top of the image connect the RX and TX lines of the ESP8266 and the ATMega328P. Left of that, by the ATMega IC you have an unpopulated ISP header. You will have to solder a 2×3 header here to program the Atmel IC. Also, you have the Electret Mic in the forefront.


The other three sensors are pleaced on a plastic holder and fit inside the cone of the device. They are hot-glued between them and using standard JST connectors, so replacing them should be no problem…

Upgrading the Sonoff SC

There are a couple of simple, almost out-of-the-box, upgrades you can do to your Sonoff SC. First you can easily replace the DHT11 termperature and humidity sensor with a more precise DHT22 (AM2302) [Aliexpress]. Both sensors are pin compatible. You can read great full comparison of them plus the Sensirion SHT71 [Aliexpress]. The DHT22 is better in accuracy and range to it’s cheaper sibling, but it also has a short life expectancy, so after all it’s a good idea to be able to replace it easily.


DHT11 and DHT22 (AM2302) side by side. They are pin compatible.

Off course replacing the sensor is not the full story, you will need to add support for the DHT22 to the firmware. More on this later on.


The DHT22 is also bigger than the DHT11. Make sure you place it so it does not protude further than the LDR capsule, otherwise you will have problems fitting everything inside the enclosure back again.

There is also an unused connector in the PCB meant for an LED. It’s driven by GPIO D7 in the ATMega328P through a 2N7002 mosfet in reverse logic (set to LOW to turn on). Remember you have an LED on the PCB as well driven by GPIO13 of the ESP8266 also in reverse logic. The 5V pin is connected directly to the USB supply, so if you have a good power supply you may as well connect here an WS2812 LED ring [Aliexpress] for some colourful notifications. You will need a GND connection too but there are quite a few available (and properly labelled) on the board already.


The LED connector side by side to the dust sensor one.

New firmware for the Sonoff SC

This custom Sonoff SC firmware is released as free open software and can be checked out at my SonoffSC repository on Github.

So after making myself comfortable with the hardware of the device I started putting together some pieces grabbing code from other projects like the ESPurna firmware. The goal was to replace the code in the ATMega328 and the ESP8266 microcontrollers to be able to integrate the Sonoff SC into my home network. That means no cloud, that means MQTT.

While doing that I have added some features that came almost for free since I had already worked on them in other projects: Domoticz support for those that use that home automation platform and a “clap monitor“. Yes. Clap your hands to switch on/off the lights.

Just like the original firmware, this custom firmware monitors temperature, humidity, noise level (in %), dust (in mg/m3) and light (in %).


First thing was to be able to send messages between the ATMega328P and the ESP8266. Itead Studio provides a simple firmware for the ATMega328P in the Sonoff SC wifi page. The firmware is a good starting point but I don’t like it’s architectured. Everything is too coupled.

So first thing was to create a communications library between both microcontrollers. I started looking for similar solutions and found out the SerialComm library by fjctp. It was almost what I was looking for but I liked the AT commands approach, one char keys are too minimal and naming is important. So I wrote the SerialLink library that allows me to:

  • Compatible with AVR and ESP8266 ICs
  • Define custom commands (the library is agnostic) like AT+TEMP
  • Query command management (AT+TEMP=?)
  • Optional automatic ACK responses
  • Tolerant to noise in the line (debug output from the other controller)
  • Callbacks for get and set values from the application
  • Custom separator (=), terminator (\n) and query (?) chars
  • Currently, it only accepts integer payloads

In the picture below you have a sample of the communication between both microcontrollers. The ESP8266 debug messages are quite verbose but only those starting with AT+… are answered by the ATMega328P. These are configuration messages “AT+EVERY=60” (set update interval to 60 seconds), “AT+CLAP=1” (enable clapping monitor) and “AT+PUSH=1” (enable message push from the ATMega328P to the ESP8266). Further down the log you start seeing MQTT messages due to push messages from the AVR about a clap code or sensor data.


The SerialLink library is currently bundled into my SonoffSC repository. I will create it’s own repo soon.

MQTT and Domoticz

MQTT and Domoticz integration was easy since most of the code was already there in the ESPurna firmware. I configured the communication link for push messages so in the ESP8266 side I have a callback function that gets all the messages from the ATMega328P and dispatches them to the different outputs.

In this code fragment you can see how message keys are matched and messages are forwarded to three different clients: MQTT, Domoticz and broadcasted to websocket clients like the web interface.

bool commsSet(char * key, int value) {

    char buffer[50];

    if (strcmp_P(key, at_code) == 0) {
        mqttSend(getSetting("mqttTopicClap", MQTT_CLAP_TOPIC).c_str(), value);
        return true;

    if (strcmp_P(key, at_temp) == 0) {
        temperature = (float) value / 10;
        mqttSend(getSetting("mqttTopicTemp", MQTT_TEMPERATURE_TOPIC).c_str(), temperature);
        domoticzSend("dczIdxTemp", temperature);
        sprintf(buffer, "{\"sensorTemp\": %s}", String(temperature).c_str());
        return true;



Clap monitor

Now, this is more like a game feature. Don’t know if it’s really useful but it’s certainly fun to play with. Have you ever wanted to move someone by clapping your room lights into romantic mode? Well, this feature is about that.

The algorithm for clapping recognition is somewhat hard if you want to make it reliable, remove false positives and avoid “losing” messages. It’s not certainly suited for a noisy environments (I have kids at home…). My current approach is:

  • The ATMega samples the mic analog output (amplified) in 20ms windows and calculates peak-to-peak values
  • If peak-to-peak value is higher than a certain threshold during N consecutive time windows it flags it as a clap as remembers the current time in milliseconds
  • From the second clap on it stores the time between claps (there is also some debouncing code here)
  • After the last clap times out it checks if it has recorded any intervals (so that it has sensed a minimum of two claps in a row).
  • Clap intervals are coded into binary values. The value always starts with a 1 and each interval pushes a new bit from the right ad shifts everything up. The first interval length is considered a “short” or a 0. If an interval is at least 1.5 times bigger than the first one it is read as a “long” or a 1.
  • Finally the intervals array is reset and everything starts over again

This way I can encode clapping patterns as one byte codes. Two claps are always a “short” so it will be coded as b00000010 or 2. Three claps evenly spaced in time will be a b00000100 or 4. But if you leave a longer time (less than a second) between the second and third claps you get a b00000101 or 5.

I admit it’s somewhat weird but you easily get used to it. “Clap, clap,… clap, clap” (that’s a 10) and switch on the mirror light. “Clap, clap, clap, …. clap” (that’s an 9) and there goes the living room one.

Right now clapping codes are sent by MQTT to a user defined topic. So it’s a matter of having a service somewhere in you local network translating them to MQTT topics to perform different actions. This is a my test flow in Node-RED at home:


And the code of the “matching” function node is below. Those are ESPurna devices, payload 2 means toggle relay.

if (msg.payload == 9) {
    msg.topic = '/home/living/lamp/relay/0';
    msg.payload = 2;
} else if (msg.payload == 10) {
    msg.topic = '/home/mirror/light/relay/0';
    msg.payload = 2;
} else {
    msg = null;
return msg;

And in the future…

There are some features I’d like to add in the future. One thing is that the device has a microSD slot connected to the SPI lines of the ATMega328P. Log sensor data to an SD card could be an option here for non-connected mode.


Also I’d like to be able to map clap codes to MQTT topics, hence not needing an external service like NodeRED to do that.

A neat feature would be to be able to OTA flashing the ATMega328P form the ESP8266. It should be possible with a minimum hardware hack: wiring the RST pin in the ATMega328P header to the SDA (GPIO2) pin in the ESP8266 header to reset the AVR programatically.

Also, there are some spare GPIOs available in the board that could be used to add more sensors (the SPI header exposes 3 digital pins, but shared with the SD). Ideas?

Flashing the ESP8266

Flashing the ESP8266 is very easy since the header close to it has all the required connections (3V3, TX, RX, GND) and the button is connected to GPIO0. Press and hold the button while powering the board to set the ESP8266 into flashing mode. You will have to remove the TX jumper in the board to avoid the ATMega328P to interfere in the upload process.

My recommendation is to flash an OTA enabled firmware as soon as possible as use OTA from then on to update the ESP8266 firmware. This way you can keep the jumpers in place and debug the communications to the AVR IC.

Flashing the ATMega328P

The ATMega328P comes flashed with the Arduino bootloader so all you have to do is connect a USB to UART programmer [Aliexpress] to it and flash it from the Arduino IDE or PlatformIO. Notice that labels in the header are from the programmer point of view (weird). So wire RX to your programmer RX, TX to your programmer TX and RST to DTR. Use 5V logic. Also, you don’t want the ESP8266 interfere with the upload so remove the RX jumper that connects both microcontrollers. Actually remove both of them or the ESP8266 might complain with so much noise.


The ATMega328P comes with the Arduino bootloader so you can flash it using a USB to UART programmer (and FTDI-like). You will have to unbridge the connections to the ESP8266 to do it to avoid the ESP8266 interfere in the upload process. Photo by Itead Studio.

But, if you have an AVR programmer like the USBASP v2 [Aliexpress] below, it might be a better option to program the ATMega328P using the unpopulated ISP header in the board. This way you won’t have to disconnect the jumpers between both controllers and have a stable test bed


The USBASP programmer I use to flash the firmware in the ATMega328P


I’m using the ISP header to flash the ATMega328P and OTA to update the firmware in the ESP8266. This way I have everything connected and I can debug both microcontrollers using two USB to UART boards.

I use only RX lines connecting the RX of programmers to the RX pins in both headers (remember: RX to RX). Grounds are shared through my computer, but you might have to connect those too for better reliability.


Test and debug. ISP for uploading ATMega328P firmware, OTA for the ESP8266 and two RX llines to get debug messages from both microcontrollers.


The application web interface is stored in the ESP8266 using the same compression techniques I use for the ESPurna firmware. Right now you can:

  • Check the current values from the sensors
  • Configure up to 5 different WiFi networks (including the option for static IP)
  • Configure the MQTT connection and topics for the different sensor data
  • Configure the integration with Domoticz
  • Change the hostname (used for the DNS discovery feature: http://myhostname.local)
  • Change the sensor update interval
  • Enable/disable the clap monitor feature

The interface is based on jQuery and PureCSS. Here you have screenshots from the pages in the interface so you can get a better idea of what it can do at this moment.






Right now it’s a fully working firmware replacement for the Sonoff SC. You will maybe miss some features from the original firmware. Let me know which ones. Use Github (link below) to report issues or feature requests.

This custom Sonoff SC firmware is released as free open software and can be checked out at my SonoffSC repository on Github.

Any comments are more than welcome.

CC BY-SA 4.0 Sonoff SC with MQTT and Domoticz support by Tinkerman is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

186 thoughts on “Sonoff SC with MQTT and Domoticz support

    1. Xose Pérez Post author

      I got it from Itead. I’m not aware of any distributor atm. But it might be available from aliexpress in the future, like other Sonoff devices.

  1. Stuart Feltham

    This is great, and I think exactly what I want for my own setup… basically just publishing of the status of each sensor over MQTT at regular intervals. I’m so impressed I will probably just use your firmware as is, but I do have one question.

    I’ve read your whole article so apologies if you’ve said this and I’ve missed it, but can I disable the domoticz integration easily? I use Home Assistant for my home automation and I don’t want that bit, but if I can avoid a partial rewrite that would make the process of getting these setup a lot quicker.

    Just as a note, the thing that excites me about this most is the possibilities that the mic has to monitor the noise in a room. I could use that to sense when someone has left a room and not turned the light off and do it automatically. EG if the noise level has been below a threshold for 10 minutes then flash the lights to indicate that the light will be turned off in 60 seconds unless noise is sensed above the threshold. I know you said you have kids so I’m sure this is a scenario you must be familiar with. 🙂

    1. Xose Pérez Post author

      Thanks for your comment.

      You have two options to disable Domoticz. First one is “hard” and the recommended, just set ENABLE_DOMOTICZ to 0 in code/espurna/config/general.h and rebuild. Second option is “soft”, just leave the IDX of the different magnitudes to 0.

      That’s actually a great feature and not hard to implement. I have the impression that the amplifier circuit in the SonoffSC is too sensitive, it quickly climbs and saturates the analog input. Maybe that would require some algorithmic work.

      1. Stuart Feltham

        Thanks, for the feedback.

        I’ve just had a look at the code on Github and I could have worked that out about the Domoticz setting if I’d had a more thorough look! Sorry.

        I’ve not ordered a SonoffSC yet, money is still a bit tight post Christmas, but I hope to get round to it soon. If you had time to (and wanted to of course) do some experimentation on the occupancy sound feature I’d be very grateful for the help. I have a software background, but this kind of programming is still very new to me. I’d be delighted to help too of course if I can and I’ll give it a go when mine arrives if you’re not interested in implementing that into your software yourself. I entirely understand if you’d rather not.

        Your note about the saturated input is interesting. You said that the noise level is reported in %. What sort of sound level would cause the device to report a 100% level? I was thinking (in my brief musings) that if you allow the user to monitor the room when quiet and also when occupied then you could create a user editable threshold for when occupancy would be assumed. That way it could be used in all sorts of situations unless a background noise like a heater or fan etc is going to saturate the mic.What do you think?

        1. Xose Pérez Post author


          The noise input is an analog pin in the ATMega328, so it goes from 0 to 1023, I just translate it to % in code because it makes more sense to human beings. But maybe I should apply some kind of logarithmic calculation first. Anyway, it will take some time to experiment with different backgrounds. I noted than a kid talking in their higher than average tone and trying to make herself listened sometimes saturates the input.

          I’m not forgetting about the occupancy feature, but I cannot commit to work on it just now. Will let you know.

  2. Jeff Fox

    I like Stuart’s idea of using the mic to check for room occupancy. Along with that perhaps you could add a PIR sensor if there is a good way to mount it without making ugly modifications to the case.

    1. Xose Pérez Post author

      There is a plastic tube inside the SonoffSC where the sensors fit. Between the tube and the outside body there could be room for a PIR. A Panasonic PIR [Amazon US] for sure, maybe even one of the “standard” ones too.

        1. Xose Pérez Post author

          That’s a good idea. Microwave sensors can sense objects moving even through doors or thin walls so the Sonoff case won’t be a problem.

    1. Xose Pérez Post author

      I have a 12 LEDs ring and it does not fit in. Maybe a better solution would be a LED strip and stick it to the inner side of the tube. Still, the LDR might complain 🙂

          1. Xose Pérez Post author

            Awesome!!! That’s a hack I’m going to do myself for sure. My kids will love it! Thanks for sharing!

          2. justblairthompson

            I wonder if you will have a look at my github.. I will do a pull request, but I dont expect you to use it necessarily. I wanted initially to get the rgb ring doing something (which it is).

            I also found that I needed to run comConfigure() in setup. without it my at328 was not getting instructions to start up.

            Your code is complex. I am looking to see how to control the leds using mqtt. I cant quite see if your code is listening on MQTT or simply publishing. Perhaps you can give me some pointers.

          3. Xose Pérez Post author

            I have just seen your PR. Of course I will have a look at your code.

            I see the problem with the comConfigure. Do you want to open an issue in the repository?

            I’m not subscribing to any topic in the code of the Sonoff SC. But the code base I’m using is the same as in my ESPurna firmware. Since I use an aynchronous MQTT library, all actions are executed via callbacks. You only have to create your callback method like in the example below and call “`mqttRegister(mqttCallback)“` in your setup.

            void mqttCallback(unsigned int type, const char * topic, const char * payload) {
            	// When connected, subscribe to the topic
                if (type == MQTT_CONNECT_EVENT) {
                if (type == MQTT_MESSAGE_EVENT) {
            		if (strcmp(topic, MY_TOPIC) == 0) {
            			Serial.printf("Received %s\n", payload);
          4. justblairthompson

            Had some success with this thanks… but then realised that the seriallink library was not going to let me pass uint32_t values without breaking loads of stuff.

            Got R, G and B values transferring via seperate AT commands now and it works well. Broke something tonight in the ESP8266 sketch, hopefully work it out tomorrow

          5. Xose Pérez Post author

            Yes, the SerialLink library only accepts integers at the moment. It would not be hard to change it to use longs so you can send 4-byte payloads…

          6. Blair Thompson

            Ah it makes no difference I think. I am pretty sure that I fixed the ESP8266 Sketch this morning,. just need to try it tonight and then I will put in a pull request,

            I could already separate out the rgb values from a mqtt message (using commas as delimiters), so I think it will work.

            Assuming it does I can then add responses from my Openhab2 rules to provide a colour status indicator.

            Starting to think of other modes:

            * Temperature indication (Green = just right, red = too hot, blue = too cold)
            * Flashing air quality warning
            * Assistive technology applications for the hard of hearing
            * Doorbell indicator
            * Silent Phone ringer

          7. Blair Thompson

            I am not brilliant with github… I have completed the changes you suggested on the pull request, but I don’t know how I am supposed to tell you that has been done. 🙂

          8. Xose Pérez Post author

            No problem. I can see your PR changes, it’s just that I had no time to review them and merge the files. Will do as soon as I can.
            Thank you very much for your code. I’m waiting for a 24 LED ring to arrive to do your hack on my Sonoff SC 🙂

          9. Xose Pérez Post author

            Great video! Thanks for sharing.
            Hope it won’t take long for my LED ring to arrive!

      1. Simon (sjp770)

        I got a 24 led ring, but its a mm or so smaller than outside diameter of the inner sensor tube. I melted down the bits it was catching on and it fits tightly. Also cut out of the mid plate of the case to allow a 2×3 pin header to be installed facing up to the sensor, now its easy to connect the rgb ring.

          1. Simon (sjp770)

            I think the density changes on different strips / rings. You pay more to get more pixels per meter. I have a set of 4x nested ones on the way for about the same price. This time instead of a quick ebay delivery i’ll have to wait for the slow boat from China.

  3. Thomas

    Hi, I was doing exactly the same with this product. My goal was to get more precise data from dust sensor (instead of three levels from original sonoff firmware).

    I wanted to do a first test using your code but I saw you put a symlink for SerialLink.h instead of original file to github 🙂

    Anyway… good post and happy tinkering 🙂

    1. Xose Pérez Post author

      True, got to fix that. Anyway the original SerialLink library is in the “common” folder in the same repo. Just copy it over to the “lib” and it should work.

    1. Xose Pérez Post author

      You will first need to connect to an MQTT broker using the MQTT component. The minimum you will have to configure is the broker IP, but a more complete configuration will look like this:

        port: 1883
        username: USERNAME
        password: PASSWORD
        client_id: home-assistant-1
        keepalive: 60
        protocol: 3.1
          topic: '/service/hass/status'
          payload: 1
          qos: 1
          retain: true
          topic: '/service/hass/status'
          payload: 0
          qos: 1
          retain: true

      Next you will have to configure sensors using the MQTT platform. A simple example is:

        - platform: mqtt
          state_topic: "/home/living/temperature"
          name: "Livingroom Temperature"
        - platform: mqtt
          state_topic: "/home/living/humidity"
          name: "Livingroom Humidity"

      The topics will be those defined in the MQTT tab of the SonoffSC device flashed with my firmware (actually the concatenation of the root topic plus each of the magnitude topics).

  4. cnxsoft

    I’m trying to use Sonoff POW with Domoticz, and while I’ve create “MQTT Client Gateway with LAN interface” in Domoticz, I guess I have to create another device to get data from Sonoff POW.
    Looks at the code it seems only the relay is supported, not the power usage data, is that correct?

    1. Xose Pérez Post author


      I just read your review about using the Sonoff POW with ESPurna and Domoticz. Great job. I’m glad you find ESPurna useful. I added a comment to let you know that support for telemetry data to Domoticz will be release soon (maybe this same weekend). Depending on your hardware you will be able to send active power, current, voltage, temperature or humidity.

      Besides the “MQTT Client Gateway with LAN interface” which basically enables Domoticz as an MQTT client you will need to add a “Dummy (used for virtual switches)” hardware and a virtual sensor on top of it of type “Sensor type switch”. I don’t use Domoticz myself and I find the procedure a bit confusing, but it works.

  5. Pingback: How to use Sonoff POW with ESPurna Firmware and Domoticz Home Automation System

  6. Pingback: IOT heatpump controller - EcoRenovator

  7. Glenn Bollue


    Thanks for this blog, but I have an issue with my Sonoff. I did the same steps mentioned in this blog but on the webpage of my sonoff I can’t read any value and it’s also not repsonding in the Home assistant. I also included the steps that is mentioned for the Home Assistant Configuration.

      1. Glenn Bollue


        Yes the filesystem is flashed too and I can see the webpage but all the boxes are empty, for some reason it is not communicating with my raspberry/home assistant. I’m pretty new to this.

        btw a friend of mine did the same steps and he can read the values of his sonoff (he don’t know what is the delta with my layout). I can’t see the messages either.

        kind regards,

        1. Xose Pérez Post author

          By “all the boxes are empty” you mean there is no info in the web interface? No IP, ChipID, Hostname,…? I’d like to ask you to open and issue in the repository to do a proper follow-up. It helps me a lot to have everything (bugs, requests,…) in a single place…

      2. Glenn Bollue


        Not sure if my reply came thru, but yes I flashed the filesystem and still no success my textboxes from the sensors are still empty. My broker is the IP coming from my raaspberry pi/ home assistant.

        kind regards,

        1. Simon (sjp770)

          If only the sensor data is not showing maybe reflash the atmega chip? Make sure the jumpers are removed and the RST is connected to DTR. Then ensure the jumpers are back in place.

        2. Simon (sjp770)

          I found my issue (same – no sensor values) – because I burnt out the socket on the board for the DHT11 and I neglected to replace it there is a trace carrying 5v between the two smd resistors I had broken. I now have my DHT22 on D13 in the ISP header, pulling 5v from the spare header on the top of the board, gnd from the programming header and I bridged the two SMD resistors. All fixed.

          So i’d say if you fiddled with that area of the board check your soldering.

          1. Adam

            Can you provide more details and or photos of what you did? I think I have severed the connection between the Arduino and the ESP8266 trying to replace the soldered on DH11 🙁

          2. Xose Pérez Post author

            I have one of the first batch of Sonoff SCs and the DHT11 was not soldered but simply plugged to a JST connector.

  8. Simon (sjp770)

    Very keen to flash the chips of the sonoff, but the arduino IDE cant compile because DebounceEvent.h is missing. Are you using a different system to flash that fetches the libraries? I’m following along with Blair Thompson after his youtube vid, and will have the neopixel ring installed as well.

    Is there room / a way to have functions like a colour sweep or fire animation stored on the arduino chip and just call them with mqtt and a duration? Really hoping to have some dynamic lighting options as well as just rgb modes.

    1. Xose Pérez Post author

      Hi Simon

      I use PlatformIO as my development environment and it fetches all the dependencies itself, very useful. You can find the DebounceEvent library in its repo here: You can also download it as a ZIP file ready to install from your arduino IDE.

      I’m waiting for my LED ring too, eager to do Blair’s hack on my Sonoff SC. And I know myself and I know I will add more functionality to it. Taking note of your idea. Thank you!

      1. Simon (sjp770)

        Thanks for the links. Sorry for requesting them over on the espurna bitbucket issue tracker! I’m still new to git type repos. When I go to flash the atmega328p i get the following:

        avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe0
        An error occurred while uploading the sketch

        Is it because ive chosen the wrong board type or programmer within Arduino IDE? if so could you detail the settings I need to flash it?

        One last query – could you run the RGB ring off the ESP8266? Scargills blog and detail how to upgrade the memory chip if storage of code is a limitation.

        1. Xose Pérez Post author

          The error is probably due to a bad wiring: TX and RX are mislabelled, you should connect TX in the board to your programmer TX line, same for RX; also connect RST to DTR. The board is a Arduino/Genuino UNO compatible.
          The RGB ring code could be moved to the ESP8266, sure. It was Blair’s decision to do it in the atmega328. The SonoffSC uses a 1Mbyte memory chip for the ESP8266, it’s more than enough to store several animations and thousands of other stuff on it.

  9. Simon (sjp770)

    Any more info on troubleshooting? I have both flashed now and get the RGB rainbow flash on my neopixel ring, but the web interface doesnt show any values for any of the sensors. Also are the mqtt topics just as per the web interface or is there anything else on them? The TASMOTA firmware for the sonoff was /cmnd/sonoff/power but the web interface only showed /sonoff as the topic.

    Do you have the topic and payload to send RGB values to the Sonoff SC?

    1. Xose Pérez Post author

      For the sensors you can define the topics in the web interface (root topic + sensor topic). The only one not there yet is the RGB that is fixed to root topic + “/rgb”. The payload is a 3 number string comma separated, each value being from 0 to 255. So if you want to set it read send “255,0,0”. At the moment is only allows single colors.

  10. Ewald Harmsen

    This guide is fantastic! Thanks!

    Do you know if it is possible to just flash the ESP8266 chip with ESP easy?
    Will it still be able to receive the data from arduino and sent it to domoticz?

    1. Xose Pérez Post author

      Don’t think ESPEasy has support for the custom messages the ATmega328 is sending (either the factory ones or the ones I defined). You should ask in the ESPEasy forum.

  11. MiKa

    My Sonoff SC is still in AP mode, i configured network parameters but cannot connect to WiFi network, not working with fix IP and with DHCP too. Wifi have hidden SSID… Some reccomendations?

    1. Xose Pérez Post author

      It’s probably due to the hidden SSID. You can modify the wifi.ino file and modify the line that says:




  12. Miroslav Kartal

    I cant connect my Sonoff SC to my Wifi Network.
    I configured and double check all parameters, Device is still in AP mode, dont work fith fix IP and DHCP too
    Some hints?

  13. Simon (sjp770)

    Worth noting the v1.1 of the PCB has the DHT11 directly soldered to the board. I failed to replace it as the solder wouldnt grip to the holes after I had removed the old sensor.

    1. Xose Pérez Post author

      Oh! Bad news. The firmware supports both sensors and even thou the DHT22 is not my favourite it is certainly better than the DHT11.

      1. Simon (sjp770)

        Which pins are available to connect to on the 2×3 pin header? I’m thinking of a fix for my temp probe. Looks like I need a resistor from the 5v to the data pin, but 5vdc and gnd are exposed on the 2 pin header on the top of the board, just need a free data pin thats not the one im using for rgb.

  14. Santi

    Hi Xose,

    I am thinking to buy the sonoff sc with the 1 Channel Inching /Self-Locking WiFi Wireless Switch 5V to control my gas boiler using the cloud of itead. The problem is that I have read the temperature sensor has +-2ºC of accuracy and it is a lot of a house.

    can I change it by the dht22 with the original firmware or it is necessary change the firmware?


    1. Xose Pérez Post author

      Hi Santi

      The original firmware does not support the DHT22, or at least there is no documentation on how to do it. And since Itead’s cloud is not open source and no public API available, you will have to decide weather to use a better sensor or use Itead’s Cloud.

  15. falk

    I can second the detail about the DHT11 soldered to the board in rev.1.1 – also my SC came without the Jumper for the TX and RX pins. There is one other thing – I am not sure the dust sensor can work the way it is now – normally it needs an airflow through the hole. I will maybe print something that will force the warmed up air from below (warmed by the electronics) through the hole.

    I will try to add a CO sensor later as well but that’s for the future since they are still on their way.

    1. Xose Pérez Post author

      Hi Falk

      You are probably right about the dust sensor, since 11st January the maximum value it has reported has been 0.21 mg/m3…

  16. D-mah

    Hello Xose,

    first of all thanks a lot for your great job!
    I’m trying to get my Sonoff SC run but I have some minor issues.

    I flashed the ESP and ATMega as well.
    WiFi Connection is established with Sonoff SC but I can’t see any UI from web.
    I’ve typed the credentials in, but afterwords nothings appear.

    Do you have an idea what is happening?
    Thanks in advance!

    1. Xose Pérez Post author

      You have to flash the filesystem image too… If you are using PlatformIO just type “`pio run -t uploadfs“` from the esp8666 folder of the project. If you are using the Arduino IDE take a look at the section in the Arduino Core for ESP8266 wiki about uploading files to the file system. The files to upload are already in the data folder, where the SPIFFS Uploaded tool will look for them.

      1. D-mah

        Hi Xose,

        thanks for your fast reply!
        At least I switched to platformio IDE, due to issues with Arduino IDE. There it worked like a charm, thanks a lot!!

        I’m using now Sonoff_Sc with FHEM via MQTT, works perfect!

        1. Xose Pérez Post author

          Great. I strongly recommend using PlatformIO. But just out of curiosity: what problems did you face with Arduino IDE?

          1. D-mah

            I had problems to flash the SPIFFS filesystem. In detail I got following error:

            SPIFFS_write error(-10001): File system is full.

          2. Xose Pérez Post author

            The Sonoff SC comes with a 1MByte flash memory. When building your project from Arduino IDE be sure to select “Flash Size: 1M (128K SPIFFS)” from the tools menu.

    1. Xose Pérez Post author

      I don’t. But you can check the video tutorials by Andreas Spiess or Blair Thompson in Youtube. They both cover the Sonoff SC with hardware and software modifications.

  17. martin

    when i will flash with plattformio i get the error sonoffsc-master/esp8266/sonoffsc/comms.ino:9:24: fatal error: SerialLink.h: No such file or directory

    1. Xose Pérez Post author

      The SerialLink library is in the “common” folder in the repo. If you are using Arduino IDE you will have to “install” the ZIP file in “Sketch > Include library > Add .ZIP library” form the IDE.

  18. Juan

    Hi Xose,

    I have created an issue at sonoffsc github:, Embedis EEPROM dictionary doesn’t work with SerialLink.

    Hope you can take a look. Have you tested embedis terminal at esp8266 serial interface of SonoffSc ?.
    I was not lucky getting responses.


    1. Xose Pérez Post author

      Embedis commands are disabled because I did find they were not compatible with serial communication with the ATMega328. The parser is handled in the settingsLoop method which is not being called in the main loop.

  19. Jon-Magne Johansen

    Would it be possible to include the SonoffSC code in the normal ESPurna code? Of course just the ESP code. In that way, the Atmega could be handled as a normal sensor.
    I use Domoctiz, but the SC code has a bug, so no readings is passed to Domoctiz.
    Compare the domoctiz sections of the SC code with the same in the ESPurna code, and note that the sprintf.. lines are different.

    1. Xose Pérez Post author

      ESPurna and the ESP8266 part of my SonoffSC code share a lot of code, still they are different products. I don’t really see a need for that. Of course I can change my mind but at the moment I don’t feel like investing time in this. If you find a bug in the SonoffSC code please report it to the issues sections in the repo.

  20. Learn Smart

    Can you help me? I do not know how to configure and control MQTT_RGB_TOPIC MQTT information in homeassistant,this is no working:

    – platform: mqtt
    name: “sonoffsc RGB”
    state_topic: “/test/sonoffsc/rgb/status”
    command_topic: “/test/sonoffsc/rgb/switch”
    #brightness_state_topic: “/test/sonoffsc/rgb/brightness/status”
    #brightness_command_topic: “/test/sonoffsc/rgb/brightness/set”
    rgb_state_topic: “/test/sonoffsc/rgb/rgb/status”
    rgb_command_topic: “/test/sonoffsc/rgb/rgb/set”
    state_value_template: “{{ value_json.state }}”
    #brightness_value_template: “{{ value_json.brightness }}”
    rgb_value_template: “{{ value_json.rgb | join(‘,’) }}”
    qos: 0
    payload_on: “ON”
    payload_off: “OFF”
    optimistic: false

    1. Xose Pérez Post author

      I have not modified my SonoffSC to add Blair’s hack but plan to do so soon. Then I’ll be in better position to answer your question.

  21. Roger

    Excellent work.Many thanks for you!

    The DUST sensor, I felt it so inaccurate. Waiting for a update firmware with RGB light control.

    1. Xose Pérez Post author

      The main problem with the dust sensor is that there is no air flow inside the enclosure. Adding a small fan (how or where I don’t know) would probably improve the range of values.

  22. Vadim

    Hi, I am just wondering what I need for this project. Do I need USBasp USB ISP 3.3V / 5V AVR Programmer only? Or I need this one as well: FT232RL FTDI USB 3.3V 5.5V to TTL Serial Adapter ?
    Or I need both? I am not planning to debug, just want to flash to this firmware that has great Cloud independent interface. Please help!

    1. Xose Pérez Post author

      You will need the FTDI board to flash the ESP8266 in the SonoffSC. I used the USBasp to flash the ATMega328 but you can also flash it using the FTDI, only it’s a little more involved since you have to remove the jumpers to flash it and connect them again to test it, every time. If you plan to just flash it once and forget the FTDI might be all you need, but bugs happen 🙂

  23. Andi

    a really cool projekt. Fun and joy to read 🙂

    I didn’t have a closer look at your code yet. What I was thinking on first sight:
    What about using retained messages for MQTT sensor data?
    define MQTT_SKIP_RETAINED 1 => 0

    If you do a simple “has value changed since last meassure” and only send it as retained after a change, it would reduce bandwith and energy.

    And for it seems as if theese little devices would multiply themself, it might be worth thinking about.


    1. Xose Pérez Post author

      It is worth thinking about, for sure. A lot of my sensors just report the same value over and over, like: “door closed”, “door closed”, “door closed”. Of course my house door is only opened a few times a day and for a brief time. Same with these MQTT devices. But at the same time these repetitive messages double as heartbeat messages. I guess the point is to be able to tune it to your needs.

  24. Learn Smart

    can you help me? if i use the ESPurna Firmware(Version 1.7.1) ,DebounceEvent library Version can not support SC Firmware,can you update DebounceEvent library to support ESPurna Firmware(Version 1.7.1) and SC Firmware both of them。

    1. Xose Pérez Post author

      That upgrade shouldn’t be too difficult but I’ll be soon working on the SC, so yes 🙂

    1. Xose Pérez Post author

      I see. No, ESPurna does not support the PSB-04. I suspect it uses the same protocol as the DUAL, with a Silicon Labs F330 handling the buttons and relays, but I have no way to test it.

          1. Xose Pérez Post author

            This is not the same device you previously linked from Itead. This one is based on the PSF-B85 (a carrier for the ESP8285), not the PSB-04.

  25. George Pucci

    Great Work !!

    I just flash my Sonoff(version 1.1 – DTH soldered in the board) today but it show weird temperature (640) and humidity (1512) values !!! I dont change DHT11 sensor, so i leave DTH_TYPE parameters with DHT11. Before update firmware, Itead app show correct values !!

    1. Xose Pérez Post author

      Don’t have a 1.1 version. Things to check:
      * GPIOs are the same?
      * Does it have a pull-up for the data line?

      1. George Pucci

        Sorry, 1.1.0 is the version of debounceevent !!! I find the error. Need to change the setting in plataformio.ini file too !! Now all is fine !!

        Thanks !!

  26. George Pucci

    After 4 days working, my Sonoff SC stops to show values in the sensors fields !! I just flash atmega again (Atom + IFTDI + all wires + remove the jumpers), upload process ok, but no luck with the sensors !!

    1. Xose Pérez Post author

      Why don’t you open an issue on Github to found out what’s going?
      Thank you

      1. Peter

        I left a reply further up on this issue. I have also seen it. It seems that the 328 misses the AT+PUSH=1 command and sometimes just sits there waiting for it. I discovered this while I had debug console and sent it manually and everything came back. Also changing the update frequency gets it going again. Timing issue perhaps?

        1. Xose Pérez Post author

          Do you mind opening an issue on github for this? It will be better tracked there. Thanks!

  27. Nico Copica

    Hello and thank you for your work!

    I’m having an issue with the web interface. I have flashed the ATMega and the ESP with success. I am able to connect to the Sonoff SC through Wifi. The password is asked and authentication seems successful. But then nothing happens, I can’t see any interface.

    Would you have an idea of something I did wrong or is there a way to access to settings by another way ?
    Thank you

      1. Nico Copica

        Thank you so much! I flashed SPIFFS using the Arduino IDE and I can now access to UI.

  28. Peter


    Tried to compile using both PlatfromIO and Arduino IDE. It seems the DebounceEvent library may have changed as I am getting this error in either platform.

    C:/Users/HA/CloudStation/ In function ‘void buttonLoop()’:
    C:/Users/HA/CloudStation/ error: ‘class DebounceEvent’ has no member named ‘getEvent’
    uint8_t event = _button.getEvent();
    C:/Users/HA/CloudStation/ error: ‘EVENT_DOUBLE_CLICK’ was not declared in this scope

    if (event == EVENT_DOUBLE_CLICK) createAP();
    C:/Users/HA/CloudStation/ error: ‘EVENT_LONG_CLICK’ was not declared in this scope
    if (event == EVENT_LONG_CLICK) ESP.reset();

    1. Xose Pérez Post author

      The SonoffSC code uses version 1.1 of the DebounceLibrary, but latest version in the repository is 2.0. You can either checkout tag 1.1 or change the dependency line in platformio.ini to

      1. Peter

        LOL thanks I posted this then almost immediately saw the issue in Github. Anyway I now have the right lib. Thanks and great work. I was thinking of doing this myself but why re-invent the wheel so to speak.

  29. Peter

    Xose I also have the issue where it seems I cannot get out of AP mode. I am not sure how to make the SC connect to my WiFi access point so I can connect it to my mqtt broker. I have added the WiFi details correctly and pushed RECONNECT button but it just comes back into AP mode. Also when it comes back it loses the WiFi password and I have to re-enter it again. Also sensor data is empty so I guess it’s not talking to the 328. Sorry to trouble you.

    1. Xose Pérez Post author

      Do you have the option to connect it via serial to your computer to debug? You can easily add the proper commands via the command line (connected to the ESP8266, that is). You can do:

      set ssid0 YOURSSID
      set pass0 YOURPASS

      And you should see the log of the connection process.

      About the communication with the ATMEGA, again, in the debug console you should be seeing the messages from the ATMEGA328 as AT commands (AT+TEMP=25, for instance). If you don’t see anything maybe you have not flashed the ATMEGA properly.

  30. Peter

    Yes I can see Serial. Keeps looping with “Scanning” and says no known networks found. I try and set it via Serial but it doesn’t accept any commands. When I connect to the units AP and the Webpage I see [WEBSERVER] Request: GET / on console until the next “Scanning” happens and then it kicks me off the AP and I have to reconnect. Sensors show as ZERO. I don’t have USBAsp but when I connect to the 328 I see AT+HELLO1 so the 328 is responding but I cannot see the flow between them unfortunately.

  31. Peter

    Xose sorry about multiple messages. You may delete them. I can confirm that the 328 is working correctly. If I send AT+EVERY=30 I get a sensor reading which is populated with numbers no problem. Clap detector is also working with AT+CODE=2. So it leaves all issues in is ESP it seems. One thing I haven’t done is install GULP? Could this be the issue?

  32. Peter

    Xose I have it going. I have no idea why but it seems the flash was corrupt on the ESP. I filled it full of 0’s started everything from scratch and I have it working. Thanks for your great work, Obviously you don’t need to publish this if you don’t want to 😀

    1. Xose Pérez Post author

      Sorry, I’ve been busy lately but I’m happy to see you have sorted it out. Yes, I have also had that issue before and flashing again solves the problem.

  33. Steve Lenehan

    Love the system you have created – works well. I have one query, you have defaulted the Domoticz support to writing to the nvalue’s whereas many of their standard Domoticz devices expect the updates to arrive in the svalue field. I am currently intercepting and converting in node-red but if you were to revisit this can I suggest an option on the Domoticz status page that you could add a pair of tick boxes by each index to allow the installer to choose svalue or nvalue feeds for that index. Thanks again

    1. Xose Pérez Post author

      I’m not a Domoticz user myself so I’m ot familiar with some of the specifics.

      May I ask you to open an enhancement issue on bitbucket for this? Thank you!

  34. Russ

    Hi.. I Just flashed the ESP8266 firmware and I can see that an wifi AP is available but can’t find the password. Sorry but just spent hour going through all the scripts trying to find it.. Can you help please?

    1. Xose Pérez Post author

      The default password is “fibonacci”, it’s defined in the general.h file.

      1. Russ

        Thanks very much. I did eventually find the password. But then I realised when I had flashed the esp firmware with arduino that I didn’t include the SPIFS part.
        Again found after several hours found that for me this only worked with Arduino 1.65 r5 (1.66 and 1.8 Not working ) also using version 0.2.0 of the ESP8266FS plugin worked wheras 0.3.0 Not working.
        I could then upload the SPIFS. But then I found the gz files needed to be extracted first from gz type to their proper files.
        Once this was done flashed the atmega firmware and was up and working.

        Only issue I have now is sending the sensor data to Domoticz part. The mqtt seems to be in the wrong format. I see an error in the domoticz log.

        2017-05-20 07:28:45.338 Error: MQTT: Invalid data received!
        2017-05-20 07:28:45.438 MQTT: Topic: domoticz/in, Message: {“idx”: 1706, “nvalue”: 43, “svalue”: “”}.
        This is the same for all the sensors.

        For now as a work around I am going to change the payload in node red and then send to domoticz.

        One other thing that might be useful. I noticed that the same mqtt server address as the domoticz server. It might be useful to be able to define these separately? (for instance I have my main mqtt broker on another pi than my domoticz)

        Apart from these small things . Thanks for an excellent piece of work

        1. Xose Pérez Post author

          The documentation in my Sonoff project is non-existant, I know, and that’s something I’d like to change when I have the time to do it. Maybe you could add an issue to the repository for the format thing, don’t know right now what’s going on there. As for the rest: hopefully I will be updating the code soon and flashing the SPIFFS “partition” will no longer be necessary. And the MQTT server you should be able to change it from the web interface and point it anywhere. The only thing is that both Domoticz and the SonoffSC should be using the same broker (or two different brokers bridget together).

  35. Steve Lenehan

    Hi Can I ask did you ever do the WS2812 hack and if so did you attch it to pin D7 as you suggest in the article. I am having real difficulty getting this to work although it works fine if I attach it to the MOSI header. I presume its because of the MOSFET architecture but just wanted to understand if I am just being thick.

    1. Xose Pérez Post author

      Actually I did the WS2812 hack and attached the LED ring to D12 (MISO in the ISP header) and it’s working like charm using the FastLED library (not the Adafruit Neopixel library Blair uses). I plan to write about it soon. Those LEDs are very time sensitive so maybe the mosfet introduces some delays, I’m not sure.

      1. Steve Lenehan

        Just so you’re aware if you change the hostname of the device the mqtt rgb command no longer works. The last function of the mqtt module needs amending to if (type == MQTT_MESSAGE_EVENT) {
        String mqttColor = (mqttTopic + (String)MQTT_RGB_TOPIC); //replaced line below to allow
        change of identity
        //String mqttTopic = (MQTT_TOPIC + (String)MQTT_RGB_TOPIC);
        if (strcmp(topic, mqttColor.c_str()) == 0) {

  36. Rodolfo Acosta

    Hola! fantástico! gracias por publicar tu trabajo! tiene una muy buena pinta esto. Para mi proyecto (un invernadero para cultivar hingos) quiero sustituir el sensor de polvo por uno de gas (mq135) y emular el hardware del sonoff con un arduino y un esp8266 v.1 dentro de un topperware o algo similar. Es difícil integrar el sensor mq135 en tu software? qué más tendría que hacer además de leer el sensor con el arduino y la respectiva biblioteca? Saludos desde Berlin!

    1. Xose Pérez Post author

      Hola, en principio no deberías tener problema. En el connector del sensor de polvo tienes un puerto analógico (A1) que es lo único que necesitas para usar un MQ135. Hay muchos recursos en internet sobre como utilizarlo pero fíjate que debes hacer un “preheating” para calibrar el sensor.

      Si lees el código de mi firmware para el SonoffSC verás que el código del ATMega328 básicamente lee los datos de los sensores y los envía via UART al ESP8266, después allí los coges haces lo que quieras con ellos.

  37. T. Reinartz


    Just got the sonoff SC flashed and it seems to be working. With both serial debuggers I am able to sew the values from the devices. Only the temp and hum stay at 0. But when I try to view the information in the web interface the values stay 0.

    Is there a good starting point to debug this issue? I think the dht sensor is broken somehow and this breaks some part of the application.

    Any help is appreciated. Many thanks in advance.

    1. Xose Pérez Post author

      The DHT sensors are really bad. It can easily be the sensor broken but try reconnecting it, sometimes a bad connection makes it fail.
      As for the data… if you see the readings going from the ATMega to the ESP8266 they should show on the web interface. Are the jumpers in place?

      1. T. Reinartz

        Hi xose,

        After some debugging I found that the atmega was fried for a bit so I replaced it with a arduino nano and now it works flawless.

        Thanks for the amazing firmware

  38. Tim Gray

    Where do you think I could stick a 433 reciever in there to also add a 433 MQTT gateway to use cheap 433 door sensors? did you map out what pins on the board are available?

    Thanks for the overview of this! Ordering 2 of them now for more hacking!

    1. Xose Pérez Post author

      You mean a transmitter, right? It will depend on your transmitter. Those cheap RF links require at least a 5V microcontroller so your chance is to use any of the atmega available pins, like the ones on the ISP header, check my other post about the SonoffSC for more info.

  39. Ron

    I received my SC and now I’m trying to flash the files to spiffs, but always receive the folowing error:
    I already tried to clear the flash ( –port /dev/ttyUSB0 erase_flash)
    Is there a way to fix that?

    Verbose mode can be enabled via `-v, –verbose` option
    before_build_spiffs([“.pioenvs\sonoffsc\spiffs.bin”], [“sonoffsc\data”])
    [23:50:29] Using gulpfile ~\Downloads\sonoffsc-0.3.0\esp8266\gulpfile.js

    [23:50:29] Starting ‘clean’…
    [23:50:29] Finished ‘clean’ after 4.28 ms
    [23:50:29] Starting ‘files’…
    [23:50:29] Starting ‘html’…
    [23:50:30] Finished ‘files’ after 705 ms
    [23:50:37] Finished ‘html’ after 7.89 s
    [23:50:37] Starting ‘buildfs_split’…
    [23:50:37] Finished ‘buildfs_split’ after 7.76 ╬╝s
    [23:50:37] Starting ‘default’…
    [23:50:37] Finished ‘default’ after 2.22 ╬╝s
    Building SPIFFS image from ‘sonoffsc\data’ directory to .pioenvs\sonoffsc\spiffs.bin
    Looking for upload port…
    Auto-detected: COM3
    Uploading .pioenvs\sonoffsc\spiffs.bin
    Uploading 262144 bytes from .pioenvs\sonoffsc\spiffs.bin to flash at 0x000BB000
    …………………………………………………………………….. [ 31% ]
    …………warning: espcomm_send_command: didn’t receive command response
    warning: espcomm_send_command(FLASH_DOWNLOAD_DATA) failed
    warning: espcomm_send_command: wrong direction/command: 0x01 0x03, expected 0x01 0x04
    error: espcomm_upload_mem failed
    *** [uploadfs] Error -1
    ========================================================================================== [ERROR] Took 26.47 seconds ==========================================================================================

    =================================================================================================== [SUMMARY] ===================================================================================================
    Environment sonoffsc [ERROR]
    Environment ota [SKIP]
    ========================================================================================== [ERROR] Took 26.47 seconds ==========================================================================================

    1. Xose Pérez Post author

      Have you removed the jumpers that connect both microcontrollers? They are connected via the serial line, the same you use to flash the ESP8266 so a message from the ATMega328 while flashing the board is noise and aborts the process…

      1. Ron

        I have it working now, jumpers where already disconnected.
        my issue was i was using 2 usb-ttl’s . my 3.3v one isn’t detected in windows 10 so i used that to supply power but i think that was the issue .. swithed to linux so i can use only 1 and now it worked.. great tutorial 😉 and an awsome device 🙂

  40. Pingback: PIE Sonoff SC – อุปกรณ์ตรวจสอบสภาพแวดล้อมเชื่อมต่อ NETPIE – NETPIE BLOG

  41. E

    Very interesting post. If I may just add my own 2 cents… yes the DHT22 is more precise than the DHT11 but I wouldnt rate the difference worth it replacing the sensor, but to each his own. If you want accurate temps, go to a DS18B20 and with regard to humidity… does it really make a big difference to know if it is 63 or 68%?
    I have had DHT22’s next to eachother differing 3 percentpoints already.
    But besides that, really good article

    1. Xose Pérez Post author

      Thank you!
      And yes, you are right. Actually I’m replacing the DHT22 with HDC1080 in my recent projects.

  42. Levi Pereira

    First of all, tank you for sharing this.

    I have a issue and did not find solution.

    Here is the code:

    void mqttCallback(unsigned int type, const char * topic, const char * payload) {

    // When connected, subscribe to the topic
    if (type == MQTT_CONNECT_EVENT) {
    // Feel I should be using mqttSubscribe here…

    if (type == MQTT_MESSAGE_EVENT) {
    String mqttTopic = (MQTT_TOPIC + (String)MQTT_RGB_TOPIC);
    if (strcmp(topic, mqttTopic.c_str()) == 0) {

    At first run it show

    [MQTT] Subscribing to : /test/rgb

    but don’t receive the topic, until I publish a topic in mqtt server.

    When publish the topic I receive:
    [MQTT] Received topic: /test/rgb

    What is my issue?
    I want restart sonoffsc and it set current state of Topic, without need publish somevalue.

    Thank you again.

    1. Xose Pérez Post author

      Yes, that’s the way to “send messages” to offline devices. Retain the message and the device will receive it upon subscription.

  43. revdaz


    I really like your work, but I can’t flash the ATMega328P with Arduino and do not know what I’m doing wrong. I flashed a lot of sonoff devices and also the ESP part of the Sonoff SC, but don’t know how to flash the ATMega328P.
    I have compiled everything without errors, but when I want to upload the code I get everytime this message:
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x1c
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x1c
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x8e
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x1c
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x1c
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe0
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xfc
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x70
    Beim Hochladen des Sketches ist ein Fehler aufgetreten

    Have I press a button to get in flash mode? I have choosen Board: Arduino Nano and processor: ATMega328P. The green LEd is blinking on the Sonoff. In the serial monitor I see AT+STATUS?
    I have also disconnected the jumpers.
    I really tried everything and getting crazy….

    Thank you very much for help

    1. Xose Pérez Post author

      I use “Arduino Uno” as board type. Also, you can try flashing it via the serial header using an USB2UART programmer. Check my other post about the Sonoff SC.

      1. Xose Pérez Post author

        I can’t remember why I used the ISP header when I first flashed the ATMEGA. But when I needed that header to add more sensors I first flashed an Arduino bootloader to use the FTDI header…

      2. George

        I have the same problem as you, and I also get “AT+STATUS?” sent from the atmega328p.
        When I set RESET to low it does not seam to reset it either.

        How did you flash the boot loader, it was really long time since i did it on my old Arduino.
        And I not remember if i used my FTDI device ( to get the boot loader flashed and what settings did you use in arduino ide?

  44. Marco Ghiglieri

    Hi Xose! Thanks for your work. I got an SC with the soldered DHT11 – mostly unusefull for humidity… So I’d like to replace with BME280 I already have, but I can’t figure out from the schematics where I can get the I2C signals. Can you share an idea?
    Btw… your dust sensor is working correctly? mine stays always in “good” status…. I’m thinking of replacing it with a CO2 sensor…

    1. Xose Pérez Post author

      The I2C pins in the ATMEGA328p are PC4 and PC5 (A4 and A5 in Arduino slang). These are not brought up in the board so your only option here is to solder a thin wire to the IC legs (good luck). Also: double check the sensor input voltage, most BME280 are not tolerant to 5V.
      Option 2: connect it to the ESP8266, you can use pretty mush any GPIO available here but again there is only one GPIO available (GPIO2, labelled SDA), the othr one could be GPIO13 which drives the green LED.
      The dust sensor probably works OK but it’s closed in a boc with very few air flow. The Sonoff SC enclosure was meant for a bluetooth speaker, not an env sensor…

  45. George

    Hi Xose,

    Great article!

    I have some trouble flashing my Arduino atmega328.

    First i was trying to program through the serial adapter, failed same error as “revdaz”.

    Now I am trying to flash my Sonoff sc v2 with an arduino nano clone that i have programmed as an ArduinoISP.

    i’m keep getting this from Arduino IDE, when i try to upload “sonoffsc”:

    avrdude: Expected signature for ATmega328P is 1E 95 0F
    Double check chip, or use -F to override this check.
    Wrong microcontroller found. Did you select the right board from the Tools > Board menu?

    Anyone who know what i have done incorrectly, or is it just a warning that i can disregard and use the -F override?

    Have disconnected jumpers aswell.

    Did also some checks with
    It looks like its an bootloader on the board from the beginning and that it should support serial programming (see below).

    Atmega fuse calculator.
    Written by Nick Gammon.
    Version 1.11
    Compiled on Oct 22 2017 at 02:03:07 with Arduino IDE 10801.
    Attempting to enter programming mode …
    Entered programming mode OK.
    Signature = 0x1E 0x95 0x0F
    Processor = ATmega328P
    Flash memory size = 32768
    LFuse = 0xFF
    HFuse = 0xDE
    EFuse = 0xFD
    Lock byte = 0xCF
    Clock calibration = 0x8E
    External Reset Disable……………… [ ]
    Debug Wire Enable………………….. [ ]
    Enable Serial (ICSP) Programming…….. [X]
    Watchdog Timer Always On……………. [ ]
    Preserve EEPROM through chip erase…… [ ]
    Boot into bootloader……………….. [X]
    Divide clock by 8………………….. [ ]
    Clock output………………………. [ ]
    Bootloader size: 512 bytes.
    Start-up time: SUT0: [ ] SUT1: [ ] (see datasheet)
    Clock source: low-power crystal.
    Brownout detection at: 2.7V.

    Atmega chip detector.
    Written by Nick Gammon.
    Version 1.20
    Compiled on Oct 22 2017 at 01:45:17 with Arduino IDE 10801.
    Attempting to enter ICSP programming mode …
    Entered programming mode OK.
    Signature = 0x1E 0x95 0x0F
    Processor = ATmega328P
    Flash memory size = 32768 bytes.
    LFuse = 0xFF
    HFuse = 0xDE
    EFuse = 0xFD
    Lock byte = 0xCF
    Clock calibration = 0x8E
    Bootloader in use: Yes
    EEPROM preserved through erase: No
    Watchdog timer always on: No
    Bootloader is 512 bytes starting at 7E00


    7E00: 0x11 0x24 0x84 0xB7 0x14 0xBE 0x81 0xFF 0xF0 0xD0 0x85 0xE0 0x80 0x93 0x81 0x00
    7E10: 0x82 0xE0 0x80 0x93 0xC0 0x00 0x88 0xE1 0x80 0x93 0xC1 0x00 0x86 0xE0 0x80 0x93
    7E20: 0xC2 0x00 0x80 0xE1 0x80 0x93 0xC4 0x00 0x8E 0xE0 0xC9 0xD0 0x25 0x9A 0x86 0xE0
    7E30: 0x20 0xE3 0x3C 0xEF 0x91 0xE0 0x30 0x93 0x85 0x00 0x20 0x93 0x84 0x00 0x96 0xBB
    7E40: 0xB0 0x9B 0xFE 0xCF 0x1D 0x9A 0xA8 0x95 0x81 0x50 0xA9 0xF7 0xCC 0x24 0xDD 0x24
    7E50: 0x88 0x24 0x83 0x94 0xB5 0xE0 0xAB 0x2E 0xA1 0xE1 0x9A 0x2E 0xF3 0xE0 0xBF 0x2E
    7E60: 0xA2 0xD0 0x81 0x34 0x61 0xF4 0x9F 0xD0 0x08 0x2F 0xAF 0xD0 0x02 0x38 0x11 0xF0
    7E70: 0x01 0x38 0x11 0xF4 0x84 0xE0 0x01 0xC0 0x83 0xE0 0x8D 0xD0 0x89 0xC0 0x82 0x34
    7E80: 0x11 0xF4 0x84 0xE1 0x03 0xC0 0x85 0x34 0x19 0xF4 0x85 0xE0 0xA6 0xD0 0x80 0xC0
    7E90: 0x85 0x35 0x79 0xF4 0x88 0xD0 0xE8 0x2E 0xFF 0x24 0x85 0xD0 0x08 0x2F 0x10 0xE0
    7EA0: 0x10 0x2F 0x00 0x27 0x0E 0x29 0x1F 0x29 0x00 0x0F 0x11 0x1F 0x8E 0xD0 0x68 0x01
    7EB0: 0x6F 0xC0 0x86 0x35 0x21 0xF4 0x84 0xE0 0x90 0xD0 0x80 0xE0 0xDE 0xCF 0x84 0x36
    7EC0: 0x09 0xF0 0x40 0xC0 0x70 0xD0 0x6F 0xD0 0x08 0x2F 0x6D 0xD0 0x80 0xE0 0xC8 0x16
    7ED0: 0x80 0xE7 0xD8 0x06 0x18 0xF4 0xF6 0x01 0xB7 0xBE 0xE8 0x95 0xC0 0xE0 0xD1 0xE0
    7EE0: 0x62 0xD0 0x89 0x93 0x0C 0x17 0xE1 0xF7 0xF0 0xE0 0xCF 0x16 0xF0 0xE7 0xDF 0x06
    7EF0: 0x18 0xF0 0xF6 0x01 0xB7 0xBE 0xE8 0x95 0x68 0xD0 0x07 0xB6 0x00 0xFC 0xFD 0xCF
    7F00: 0xA6 0x01 0xA0 0xE0 0xB1 0xE0 0x2C 0x91 0x30 0xE0 0x11 0x96 0x8C 0x91 0x11 0x97
    7F10: 0x90 0xE0 0x98 0x2F 0x88 0x27 0x82 0x2B 0x93 0x2B 0x12 0x96 0xFA 0x01 0x0C 0x01
    7F20: 0x87 0xBE 0xE8 0x95 0x11 0x24 0x4E 0x5F 0x5F 0x4F 0xF1 0xE0 0xA0 0x38 0xBF 0x07
    7F30: 0x51 0xF7 0xF6 0x01 0xA7 0xBE 0xE8 0x95 0x07 0xB6 0x00 0xFC 0xFD 0xCF 0x97 0xBE
    7F40: 0xE8 0x95 0x26 0xC0 0x84 0x37 0xB1 0xF4 0x2E 0xD0 0x2D 0xD0 0xF8 0x2E 0x2B 0xD0
    7F50: 0x3C 0xD0 0xF6 0x01 0xEF 0x2C 0x8F 0x01 0x0F 0x5F 0x1F 0x4F 0x84 0x91 0x1B 0xD0
    7F60: 0xEA 0x94 0xF8 0x01 0xC1 0xF7 0x08 0x94 0xC1 0x1C 0xD1 0x1C 0xFA 0x94 0xCF 0x0C
    7F70: 0xD1 0x1C 0x0E 0xC0 0x85 0x37 0x39 0xF4 0x28 0xD0 0x8E 0xE1 0x0C 0xD0 0x85 0xE9
    7F80: 0x0A 0xD0 0x8F 0xE0 0x7A 0xCF 0x81 0x35 0x11 0xF4 0x88 0xE0 0x18 0xD0 0x1D 0xD0
    7F90: 0x80 0xE1 0x01 0xD0 0x65 0xCF 0x98 0x2F 0x80 0x91 0xC0 0x00 0x85 0xFF 0xFC 0xCF
    7FA0: 0x90 0x93 0xC6 0x00 0x08 0x95 0x80 0x91 0xC0 0x00 0x87 0xFF 0xFC 0xCF 0x80 0x91
    7FB0: 0xC0 0x00 0x84 0xFD 0x01 0xC0 0xA8 0x95 0x80 0x91 0xC6 0x00 0x08 0x95 0xE0 0xE6
    7FC0: 0xF0 0xE0 0x98 0xE1 0x90 0x83 0x80 0x83 0x08 0x95 0xED 0xDF 0x80 0x32 0x19 0xF0
    7FD0: 0x88 0xE0 0xF5 0xDF 0xFF 0xCF 0x84 0xE1 0xDE 0xCF 0x1F 0x93 0x18 0x2F 0xE3 0xDF
    7FE0: 0x11 0x50 0xE9 0xF7 0xF2 0xDF 0x1F 0x91 0x08 0x95 0x80 0xE0 0xE8 0xDF 0xEE 0x27
    7FF0: 0xFF 0x27 0x09 0x94 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x04 0x04

    MD5 sum of bootloader = 0xFB 0xF4 0x9B 0x7B 0x59 0x73 0x7F 0x65 0xE8 0xD0 0xF8 0xA5 0x08 0x12 0xE7 0x9F
    Bootloader name: optiboot_atmega328

    First 256 bytes of program memory:

    00: 0x0C 0x94 0x62 0x00 0x0C 0x94 0x94 0x04 0x0C 0x94 0x6D 0x04 0x0C 0x94 0x8A 0x00
    10: 0x0C 0x94 0x8A 0x00 0x0C 0x94 0x8A 0x00 0x0C 0x94 0x8A 0x00 0x0C 0x94 0x8A 0x00
    20: 0x0C 0x94 0x8A 0x00 0x0C 0x94 0xE2 0x04 0x0C 0x94 0x8A 0x00 0x0C 0x94 0x8A 0x00
    30: 0x0C 0x94 0x8A 0x00 0x0C 0x94 0xBB 0x04 0x0C 0x94 0x8A 0x00 0x0C 0x94 0x8A 0x00
    40: 0x0C 0x94 0x23 0x04 0x0C 0x94 0x8A 0x00 0x0C 0x94 0xC8 0x03 0x0C 0x94 0xA2 0x03
    50: 0x0C 0x94 0x8A 0x00 0x0C 0x94 0x8A 0x00 0x0C 0x94 0x8A 0x00 0x0C 0x94 0x8A 0x00
    60: 0x0C 0x94 0x8A 0x00 0x0C 0x94 0x8A 0x00 0x00 0x00 0x00 0x00 0x24 0x00 0x27 0x00
    70: 0x2A 0x00 0x00 0x00 0x00 0x00 0x23 0x00 0x26 0x00 0x29 0x00 0x00 0x00 0x00 0x00
    80: 0x25 0x00 0x28 0x00 0x2B 0x00 0x04 0x04 0x04 0x04 0x04 0x04 0x04 0x04 0x02 0x02
    90: 0x02 0x02 0x02 0x02 0x03 0x03 0x03 0x03 0x03 0x03 0x01 0x02 0x04 0x08 0x10 0x20
    A0: 0x40 0x80 0x01 0x02 0x04 0x08 0x10 0x20 0x01 0x02 0x04 0x08 0x10 0x20 0x00 0x00
    B0: 0x00 0x08 0x00 0x02 0x01 0x00 0x00 0x03 0x04 0x07 0x00 0x00 0x00 0x00 0x00 0x00
    C0: 0x00 0x00 0xDE 0x0C 0x11 0x24 0x1F 0xBE 0xCF 0xEF 0xD8 0xE0 0xDE 0xBF 0xCD 0xBF
    D0: 0x12 0xE0 0xA0 0xE0 0xB1 0xE0 0xE6 0xEB 0xF0 0xE2 0x02 0xC0 0x05 0x90 0x0D 0x92
    E0: 0xA8 0x30 0xB1 0x07 0xD9 0xF7 0x24 0xE0 0xA8 0xE0 0xB2 0xE0 0x01 0xC0 0x1D 0x92
    F0: 0xAC 0x30 0xB2 0x07 0xE1 0xF7 0x10 0xE0 0xC2 0xE6 0xD0 0xE0 0x04 0xC0 0x21 0x97

    Programming mode off.

  46. George

    I’m getting wrong device signature: like this: 0xFF000 or 0x00FF00 or 0x0000FF so do this indicate that some connection is bad. i have check like 5 times and reheated the connection to be completely sure and even measured with an ohm meter to check that it got connection and every wire gives me 1 ohm.

    1. Xose Pérez Post author

      You are right. It looks like a connection problem. Have you double check all the traces/wires? How are you powering the Sonoff SC? Double check your power supply and that the jumpers are removed.

      1. George

        I have tried powered it through USB on my computer to the Arduino ISP to ISP interface on the Sonoff sc board. the led lights up on the Sonoff SC board and start blinking.

        I have also connected different USB ports from my computer, one USB connected to Arduino ISP and one USB port for the Sonoff SC USB connector, thought it should resolve it if it did not provide enough power through a single port.

        like i said it the measurements i have taken with ohmmeter is from the Arduino ISP pin to the ISP interface on the Sonoff SC, and all 6 pins give me 1 Ohm.

        I have now ordered a new programmer to see if i have better luck with it (

        Any other suggestions i can try while waiting for that programmer, i could try to solder the cables instead of using the DuPont’s connectors, but it feels like a long shot 🙂

        1. Xose Pérez Post author

          Can’t really tell you. Probably you have already checked this but some programmers do not provide power to the board… Maybe you could power the Sonoff SC through the microUSB connector and remove the power cable in the ISP.

          1. George


            I have now successfully got everything up and running, it was as you expected a bad wiring.
            One lead was broken under the insulation, did not get a bad measurements with the ohm meter but when i did a rework on all cables i found it.

            So i did not use the ISP programmer ports only the serial ports to program both ATmega and ESP8266.

            Thanks for the help mate!

            I can confirm you would NOT need to flash a boot loaded on atmega 328 on the Sonoff SC V2.0 at least.

            So that can be put in this article.

            And by reading through all comments i think it should state earlier in the article that people should use “Platform IO” and not standard “Arduino IDE” to compile and upload things to get least problems.

            and Thank you again for a good article!

            // George

  47. Greg

    Hi Xose, thanks so much for the article and the firmware – got both up and running a few months ago (and learned a lot along the way, I’m new to this world, more of a sysadmin :P)

    I decided to take a shot at replacing the DHT11 with a DHT22. As others have said the latest model has it soldered directly to the board – however with a little effort I crack the plastic casing on the DHT11, and could then snip the legs.

    I’ve now soldered the DHT22 to the remains of the legs (photo here – but the SC is reporting a temperature of 0. I’ve checked the base of the pins with my multimeter and I’m getting ~5V across Vcc / GND. Have I broken it, or do I need to alter the sketches for a DHT22? Would one of the serial interfaces tell me more about what might be broken?

    Thanks again!

    1. Xose Pérez Post author

      Hi Greg!
      Yes, in the sonoffsc.ino file in the atmega328 code there is a DHT_TYPE setting you have to set it to DHT22.

  48. Greg Sutcliffe

    Thanks Xose – of course, now that I go back and re-read the article, I see it’s obvious anyway. Sorry for the daft question – got a nice Temp readout now 🙂

  49. Savas

    Hi Xose, when I try to flash the ATMega328P, I am getting the following error message;


    line240 class “Ticker” has no member “setInterval”
    line241 class “Ticker” has no member “setCallback”

  50. pablo bolomey

    Hi when opening the project on PIO i’m getting the following error

    Cloning into ‘C:\Users\pablo.bolomey\Documents\sonoffsc-1.1.1\esp8266.piolibdeps_tmp_installing-qjnc0h-package’… warning: Could not find remote branch 1.1.4 to clone. fatal: Remote branch 1.1.4 not found in upstream origin Error: Traceback (most recent call last): File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\”, line 120, in main cli(None, None, None) File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\click\”, line 700, in call return self.main(args, kwargs) File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\click\”, line 680, in main rv = self.invoke(ctx) File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\click\”, line 1027, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\click\”, line 873, in invoke return ctx.invoke(self.callback, ctx.params) File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\click\”, line 508, in invoke return callback(args, kwargs) File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\click\”, line 16, in new_func return f(get_current_context(), *args, kwargs) File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\platformio\commands\”, line 102, in cli pg = ProjectGenerator(project_dir, ide, env_name) File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\platformio\ide\”, line 35, in init self._gather_tplvars() File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\platformio\ide\”, line 151, in _gather_tplvars self._tplvars.update(self.get_project_build_data()) File “c:\users\pablo.bolomey.platformio\penv\lib\site-packages\platformio\ide\”, line 75, in get_project_build_data raise result.exception WindowsError: [Error 5] Access is denied: ‘C:\Users\pablo.bolomey\Documents\sonoffsc-1.1.1\esp8266\.piolibdeps\_tmp_installing-qjnc0h-package’

    Any ideas, have i setup Atom and PIO wrong


  51. pablo bolomey

    Hi Xose,

    I have manage to sort out all decencies issues I had for the project, but now I’m getting the following errors warnings.

    Are you able to share some light on what I’m doing wrongs



    Compiling .pioenvs\sonoffsc\lib9b4\Ethernet\EthernetUdp.cpp.o
    Archiving .pioenvs\sonoffsc\lib339\libSPI.a
    C:/Users/pablo.bolomey/Desktop/sonoffsc-1.1.1/esp8266/sonoffsc/comms.ino: In function ‘bool send_P_repeat(const char*, long int, unsigned char)’:
    C:/Users/pablo.bolomey/Desktop/sonoffsc-1.1.1/esp8266/sonoffsc/comms.ino:146:1: warning: no return statement in function returning non-void [-Wreturn-type]
    C:/Users/pablo.bolomey/Desktop/sonoffsc-1.1.1/esp8266/sonoffsc/debug.ino: In function ‘void debugSend(const char*, …)’:
    C:/Users/pablo.bolomey/Desktop/sonoffsc-1.1.1/esp8266/sonoffsc/debug.ino:25:9: warning: unused variable ‘len’ [-Wunused-variable]
    int len = ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, format, args);
    C:/Users/pablo.bolomey/Desktop/sonoffsc-1.1.1/esp8266/sonoffsc/lights.ino: In function ‘void sendNotification(bool, long unsigned int)’:
    C:/Users/pablo.bolomey/Desktop/sonoffsc-1.1.1/esp8266/sonoffsc/lights.ino:175:33: error: ‘class Ticker’ has no member named ‘once’
    if (time > 0) _lights_defer.once(time, sendNotification, !state);
    C:/Users/pablo.bolomey/Desktop/sonoffsc-1.1.1/esp8266/sonoffsc/mqtt.ino: In function ‘void mqttSend(const char*, const char*, bool)’:
    C:/Users/pablo.bolomey/Desktop/sonoffsc-1.1.1/esp8266/sonoffsc/mqtt.ino:145:28: error: ‘class Ticker’ has no member named ‘once_ms’
    _mqtt_flush_ticker.once_ms(MQTT_USE_JSON_DELAY, _mqttFlush);
    C:/Users/pablo.bolomey/Desktop/sonoffsc-1.1.1/esp8266/sonoffsc/web.ino: In function ‘void _wsParse(uint32_t, uint8_t*, size_t)’:
    C:/Users/pablo.bolomey/Desktop/sonoffsc-1.1.1/esp8266/sonoffsc/web.ino:120:24: error: ‘class Ticker’ has no member named ‘once_ms’
    _web_defer.once_ms(100, wifiDisconnect);

    1. Xose Pérez Post author

      What code/version are you using? I cannot find the “send_P_repeat” method and the Ticker class is a core class in the Arduino ESP8266 Core…

  52. umerfraz

    Hi, i am also getting the error on “ticker.once” and “ticker.once_ms”. anyone got it fixed. i flashed my first sonoff sc after a lot of struggle about an year ago. dont remember HOW. now trying to flash the two new ones, its just failing me with this message.

    C:/Umer/Personal/Tinkering/Dev/sonoffsc-master/esp8266/sonoffsc/web.ino: In function ‘void _onRPC(AsyncWebServerRequest*)’:
    C:/Umer/Personal/Tinkering/Dev/sonoffsc-master/esp8266/sonoffsc/web.ino:612:24: error: ‘class Ticker’ has no member named ‘once_ms’
    _web_defer.once_ms(100, []() {
    C:/Umer/Personal/Tinkering/Dev/sonoffsc-master/esp8266/sonoffsc/web.ino: In function ‘void _onUpgrade(AsyncWebServerRequest*)’:
    C:/Umer/Personal/Tinkering/Dev/sonoffsc-master/esp8266/sonoffsc/web.ino:826:20: error: ‘class Ticker’ has no member named ‘once_ms’
    _web_defer.once_ms(100, []() {

    any help will be really great thanks


Leave a Reply (all comments are moderated, be patient)

This site uses Akismet to reduce spam. Learn how your comment data is processed.