WiFi in NodeMCU now depends on slaves?????????

Hello amazing people!
I have a problem here…i m tryna make a device havin BME 280,DS18B20,Soil moisture sensor<LUX sensor…all of em in nodeMCU…they work all fine as i use em one by one…when i connect all of em together to nodeMCU…Serial monitor dosent work…when i get my board outa circuit Serial monitor works well and works according to WiFimanager library…
Aint that damn strange… heres my code…please help me here
Thanks in advance

#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager
#include <Wire.h>
#include <SparkFunTSL2561.h> // library for luminosity sensor
 #include <SPI.h>
#include "cactus_io_BME280_SPI.h"
#include <WiFiClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>  // library for temperature sensor

#define sleepTime 180

String API_KEY ="HG509EcVR7RE18";

// assign the ESP8266 pins to arduino pins
//#define D1 5
//#define D2 4
//#define D4 2
//#define D5 0
// assign the SPI bus to pins
#define BME_SCK D3
#define BME_MISO D7
#define BME_MOSI D6
#define BME_CS D5
//#define SEALEVELPRESSURE_HPA (1013.25)

// Create the BME280 object
BME280_SPI bme(BME_CS,BME_MOSI,BME_MISO,BME_SCK);    // software SPI

double   humidity, pressure,altitude,ambient_temperature;

#define common_power D8 
//temp related info

int temperature_pin = D3; // often dosent work if pin is otherthan D3 or D4..........

OneWire oneWire(temperature_pin);

DallasTemperature sensors(&oneWire);

double Celcius = 0.00;

//moisture sensor related info

int moisture_pin = A0;

int moisture_reading;

// luminosity related info

//create object  LUX

SFE_TSL2561 LUX;

double lux_value;

//following three are parameters for function getTiming

//and have these particular datatypes with few predefined values

//which have their already meant purpose                       SDA=> D2.   SCL=> D1

unsigned char timer = 2;

unsigned int ms;

boolean sensitivity;
//username and password for net connection,which esp shall search for

char  *username = "SADAF", *password = " A123456d@";

double moisture_data;

//80=http

ESP8266WebServer server(80);

String page;

void setup() {

  // put your setup code here, to run once:
//    WiFi.mode(WIFI_STA);
//  wifi_set_sleep_type(LIGHT_SLEEP_T);

  Serial.begin(115200);

  WiFiManager wifiManager;
  
  wifiManager.autoConnect("Device CorpH");

  pinMode(moisture_pin, INPUT);

  pinMode(common_power, OUTPUT);
  
  WiFi.begin(username, password);

// ds18b20 must be taken in parasitic mode or pull up resistor should be defined

//observed: it works if none of the  above is done,...but some narrate it gets hot if not done so

//no proceeding till wifi connection is established
//
//  while (WiFi.status() != WL_CONNECTED) {
//
//    delay(500);
//
//    Serial.print("->");
//
//  }


  Serial.println("\nConnected to Wifi \nAll info shall be on the website");

  Serial.println("connected to");

  Serial.println(username);

  Serial.println("IP ADDRESS");

//IP should be noted and followed in browser

  Serial.println(WiFi.localIP());

//creating an html web page, also sendind data to it.....(gets executed after  "server.handleClient();" ststement in loop)

  server.on( "/", [] () {

    page = "<h1>DATA FROM SENSORS</h1><h3>Moisture sensor  </h3><h5>" + String(moisture_reading ) + "</h5><h3>Temperature sensor  </h3><h5>" + String(Celcius) + " celcius</h5><h3>LUX sensor  </h3><h5>" + String(lux_value) + " LUX</h5>";

    server.send(200, "text/html", page);
    delay(100);
    yield();
    

  });


  server.begin();

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  bme.setTempCal(-1);
  
}

