我有4个传感器,其中一个传感器始终显示错误的温度。这不是传感器的问题,但这是代码的问题,因为我检查了它。
void getTemperature() {
float tempC;
float tempC3;
float tempC2;
float tempC4;
do {
DS18B20.requestTemperatures();
tempC = DS18B20.getTempCByIndex(0);
dtostrf(tempC, 2, 2, temperatureCString);
tempC3 = DS18B20.getTempFByIndex(1);
dtostrf(tempC3, 3, 2, temperatureCString3);
tempC2 = DS18B20.getTempCByIndex(2);
dtostrf(tempC2, 4, 2, temperatureCString2);
tempC4 = DS18B20.getTempCByIndex(3);
dtostrf(tempC4, 5, 2, temperatureCString4);
delay(100);
} while (tempC == 85.0 || tempC == (-127.0));
}
发送数据。
if (c == '\n' && blank_line) {
getTemperature();
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connection: close");
client.println();
// your actual web page that displays temperature
client.print("[");
client.print(temperatureCString);
client.print(",");
client.print(temperatureCString2);
client.print(",");
client.print(temperatureCString3);
client.print(",");
client.print(temperatureCString4);
client.print("]");
break;
}
if (c == '\n') {
// when starts reading a new line
blank_line = true;
}
else if (c != '\r') {
// when finds a character on the current line
blank_line = false;
}
}
}
// closing the client connection
delay(1);
client.stop();
Serial.println("Client disconnected.");
}
我在这里看到的是:https://screenshots.firefox.com/IStMqTgJTI2lmLxz/192.168.0.242 当我只剩下一个传感器时,我会看到以下信息: https://screenshots.firefox.com/sSXSYmcQbDLF9mUj/192.168.0.242 即使3rd(id 2)传感器不在时,也始终显示错误的温度。 你们有些人有主意吗?