Go Down

Topic: Nodemcu 0.9 - ESP8266 wifi module with 3pieces DS18B20 not only one (Read 2054 times) previous topic - next topic

User_82

Dear All,

I need your help for ESP8266 wifi module programming with 3pcs DS18B20 temerature sensor. Actually I have an example code which is working properly and  the temp results can be show in thingspeak graph.
My problem is now, the code is handling only one DS18B20 sensor, but I would like to measure with 3pcs sensors, and now I don't know how can I extend the code for more sensors. Also problem, I'm using 3pcs DS18B20 with individual 4k7 resistor,so I would not like to use a onewire BUS, I would like to solve on 3 different input on ESP8266.

Here is the code which is handling only one DS18B20 sensor insted of 3pieces:
Can anybody help on which direction can I start to extend this code for 3cs sensors on single input insted of the onewire bus?
 
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <stdlib_noniso.h>
 
 
#define ONE_WIRE_BUS 5  // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
 
const char* ssid     = "xxxxxxxxxxx";
const char* password = "xxxxxxxxxxx";
 
const char* host = "api.thingspeak.com";
const char* APIkey   = "O4C1EPUZQ87AOSV4";
 
 
float oldTemp;
 
 
 
void setup() {
  Serial.begin(115200);
  delay(10);
 
  // We start by connecting to a WiFi network
 
  Serial.println();
  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");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
 
 
 
void loop() {
  delay(30000);
 
  float temp;
 
 
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0);
  Serial.print("Temperature: ");
  Serial.println(temp);
 
  char charVal[12];
 
  dtostrf(temp, 8, 2, charVal);
 
  Serial.print("connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
 
 
 
 
  // We now create a URI for the request
  String url = "/update?key=";
  url += APIkey;
  url += "&field1=";
  url += charVal;//String(temp);
 
 
 
  Serial.print("Requesting URL: ");
  Serial.println(url);
 
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(10);
 
  // Read all the lines of the reply from server and print them to Serial
  while (client.available()) {
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
 
  Serial.println();
  Serial.println("closing connection");
}
 

Go Up