我有 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 总是第三(id 2) 即使他不在,传感器也会显示错误的温度。你们有些人有什么想法吗?