void loop() {
  digitalWrite(common_power,HIGH);
  delay(20);

  // put your main code here, to run repeatedly:

// calling functions to collect data

  moisture();

  temperature();
 
  lux();

  BME();
  
//  server.handleClient();

// sending data to thingspeak

  sendData( lux_value, Celcius,moisture_data,ambient_temperature,pressure,humidity);

  digitalWrite(common_power,LOW);

// taking a nap to save battries
  
  delay(1000 );
  
  ESP.deepSleep(2*1000000);

}

//functions for particular sensor

void moisture() {
  
  delay(10);
  
  moisture_reading = analogRead(moisture_pin);

//changing voltage (data) form sensor to percentage

  moisture_reading = map(moisture_reading, 1024, 0, 0, 100);

  Serial.println("moisture");

  Serial.println(moisture_reading);
  
  
}

void temperature() {
   

  delay(10);
  
  sensors.begin();

  sensors.requestTemperatures();

  Celcius = sensors.getTempCByIndex(0);
  Serial.println("Celcius");

  Serial.println(Celcius);
}

void BME(){
  
 bme.readSensor();
  
    Serial.print(bme.getPressure_MB()); Serial.print("\t\t");    // Pressure in millibars
    Serial.print(bme.getHumidity()); Serial.print("\t\t");
    Serial.print(bme.getTemperature_C()); Serial.print(" *C\t");
    Serial.print(bme.getTemperature_F()); Serial.println(" *F\t");

   
    
    humidity=bme.getHumidity();

    pressure=bme.getPressure_MB();

    ambient_temperature=bme.getTemperature_C();
}

void lux() {

  delay(10);
  
  LUX.begin();

  LUX.setTiming(sensitivity, timer, ms);

  LUX.setPowerUp();

  unsigned int data1, data2;

  LUX.getData(data1, data2);

  // data1 and data2 corresponds to data of lingt and infrared rays,

  //passing them to following function, unaltered, gives luminosity 

  LUX.getLux(sensitivity, ms, data1, data2, lux_value);   // this function is of boolean type
  
  Serial.println("lux_value");

  Serial.println(lux_value);
  
 
}

void sendData(double lux,double Temperature,double moisture,double ambient_temperature,double pressure, double humidity) {  
   WiFiClient client;
  
   if (client.connect("api.thingspeak.com", 80)) { // use ip 184.106.153.149 or api.thingspeak.com
       Serial.println("WiFi Client connected ");
       
       String postStr = API_KEY;
       postStr += "&field1=";
       postStr += String(lux);
        postStr += "&field2=";
       postStr += String(Temperature);
       postStr += "&field3=";
       postStr += String(moisture);
       postStr += "&field4=";
       postStr += String( humidity);
       postStr += "&field5=";
       postStr += String(pressure);
       postStr += "&field6=";
       postStr += String(ambient_temperature);
       postStr += "\r\n\r\n";
       
       client.print("POST /update HTTP/1.1\n");
       client.print("Host: api.thingspeak.com\n");
       client.print("Connection: close\n");
       client.print("X-THINGSPEAKAPIKEY: " + API_KEY + "\n");
       client.print("Content-Type: application/x-www-form-urlencoded\n");
       client.print("Content-Length: ");
       client.print(postStr.length());
       client.print("\n\n");
       client.print(postStr);
       delay(1000);
   }
}

esp8266 was developed as 'network adapter' not to be used as standalone MCU. pins 0 D3, 2 D4 and 15 D8 are boot configuration pins and must have at boot the required state ensured by pull-up/down resistors. if you connect a wire that pulls down a pin that should be HIGH at boot, the the esp8266 will not start.

ADC of the esp8266 is used by WiFi libraries. you can use it, but if you use it very intensive, it interferes with the WiFi usage and the WiFi goes down.

why do you use software SPI?
you use D3 twice

thanks Juraj for your reply
It looks you've gone via my code carefully.....Damn thanks for that....
I used SPI for BME 280....before i tried to go for I2C which didnt work for BME at all....so had to go for SPI....
As for D3....that was a mistake....i corrected it and put D4 for temperature pin
Now isnt D3 SDA pin?.....how should I tackle this problem now.....I want to have all the devices connected to it along with wifi.......Then when can we use the pins you mentioned.....actually this is something new I got here....where can I get this in detail.....
Thanks again Juraj

