Just an observation, but the code for getting the temperature looks way too complex. What model of sensor are you using?
You need to include the spark-dallas-temperature
library in your code.
To get the temperature in Celsius you can just do:
ds.requestTemperatures();
float celsius = ds.getTempCByIndex(0);
Also, you should probably change:
OneWire ds = OneWire(D4); // 1-wire signal on pin D4
to
DallasTemperature ds(new OneWire(D4));
getSoilTemp
should look like this:
void getSoilTemp()
{
ds.requestTemperatures();
float celsius = ds.getTempCByIndex(0);
float fahrenheit = ds.getTempFByIndex(0);
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");
}
Also, you can substitute a timer by putting this in your loop()
:
if (millis()/1000 % 1 == 0) // Every second
{
getSoilTemp();
}