Sonoff module version affecting programming from Arduino IDE?

I’m using Arduino IDE 1.8.12 in Windows 10 / 64. Board Generic ESP8266 Module.

I’ve extended the firmware presented by Rui Santos for the Sonoff.
I added a timer functionality to count down and turn off after an interval.
The complete code (except SSID/PW) is attached in “Sonoff_local_web_server1_fan - Copy.ino”

I have a Sonoff module I bought a couple of years ago. It has 5 pins for serial interfacing, with pin 1 closest to the reset button:

1: Vcc 3.3V
2: RX
3: TX
4: GND
5: GPIO14
Like this one

I purchased some additional units last month. They have four pins for serial interfacing, with pin 1 closest to the reset button:
1: Vcc 3.3V
2: RX
3: TX
4: GND
Like this one:

I connected the new unit to the FTDI USB/Serial programming cable to check it out, and the sketch compiled and ran properly.

Today, I wanted to program the older unit with the latest sketch. I uploaded the same sketch to the original unit. The segment sizes and other details during the upload process are identical.

However, the older Sonoff stops working after a few seconds. The serial monitor shows the normal output:
IP address: 192.168.1.104
MDNS responder started
HTTP server started

There is never any response from a browser.
I can ping at 192.168.1.104, and a few pings respond, then all timeouts.

Apparently the code is failing, but everything appears to be identical other than the board layout.
The original unit used to work fine with this code before I started testing with the newer units.

I have attached the IDE Upload log for both units. There is a slight difference:

Newer unit that works:

Chip is ESP8285
Features: WiFi, Embedded Flash

Older unit that fails:

Chip is ESP8266EX
Features: WiFi

I can confirm that the unit that is now failing was working properly a few weeks ago.

Sonoff_local_web_server1_fan - Copy.ino (5.57 KB)

IDE-upload-log-for-original-sonoff-FAILS.txt (1.53 KB)

IDE-upload-log-for-newerl-sonoff-WORKS.txt (1.59 KB)

Yes, what you should look at is... your post from our point of view, after you've read the forum guide in the sticky post. Then ask yourself if you have given enough information to allow anyone to actually help you.

As requested by @PaulRB, I added additional details and code attachments to the first post.

To determine if the issue is a hardware failure or some aspect of the software, I uploaded the older Sonoff with the sketch version I was using (successfully) when I received the new Sonoff modules and swapped them in for testing.

It turns out the old software still works normally, as it did before. Old sketch attached. So there is some type of incompatibility or difference in capability between the old Sonoff and new Sonoff modules.

Here are the lines from the compile/upload log from the newer sketch on the old module that fails:

IROM   : 282540          - code in flash         (default or ICACHE_FLASH_ATTR) 

IRAM   : 27692   / 32768 - code in IRAM          (ICACHE_RAM_ATTR, ISRs...) 

DATA   : 1276  )         - initialized variables (global, static) in RAM/HEAP 

RODATA : 1584  ) / 81920 - constants             (global, static) in RAM/HEAP 

BSS    : 25440 )         - zeroed variables      (global, static) in RAM/HEAP 

Sketch uses 313092 bytes (32%) of program storage space. Maximum is 958448 bytes.
Global variables use 28300 bytes (34%) of dynamic memory, leaving 53620 bytes for local variables. Maximum is 81920 bytes.

Here’s the lines from the older, smaller code that works:

IROM   : 280300          - code in flash         (default or ICACHE_FLASH_ATTR) 

IRAM   : 27692   / 32768 - code in IRAM          (ICACHE_RAM_ATTR, ISRs...) 

DATA   : 1272  )         - initialized variables (global, static) in RAM/HEAP 

RODATA : 1124  ) / 81920 - constants             (global, static) in RAM/HEAP 

BSS    : 25384 )         - zeroed variables      (global, static) in RAM/HEAP 

Sketch uses 310388 bytes (32%) of program storage space. Maximum is 958448 bytes.
Global variables use 27780 bytes (33%) of dynamic memory, leaving 54140 bytes for local variables. Maximum is 81920 bytes.

In summary a relatively small increase in code and memory use due to new capabilities added to the sketch. My guess is that the small increase in code size has exceeded some limit in the older board, that has changed on the newer board. It seems odd since the code is 32% in both cases, and growing dynamic memory from 33% to 34% seems to cause the failure. Maybe the libraries use a huge amount of stack?

I can use the first Sonoff for smaller code, but I’d like to understand more about what is actually happening if anyone knows. In particular the curious detection of the chip by the IDE:

Older Sonoff:

Chip is ESP8266EX
Features: WiFi

Newer Sonoff:

Chip is ESP8285
Features: WiFi, Embedded Flash

Sonoff_local_web_server Apr9version Copy.ino (2.14 KB)

Compile and Upload log - old software on old Sonoff module.txt (1.48 KB)

Thanks and +1 karma for the extra info… Will try to look at this tomorrow.

The ESP8285 has built in flash memory of 1MB or 2MB (depending on chip version) but the old ESP8266 Sonoff has external flash memory. IIRC some of the early ESP modules only had 512KB flash so maybe your using just enough to push it over the limits.

Riva:
IIRC some of the early ESP modules only had 512KB flash so maybe your using just enough to push it over the limits.

It doesn't look like much more than 250K of flash is needed.

@timg11 I will haven't got around to reading your code (can't do it on my phone) but I would suggest putting in more Serial.print()s to narrow down at what point the problem occurs.

Riva:
The ESP8285 has built in flash memory of 1MB or 2MB (depending on chip version) but the old ESP8266 Sonoff has external flash memory. IIRC some of the early ESP modules only had 512KB flash so maybe your using just enough to push it over the limits.

Both the older module and the newer module report:
Auto-detected Flash size: 1MB

in the upload log.

PaulRB:
I would suggest putting in more Serial.print()s to narrow down at what point the problem occurs.

The last statement in setup(void) is

 Serial.println("HTTP server started");

That appears in the serial monitor window.
So I think it is failing in loop(void).

void loop(void){
  if (timer_run > 0 ) 
  {
     if (millis () - startTime >= timerruntime)   // timer done
     {
       digitalWrite(gpio13Led, HIGH);
       digitalWrite(gpio12Relay, LOW);
       state = 0;
       timer_run = 0;
     }
     else {
     remaining = timerruntime - (millis () - startTime) ;
     }
  }
  server.handleClient();
}

Since timer_run starts out as 0, it the failure is probably in server.handleClient();
I'm not sure how to debug that with Serial.print()

the failure is probably in server.handleClient();
I'm not sure how to debug that with Serial.print()

You can't, but you can put Serial.print()s before & after it, and at the start & end of each function within the main code. I'm guessing there are other functions to take care of various incoming requests from clients? They will be registered with the handler somewhere in the sketch.