WEBSERVER propblems

I am using this web server template
Random Nerds

and the Cactus.IO library to allow the use of 2 BME280's on the same I2C line
Cactus Link

the issue is that I have only been successful 1 in 20 times (more like 1:50) to get this to upload to a Wemos D1 and work.
When I tried to change a few words in the display to get things aligned, I get errors in the upload.

when I comment out loop() and just run the sensors, it works great, every time.

Linux Ubuntu IDE 1.8.5
Wemos D1 mini
2 BME280 sensors.

//  http://randomnerdtutorials.com/esp8266-ds18b20-temperature-sensor-web-server-with-arduino-ide/
//  Cactus library :  http://static.cactus.io/downloads/library/bme280/cactus_io_BME280_I2C.zip

#include <Wire.h>
#include "cactus_io_BME280_I2C.h"
#include <ESP8266WiFi.h>

// Create two BME280 instances
BME280_I2C bme1(0x77);  // I2C using default 0x77 
BME280_I2C bme2(0x76);  // I2C using address 0x76

const char* ssid   = "*****";   
const char* password = "***********"; 

char temp1String[7];
char rh1String[7];
char pres1String[8];

char temp2String[7];
char rh2String[7];
char pres2String[8];

float temp1, rh1, pres1 , temp2, rh2, pres2;

WiFiServer server(80); // Web Server on port 80

void setup() {// ++++++++++++++++++++++++++++++++  SETUP +++++++++++++++++++++

  Serial.begin(9600);
  delay(10);

Serial.println("Multi Bosch BME280 Barometric Pressure - Humidity - Temp Sensor | cactus.io"); 

  if (!bme1.begin()) {
    Serial.println("Could not find a First BME280 sensor, check wiring!");
    while (1);
  }
  
  if (!bme2.begin()) {
    Serial.println("Could not find a Second BME280 sensor, check wiring!");
    while (1);
  }

  // Connecting to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
  

  Serial.println(WiFi.localIP());  // Print ESP IP address

// ============================= READ BME ===================
  
  delay(1000);

   bme1.readSensor();
     temp1 = (bme1.getTemperature_F());
     rh1 = (bme1.getHumidity());
     pres1 = (bme1.getPressure_MB());
     pres1 = pres1 / 33.864 ;
     delay(1000);

   bme2.readSensor();
     temp2 = (bme2.getTemperature_F());
     rh2 = (bme2.getHumidity());
     pres2 = (bme2.getPressure_MB());
     pres2 = pres2 / 33.864 ;   //  to get inched of mercury

//  print one line of data from sensors to verfiy they are on-line

    delay(1000);

    dtostrf(temp1, 2, 2, temp1String);
    dtostrf(  rh1, 2, 2, rh1String);
    dtostrf(pres1, 2, 2, pres1String);
    dtostrf(temp2, 2, 2, temp2String);
    dtostrf(  rh2, 2, 2, rh2String);
    dtostrf(pres2, 2, 2, pres2String);

Serial.println("from set-up");
Serial.print("BME1 - ");
Serial.print(temp2String); Serial.print("*F2\t");
Serial.print(rh2String);  Serial.print("%rh2\t");
Serial.print(pres2String); Serial.println(" IN HG2\t");

Serial.print("BME1 - ");
Serial.print(temp1String); Serial.print("*F\t");
Serial.print(rh1String); Serial.print("%rh\t");
Serial.print(pres1String); Serial.println(" IN HG\t");


  Serial.println(WiFi.localIP());    // Print ESP IP address
Serial.println("--- END SETUP ---");  
} // ====================  END SETUP =============

void getBME() {  //++++++++++++++++++++++ BME +++++++++++++++++++

    bme1.readSensor();
       temp1 = (bme1.getTemperature_F());
       rh1 = (bme1.getHumidity());
       pres1 = (bme1.getPressure_MB());
       pres1 = pres1 / 33.864 ;
    delay(1000);

    bme2.readSensor();
       temp2 = (bme2.getTemperature_F());
       rh2 = (bme2.getHumidity());
       pres2 = (bme2.getPressure_MB());
       pres2 = pres2 / 33.864 ;

    delay(1000);
  

    dtostrf(temp1, 2, 2, temp1String); // digits to string
    dtostrf(  rh1, 2, 2, rh1String);
    dtostrf(pres1, 2, 2, pres1String);


Serial.print("BME1 - ");
Serial.print(temp1String); Serial.print("*F\t");  // print string to verify 
Serial.print(rh1String); Serial.print("%rh\t");
Serial.print(pres1String); Serial.println(" IN HG\t");


    dtostrf(temp2, 2, 2, temp2String);
    dtostrf(  rh2, 2, 2, rh2String);
    dtostrf(pres2, 2, 2, pres2String);

Serial.print("BME1 - ");
Serial.print(temp2String); Serial.print("*F2\t");
Serial.print(rh2String);  Serial.print("%rh2\t");
Serial.print(pres2String); Serial.println(" IN HG2\t");


   
}


