I dont have a lot of experience in esp8266 but,
I found this code and i wanted to make it suitable for my needs but i dont know if it would work or what would i need to change to make it work with 12 sensors instead of 3, any help is appriciated
/*************************************************
* Written by : Usman Ali Butt *
* Property off : www.microcontroller-project.com*
* Dated : 30 July 2018 *
************************************************/
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
// Data output of DS18B20 is connected to nodemcu GPIO 5 or D1
#define ONE_WIRE_BUS 5
// Setting a one wire instance
OneWire oneWire(ONE_WIRE_BUS);
// Passing onewire instance to Dallas Temperature sensor library
DallasTemperature sensors(&oneWire);
const char* ssid = "Your SSID"; //Enter your WiFi SSID Here
const char* password = "Your Wifi Password"; //Enter your WiFi Password Here
int Celsius1=0, Fahrenheit1=0; //Variables to store temperature readings from DS18B20 temperature sensors
int Celsius2=0, Fahrenheit2=0;
int Celsius3=0, Fahrenheit3=0;
WiFiServer server(80); //Web server default port
void setup(){
Serial.begin(115200); //initialize serial communication
delay(10);
sensors.begin(); // Begin the DS18B20 initialization
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to "); // Connect to WiFi network
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address on serial monitor
Serial.print("Use this URL to connect: ");
Serial.print("http://"); //URL IP to be typed in mobile/desktop browser
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop(){
sensors.requestTemperatures(); //Call all sensors on one wire to start calculating the temperature readings
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
if (request.indexOf("/Tem=ON") != -1) {
Celsius1=sensors.getTempCByIndex(0); //Get temperature reading from sensor 0 in celsius scale
Fahrenheit1=sensors.getTempFByIndex(0);//Get temperature reading from sensor 0 in fahrenheit scale
Celsius2=sensors.getTempCByIndex(1); //Get temperature reading from sensor 0 in celsius scale
Fahrenheit2=sensors.getTempFByIndex(1);//Get temperature reading from sensor 0 in fahrenheit scale
Celsius3=sensors.getTempCByIndex(2); //Get temperature reading from sensor 0 in celsius scale
Fahrenheit3=sensors.getTempFByIndex(2);//Get temperature reading from sensor 0 in fahrenheit scale
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<h1>Multiple Ds18b20 with Nodemcu</h1>");
client.println("<br><br>");
client.print("Sensor-1 Celcius Temperature =");
client.print(Celsius1);
client.println("<br>Sensor-1 Farenheight Temperature =");
client.print(Fahrenheit1);
client.print("<br>Sensor-2 Celcius Temperature =");
client.print(Celsius2);
client.println("<br>Sensor-2 Farenheight Temperature =");
client.print(Fahrenheit2);
client.print("<br>Sensor-3 Celcius Temperature =");
client.print(Celsius3);
client.println("<br>Sensor-3 Farenheight Temperature =");
client.print(Fahrenheit3);
client.println("<br><br>");
client.println("<a href=\"/Tem=ON\"\"><button>Update Temperature</button></a><br />");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}