Also....I have used the pins,those you mentioned, very frequently with number of devices ....It never happened????
why now???

esp8255 has hardware SPI and does't have hardware I2C. so you can use I2C on any pair of pis, but I don't see a reason to use software SPI

Juraj:
sensor...all of em in nodeMCU....they work all fine as i use em one by one.....when i connect all of em together to nodeMCU.....Serial monitor dosent work.....when i get my board outa circuit Serial monitor works well and works according to WiFimanager library....

the main Serial port on the nodeMCU (any ESP ftm) is connected to pins 1 & 3 (Tx & RX ) if you use those pins in your sketch or connect them to something (that most of all) the Serial port will not function the way you want it to.

Deva_Rishi:
the main Serial port on the nodeMCU (any ESP ftm) is connected to pins 1 & 3 (Tx & RX ) if you use those pins in your sketch or connect them to something (that most of all) the Serial port will not function the way you want it to.

he doesn't use io 1 and io 3. they don't have Dx constants

thanks juraj and Deva Rishi

but I don't see a reason to use software SPI

When i tried getting I2c for Bme 280.....It didnt work an d posted a question about it, I think so,....And i find it convinient to use Spi at the moment....hold on....I see you using word software with SPI as is in my code.....also my code is more of copy and paste and adjusting em .....Is spi software different from SPI....or whatever.... i think no....
so,could ya'll please suggest me what should I do next

you can use hardware SPI only on dedicated pins D5, D6, D7. if you use other pins the BME280 library will use software SPI.

THat makes it even more beautiful....now I have four devices which fill almost all the pins on nodeMCU board.....and how should I fix this error

Juraj

This page speaks about D3 and D8....shouldnt I use em at all then.....and wait I will test if this happens all because of these pins....could you suggest How will I use any other pins which fits my code and devices
thanks

Heres what I did
I used D0 instead of D3 and left D8 and D0 alone…and it worked…also I had D0 for wakin up from deep sleep it still worked fine…but Focks! this dosent end here…once my project comes to end i shall investigate and experiment this whole issue,new for me tho…I request ya’ll to help me by then…dont forget this page

sabishaw:
Juraj

ESP8266 Boot Mode Selection · espressif/esptool Wiki · GitHub

This page speaks about D3 and D8....shouldnt I use em at all then.....and wait I will test if this happens all because of these pins....could you suggest How will I use any other pins which fits my code and devices
thanks

D3 is io 0. it determines the flashing mode. should be HIGH for normal boot.
D4 is io 2. it should not be LOW at boot. some boards have it floating.
D8 is io 15 and should be LOW at boot. it has pull-down on board.

I had relays on io 0 and io 15 without problems. same relay on io 2 caused problems.

Thanks Juraj
I have D3 and D8 left untouched but have data cable of DS18B20 on D4 and works fine.......how come?

sabishaw:
Thanks Juraj
I have D3 and D8 left untouched but have data cable of DS18B20 on D4 and works fine.......how come?

the pins have pull-up/pull-down on board. and only at moment of boot it matters if they have the required state.

wHEN DOES it boot and why on its own.....I tried googling but got nothing relevant.......also I had to use another pin as blinking pin so i used RX i.ie. pin io 3 and it too worked fine.......
please tell me more about boot and how this pin meets need of boot or please refer me to a relevent link
thanks

sabishaw:
wHEN DOES it boot and why on its own…I tried googling but got nothing relevant…also I had to use another pin as blinking pin so i used RX i.ie. pin io 3 and it too worked fine…
please tell me more about boot and how this pin meets need of boot or please refer me to a relevent link
thanks

https://github.com/espressif/esptool/wiki/ESP8266-Boot-Mode-Selection

https://www.espressif.com/en/support/download/overview?keys=&field_type_tid[]=14
“ESP8266 Hardware Design Guidelines”