void loop() {    // ++++++++++++++++++++++  LOOP +++++++++++++++++

  //getBME();
  
  
  WiFiClient client = server.available();   // Listenning for new clients
  
  if (client) {
    Serial.println("New client");
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (c == '\n' && blank_line) {
             getBME();
             //test to see if client is looking
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");
            client.println();
            // actual web page that displays temperature
            client.println("<!DOCTYPE HTML>");
            client.println("<html>");
            client.println("<head></head><body><h1>Daves Sensors</h1>");
            client.println("<h3>Unit 1 Temp : ");               
            client.println(temp1String);
            client.println("*F</h3><h3>Unit 1 Humidity : "); 
            client.println(rh1String);
            client.println("%RH</h3><h3>Unit 1 Pres : ");     
            client.println(pres1String);
            client.println("in HG</h3><h3>Unit 2 temp : ");     
            client.println(temp2String);
            client.println("*F</h3><h3>Unit 2 Humidity : "); 
            client.println(rh2String);
            client.println("%RH</h3><h3>Unit 2 Pres : ");     
            client.println(pres2String);
            client.println("in HG</h3></body></html>");  
            break;
            
        }
        if (c == '\n') {
          // when starts reading a new line
          blank_line = true;
        }
        else if (c != '\r') {
          // when finds a character on the current line
          blank_line = false;
        }
      }
    }  
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
  }
       

}   //  =============  END OF LOOP ===========

I have been butting my head against this simple problem for over a week.

I am on a Linux box, 1.8.5 IDE

I come home and can upload the sketch if it has one value
see it from my cell phone or browser on the PC.

make a small change and either it does not work or I get an error

Archiving built core (caching) in: /tmp/arduino_cache_539897/core/core_esp8266_esp8266_d1_mini_CpuFrequency_80,FlashSize_4M1M,LwIPVariant_v2mss536,Debug_Disabled,DebugLevel_None____,UploadSpeed_9600_82493cada85e65a871080fec640fc08d.a
Sketch uses 265139 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 34548 bytes (42%) of dynamic memory, leaving 47372 bytes for local variables. Maximum is 81920 bytes.
Uploading 269280 bytes from /tmp/arduino_build_601005/webserver_forum.ino.bin to flash at 0x00000000
................................................................................ [ 30% ]
................................................................................ [ 60% ]
................................................................................ [ 91% ]
......................java.io.IOException: Stream closed
at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
at java.io.BufferedInputStream.read(BufferedInputStream.java:336)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at sun.nio.cs.StreamDecoder.read0(StreamDecoder.java:127)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:112)
at java.io.InputStreamReader.read(InputStreamReader.java:168)
at processing.app.debug.MessageSiphon.run(MessageSiphon.java:81)
at java.lang.Thread.run(Thread.java:748)

Can anyone tell me what I am doing wrong ?

the above error is not something I see every time, but often enough

the serial monitor dumps hash

Ep⸮⸮@ ⸮l⸮@xtH⸮⸮YG⸮⸮tA⸮H$V$G⸮E>⸮hdGRNt⸮i⸮⸮⸮

and just because someone will ask....

//  http://randomnerdtutorials.com/esp8266-ds18b20-temperature-sensor-web-server-with-arduino-ide/
//  Cactus library :  http://static.cactus.io/downloads/library/bme280/cactus_io_BME280_I2C.zip

#include <Wire.h>
#include "cactus_io_BME280_I2C.h"
#include <ESP8266WiFi.h>

// Create two BME280 instances
BME280_I2C bme1(0x77);  // I2C using default 0x77 
BME280_I2C bme2(0x76);  // I2C using address 0x76

