Bmp180 code optimization

I have this code I entered

It basically controls 3 relays and one button + bmp180

Everything works dandy… only issue is that in case the bmp180 sda or sda cables disconnect phisically, my nodemcu goes into reset loop.
I’d like to optimize it in a way that the relays keep working in case cable/module fail
Is there another way?
thx

#include <Homotica.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <SimpleTimer.h>
#include <SPI.h> 
#include <OneWire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;

//FRONT DOOR=D4 GATE=D3   GLASS DOOR = D5

#define WDOOR D4
#define GDOOR D5
#define GATE D3
const int buttonPin = D6; // The number of the Pushbutton pin


//BUTTON declarations
SimpleTimer timer;

int buttonState = 0;  // Variable for reading the pushbutton status
long previousMillis = 0;        // will store last time LED was updated
long interval = 5000;           // interval at which to blink (milliseconds)
long currentValue;
float Dtemp;

int buttonstatedoor = 0;

WiFiClient client;


//MODIFY THESE PARAMETERS
const char* ssid = "";                             //your wifi ssid
const char* password = "";                     //your wifi password

WiFiServer serverbmp(80);
IPAddress ip(10,0,0,190);                             //your arduino IP
IPAddress gateway(10,0,0,1);                         //your network gateway
IPAddress subnet(255, 255, 255, 0);                        //your network subnet mask

unsigned int mUdpPort = 5858;
static String code = "qawsedrf";
Homotica homotica;

unsigned long lastMillis = 0;


void setup() {
    Serial.begin(74880);
  WiFi.config(ip, gateway, subnet);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }

  //D4= DOOR D5=GATE

  
  pinMode(buttonPin, INPUT);
  pinMode(WDOOR, OUTPUT);
  pinMode(GATE, OUTPUT);
  pinMode(WDOOR, OUTPUT);

 // digitalWrite(WDOOR, HIGH);


  homotica.addUsedPinOutput(WDOOR);
  homotica.addUsedPinOutput(GATE);
  homotica.addUsedPinOutput(GDOOR);
 
  homotica.attachInputFunction(myCustomInputFunction, 'M');



 //homotica.setActiveLow();  //<-- only if you need it
 homotica.set(mUdpPort, code);

//homotica.turnOn(WDOOR);
//homotica.turnOn(GDOOR);
homotica.turnOn(GATE);  

    timer.setInterval(1200L, emergencybtn);
    timer.setInterval(2000L, gateoff);
    timer.setInterval(1000L, exchangevars);

      if (!bmp.begin()) {
       Serial.println("No BMP180 / BMP085");// Crap! No Bmp180
      while (1) {}
      
  }

}

void loop() {
  homotica.refresh();
  timer.run();

   
}


int16_t myCustomInputFunction(){
  //read sensors or do stuff
  int16_t returnValue = 1234;
  return returnValue;
  
  //if an error has occurred - like the sensor didn't respond - you could
  //refuse to return a valid value; in this case use:
  //return homotica.SENSOR_ERROR;
  //which will generate a negative response to the app.
  
  //NOTE: the method does not accept negative values
}



void emergencybtn()
  {   
   //REDBUTTON EMERGENCY (Opens door by button press in case wifi jammed)
   previousMillis = millis();
 
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);

   //The button is pushed
    while (buttonState == HIGH) 
           

  {

       Serial.println(buttonState);
     
     currentValue = millis() - previousMillis;
    
     if (currentValue > interval)  //If the button has been pressed for >inverval open it
     {          
       // save the last time relays has been turned on
       previousMillis = millis();   
       
       digitalWrite(WDOOR, HIGH);      //opendoor
       delay(4000);     //give time to get in
      digitalWrite(WDOOR, LOW);    //close it
     
     }
  
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  yield();
    }
  
  }

void gateoff()
{
  // This function scans continually gate relay status and resets relay to high
   buttonstatedoor = digitalRead(GATE);
   //The button is pushed
    if (buttonstatedoor == LOW) 
     {
       Serial.println("Close DA GATE");
       delay (500);
       digitalWrite(GATE, HIGH); 
     }
     
   
}

void exchangevars(){

  //Send variables to Central arduino station
  
  float TempIN = (bmp.readTemperature());
  float Pres = ((bmp.readPressure()));
  

   WiFiClient client = serverbmp.available();
  if (client) {
    if (client.connected()) {
      Serial.println("Sending data..");
      String request = client.readStringUntil('\r');    // reads the message from the client
      client.flush();
      client.print(String(TempIN));        // sends variable 1
      client.print(',');
      client.print(String(Pres));        // sends variable 2
      client.print('\r');

    }
    client.stop();                         // disconnects the client 
  }


}

When the controller performs a reset, caused by disturbance, there is not much, probably nothing You can do in the code. I have experienced the same. Those breadboards and toy cables a very unreliable. The best You can do is using soldered wiring.

Couldn't agree more. I switched to terminal strips long ago.
arduino standard cables should be used only for prototyping with breadboards

I hope that You have enough of memory for code, stack, data etc. Otherwise unpredictable things will happend, like hangings, maybe resets.

joerack:
Everything works dandy... only issue is that in case the bmp180 sda or sda cables disconnect phisically, my nodemcu goes into reset loop.

      if (!bmp.begin()) {

Serial.println("No BMP180 / BMP085");// Crap! No Bmp180
      while (1) {}
      }

An Arduino would just sit at this point... an ESP8266 will trigger the WDT. To fix this:

      if (!bmp.begin()) {
       Serial.println("No BMP180 / BMP085");// Crap! No Bmp180
        while (1) {
          yield();
        }
      }

Now it will nicely sit there doing nothing, and not reset any more.