Sonoff TH10 'bricks' after flashing with basic Blynk script

hi, title tells the tale. I’ve tried several methods of flashing a esp8266 blynk script onto my Sonoff TH10 (thats the one with the T and humid. sensor), but each time the sonoff becomes unresponsive. When I flash it with the original software it comes alive again. I don’t know what more to post, so let me know what else I can provide to get this solved.

used:
IDE Arduino on windows 10
Flashed with DOUT setting and SPIFFS 1Mb (64k).

thank you.

There are more parameters to check. And the flash working mode is dependant of the flash chip used. You may want to check it.

Can you post the code you’re using?

Pete.

well it turns out that its less bricked than I thought…but not by much. I thought to check the serial montor and lo and behold:

Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
etc etc etc etc

But essentially its still not working. No LED, no readout no switch not connection and even the button on the sonoff does not work!

Code:
/**************************************************************
Blynk Bridge - Communication between ESP8266
Sketch code for the master module (module which will command others)
www.geekstips.com
**************************************************************/
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "CENSORED";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "CENSORED";
char pass[] = "CENSORED";

#define DHTPIN 2 // What digital pin we're connected to

//#define DHTTYPE DHT11   // DHT 11
  #define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;


void sendSensor(){
  // get readings from the DHT22 sensor
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Send command to the second ESP
  // WHEN Temperature IS OVER 28 C
  // in order to open the 220V Relay
  // Also update the VIRTUAL port 5 
  // on the second ESP
  if(t > 28){
    Serial.println("temperature is higher than 28");
  }else{
    Serial.println("temperature is lower than 28");
  }

  // Send temperature and humidity to Blynk App
  // on VIRTUAL ports 5 and 6 in order to 
  // display on Gauge Widget
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}

void setup(){
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  dht.begin();

  timer.setInterval(1000L, sendSensor);
}

void loop(){
  Blynk.run();
  timer.run();

  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
  
}lockquote

Are you sure, you are using the correct pins?
TEM1 = GPIO14,
TEM2 = GPIO4
LED (grn) = GPIO13
LED (red) = GPIO12

good point! I just grabbed that part from somewhere else but indeed yesterday ive seen a youtube tut that explained that its 4 and 14. This however does NOT explain why the leds are not flahsing!! Ill update as soon as ive updated the flash

Well, that is true, but as you see the device is working “correctly”, as it throws proper serial comm.
Perhaps you should declare the pin as output? (as initially they are inputs)
pinMode (pin, OUTPUT)

Indeed that worked! Its finally flashing. However I don’t get a readout. It remains nan. Ive first added:
pinMode (DHTPIN, INPUT);
and then tried:
#define DHTPIN 2
#define DHTPIN 4
and
#define DHTPIN 14
all give nothing.

This should be done by library.
You may try:

  • Increase readout interval to 2000ms
  • check power supply to the sensor, (Vcc, GND)
  • how long wires are? (avoid too long - when working with 3,3V try to avoid >1m)
  • try other sensor
  • ???
    Or even check sensor with plain Arduino (Atmega)

You’re trying to read your DHT sensor far too often. Every 5 seconds is about as often as you’ll be able to read it without problems. For most practical situations, there’s no logical reason to read the temperature this often anyway.

Also, the golden rule of Blynk is not to use delays and that your void loop shouldn’t have anything other than Blynk.run; and timer.run;
Everything else should be in a function that’s called with a timer.

I assume that this:

at the end of your code is something you copied by mistake?

Pete.

@PeteKnight, I’ve been reading those at 1s interval once, but that might be their limit, as anything lower and it fails too often. The other question is: Why one need to measure air temperature so often? :wink: As an environment sensor even 1minute isn’t too small frequency.

ok…

  1. im aware of timer over delay, its just test code
  2. 1 second: again just test code, I changed it to 5 seconds: no difference.
  3. lockquote: yes copied by mistake
  4. wires are short
  5. I don’t have another sensor at hand (yet). Note that the sensor communicates over I2C and is a Si7021
    Im currently trying to comprehend this:
    https://www.itead.cc/wiki/images/3/39/Sonoff_TH10A(16A)_schmatic.pdf
    to figure out on which pin the dht is communicating.

OK, noted. Then You have an answer, why it is not working. The DHT22 is a “WIRE” sensor, and I2C has nothing common with it. You need to find another library and use TWO PINS, as required by I2C

it appears so. This is all new to me so not everything is clear. Ive read about i2c somewhere else too and recall it requires an address which dht.h clearly is not asking for. It at least is good to know that everything ‘basically’ works, but I require more advanced libraries to fully use the sonoff.

So now its time to get sonoff-tasmota compiled…sigh…( been trying that for 3 days now, but I’ve finally found a good tutorial so who knows)
What Ive got that down im gonna try to insert blynk back in. Quite the project for a n00b, slightly bit more than I can chew :smiley:

Anyway thank you for the swift replies, that helped quite a bit!

Personally, I don’t like that route, mostly for the reasons that you’ve already discovered.

If you want to work on trying to get the Si7021 working with the Sonoff then here’s some info i found when doing a bit of research…

Although the Si7021 is an I2C device, the TH10 doesn’t have enough connectors in its external sensor socket to support I2C. Sonoff have therefore added an MCU to the Si7021 package to convert it into a one wire package which emulates the AM2301 sensor.

If you change this bit of your code:

to enable the DHT21/AM2301 instead of DHT22 it should work.

Pete.

ok ?! Ill try that. However, that still leaves the most important part thats also not working: the relay. Any clue how I can get that to work?

a and any clue which pin number? 2, 4 or 14?

12

Smart guys at Sonoff! :wink: Although I know nothing about it, i believe @PeteKnight has right here.

Are you testing this by powering it with your FTDI programmer from a USB port?
If so, then it’s probably not able to provide enough current to pull the relay in which may make you think that it’s not working.
Some people (who will remain anonymous to protect the guilty) think that the best solution is to power the Sonoff with mains power whilst keeping it connected to your PC with the FTDI programmer. PLEASE DONT DO THIS!!!

Disconnect the 4-pin FTDI connection to the board then connect the Sonoff to the mains and see if the relay works.

A bit of googling should show which GPIOs are used by the TH10.

Pete.

1 Like

Yea, but first of all the relay need to be driven! I don’t see that part in posted code.

no I connect to mains and then press the button: not working. Then again I don’t have any code added to imply the working of it. The code so far is generic esp8266 and im fairly clueless how to implement the relay part .

they’re galvanically separated so there’s little harm. The biggest danger is the open lines of the board itself, so yes anyone not knowing what they’re doing should not be doing that. (granted a bit strange to hear this from a n00b, but the n00b part doesn’t really apply to basic electricity and electronics, its the IC’s that drive me bonkers.)

yeah I thought so, but I ended up trying to read the pdf I’ve linked earlier, I can’t find anything on this. I’ll let you know if I get the sensor to work later, I’ve bot install issues with ide, so reinstalling the lot. (windows default vs windows store install…)