const char* ssid   = "************";   
const char* password = "*************"

char temp1String[7];
char rh1String[7];
char pres1String[8];

char temp2String[7];
char rh2String[7];
char pres2String[8];

float temp1, rh1, pres1 , temp2, rh2, pres2;

WiFiServer server(80); // Web Server on port 80

void setup() {// ++++++++++++++++++++++++++++++++  SETUP +++++++++++++++++++++

  Serial.begin(9600);
  delay(10);

Serial.println("Multi Bosch BME280 Barometric Pressure - Humidity - Temp Sensor | cactus.io"); 

  if (!bme1.begin()) {
    Serial.println("Could not find a First BME280 sensor, check wiring!");
    while (1);
  }
  
  if (!bme2.begin()) {
    Serial.println("Could not find a Second BME280 sensor, check wiring!");
    while (1);
  }

  // Connecting to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
  

  Serial.println(WiFi.localIP());  // Print ESP IP address

// ============================= READ BME ===================
  
  delay(1000);

   bme1.readSensor();
     temp1 = (bme1.getTemperature_F());
     rh1 = (bme1.getHumidity());
     pres1 = (bme1.getPressure_MB());
     pres1 = pres1 / 33.864 ;
     delay(1000);

   bme2.readSensor();
     temp2 = (bme2.getTemperature_F());
     rh2 = (bme2.getHumidity());
     pres2 = (bme2.getPressure_MB());
     pres2 = pres2 / 33.864 ;   //  to get inched of mercury

//  print one line of data from sensors to verfiy they are on-line

    delay(1000);

    dtostrf(temp1, 2, 2, temp1String);
    dtostrf(  rh1, 2, 2, rh1String);
    dtostrf(pres1, 2, 2, pres1String);
    dtostrf(temp2, 2, 2, temp2String);
    dtostrf(  rh2, 2, 2, rh2String);
    dtostrf(pres2, 2, 2, pres2String);

Serial.println("from set-up");
Serial.print("BME1 - ");
Serial.print(temp2String); Serial.print("*F2\t");
Serial.print(rh2String);  Serial.print("%rh2\t");
Serial.print(pres2String); Serial.println(" IN HG2\t");

Serial.print("BME1 - ");
Serial.print(temp1String); Serial.print("*F\t");
Serial.print(rh1String); Serial.print("%rh\t");
Serial.print(pres1String); Serial.println(" IN HG\t");


  Serial.println(WiFi.localIP());    // Print ESP IP address
Serial.println("--- END SETUP ---");  
} // ====================  END SETUP =============

void getBME() {  //++++++++++++++++++++++ BME +++++++++++++++++++

    bme1.readSensor();
       temp1 = (bme1.getTemperature_F());
       rh1 = (bme1.getHumidity());
       pres1 = (bme1.getPressure_MB());
       pres1 = pres1 / 33.864 ;
    delay(1000);

    bme2.readSensor();
       temp2 = (bme2.getTemperature_F());
       rh2 = (bme2.getHumidity());
       pres2 = (bme2.getPressure_MB());
       pres2 = pres2 / 33.864 ;

    delay(1000);
  

    dtostrf(temp1, 2, 2, temp1String); // digits to string
    dtostrf(  rh1, 2, 2, rh1String);
    dtostrf(pres1, 2, 2, pres1String);


Serial.print("BME1 - ");
Serial.print(temp1String); Serial.print("*F\t");  // print string to verify 
Serial.print(rh1String); Serial.print("%rh\t");
Serial.print(pres1String); Serial.println(" IN HG\t");


    dtostrf(temp2, 2, 2, temp2String);
    dtostrf(  rh2, 2, 2, rh2String);
    dtostrf(pres2, 2, 2, pres2String);

Serial.print("BME1 - ");
Serial.print(temp2String); Serial.print("*F2\t");
Serial.print(rh2String);  Serial.print("%rh2\t");
Serial.print(pres2String); Serial.println(" IN HG2\t");


   
}


void loop() {    // ++++++++++++++++++++++  LOOP +++++++++++++++++

  //getBME();
  
  
  WiFiClient client = server.available();   // Listenning for new clients
  
  if (client) {
    Serial.println("New client");
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        if (c == '\n' && blank_line) {
             getBME();
             //test to see if client is looking
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");
            client.println();
            // actual web page that displays temperature
            client.println("<!DOCTYPE HTML>");
            client.println("<html>");
            client.println("<head></head><body><h1>Daves Sensors</h1><h3>Unit 1 Temp : ");               
            client.println(temp1);
            client.println("</h3><h3>Unit 2 Temp : "); 
           client.println(temp2);
          //  client.println("RH</h3><h3>Unit 1 Pres : ");     
          //  client.println(pres1);
         /*   //client.println(pres1String);
            client.println("in HG</h3><h3>Unit 2 temp : ");     
                      client.println(temp1String);
            //client.println(temp2String);
            client.println("*F</h3><h3>Unit 2 Humidity : "); 
                      client.println(temp1String);
            //client.println(rh2String);
            client.println("%RH</h3><h3>Unit 2 Pres : ");     
                      client.println(temp1String);
            //client.println(pres2String);*/
            client.println("</h3></body></html>");  
            break;
            
        }
        if (c == '\n') {
          // when starts reading a new line
          blank_line = true;
        }
        else if (c != '\r') {
          // when finds a character on the current line
          blank_line = false;
        }
      }
    }  
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
  }
      

}   //  =============  END OF LOOP ===========

Merged as requested.

I'll take a wild guess that this could be caused by your antivirus software. Try TEMPORARILY disabling your antivirus for a single upload to see if the problem goes away, then turn the antivirus back on. If the problem doesn't occur with the antivirus off you will need to adjust the settings of your antivirus to whitelist the appropriate file, folder, or process so it doesn't interfere with compilation.

Thanks

I think it is something more basic. settings in the IDE.

had moved from platform.io on windows to the Arduino IDE and
all the simple stuff was working.

as programs grow, you suspect you missed something....

I changed the upload speed from 9600 to 115200
the ESP8266 has such a higher clock rate, it can handle that, and me ASSuming... that when I set the board in the board manager... the board manager changed the settings.

as for platform.io it is a really good start, but it is an on-line software package and they change things now and again that require one to erase files manually. file naming and maniuplation is horrible.... but the program has great promise. it does some things that the Arduino IDE does not.

THANK YOU for taking your time to reply.

So you reduced the upload speed and the problem went away?

I had some intermittent upload problems with my D1 Minis but never could see a direct impact on the problem from changing the upload speed.

My gripe about platformio (note it's not actually platform.io, I get that wrong all the time too) is that it allows people to write "Arduino" code that isn't actually compatible with the Arduino IDE. That's fine, they're allowed to do what they like, but the problem is that the people who write this code go and advertise it as "Arduino". I'm seeing more and more of this appearing lately and it means a lot of sorting through invalid search results, which never used to happen. If you try to get it fixed, which means only some minor changes, you get this snobby attitude "I don't use the crappy Arduino IDE, I use Platformio". Fine, but don't go publishing that code as "Arduino" unless it works with the Arduino IDE.

Other than that I think it's good to have alternative options. I haven't used platformio but it seems to be trying to fit into this weird niche of being more full featured than the Arduino IDE but easier to use than the traditional "professional" IDEs. There are some fairly basic actions that you can do via the Arduino IDE's GUI but in platformio you need to dive into editing some cryptic configuration files so I think it misses the beginner market that the Arduino IDE is targeted to. I don't get the feeling that the typical "professional" user has been clamoring for a more "Arduino" experience so I don't see them switching to Platformio either. Then whenever I see a feature that I am interested in it turns out not to be available in the free version. I'm all for people making money from their hard work but I can't justify spending $10 or more per month on my hobbyist budget.

I had problems at 9600, works perfect at 115200, so the slow upload speed was the problem.
have been uploading changes all morning. learning HTML like   along the way.

platformio seems to want to be a common platform for all software for all micros. PIC, Atmel, whatever.
not just a different interface for the Arduino bootloader. I believe the idea is that you can write your code for your Arduino in it, then your HTML for your web page, create your users manual in the text processor part, then write your LUA code, and tie it all together by writing your Python in it as well. this would be a common interface for all your programming needs. the concept is that humans use a keyboard and write in text. the interface from the human input to the machine code is something people do not see.

For IDEs, I use Netbeans and works pretty well. Still, some (easy solvable) problems with esp's SPIFFS.