2 Commits

2 changed files with 18 additions and 46 deletions

View File

@@ -12,15 +12,17 @@ public:
template <class T>
void send(int code, T contentType, const JsonVariantConst content, bool pretty = false) {
auto contentLength = pretty ? measureJsonPretty(content) : measureJson(content);
#ifdef ARDUINO_ARCH_ESP8266
if (!this->webServer->chunkedResponseModeStart(code, contentType)) {
this->webServer->send(505, F("text/html"), F("HTTP1.1 required"));
return;
}
this->webServer->setContentLength(measureJson(content));
this->webServer->setContentLength(contentLength);
#else
this->webServer->setContentLength(measureJson(content));
this->webServer->setContentLength(contentLength);
this->webServer->send(code, contentType, emptyString);
#endif

View File

@@ -175,16 +175,19 @@ protected:
continue;
}
if (millis() - this->dallasSearchTime[gpio] > this->dallasSearchInterval) {
this->dallasSearchTime[gpio] = millis();
instance.begin();
Log.straceln(
FPSTR(L_SENSORS_DALLAS),
F("GPIO %hhu, devices on bus: %hhu, DS18* devices: %hhu"),
gpio, instance.getDeviceCount(), instance.getDS18Count()
);
if (millis() - this->dallasSearchTime[gpio] < this->dallasSearchInterval) {
continue;
}
this->dallasSearchTime[gpio] = millis();
this->owInstances[gpio].reset();
instance.begin();
Log.straceln(
FPSTR(L_SENSORS_DALLAS),
F("GPIO %hhu, devices on bus: %hhu, DS18* devices: %hhu"),
gpio, instance.getDeviceCount(), instance.getDS18Count()
);
}
}
@@ -274,25 +277,14 @@ protected:
unsigned long ts = millis();
if (this->dallasPolling[gpio]) {
auto minPollingTime = instance.millisToWaitForConversion(12);
auto minPollingTime = instance.millisToWaitForConversion(12) * 2;
unsigned long estimatePollingTime = ts - this->dallasLastPollingTime[gpio];
// check conversion time
// isConversionComplete does not work with chinese clones!
if (estimatePollingTime < minPollingTime) {
continue;
}
// check conversion
bool conversionComplete = instance.isConversionComplete();
if (!conversionComplete) {
if (estimatePollingTime > (minPollingTime * 2)) {
this->dallasPolling[gpio] = false;
Log.swarningln(FPSTR(L_SENSORS_DALLAS), F("GPIO %hhu, timeout receiving data"), gpio);
}
continue;
}
// read sensors data for current instance
for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) {
@@ -345,28 +337,6 @@ protected:
continue;
}
// check sensors on bus
if (!instance.getDeviceCount()) {
for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) {
auto& sSensor = Sensors::settings[sensorId];
// only target & valid sensors
if (!sSensor.enabled || sSensor.type != Sensors::Type::DALLAS_TEMP || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) {
continue;
} else if (sSensor.gpio != gpio || isEmptyAddress(sSensor.address)) {
continue;
}
auto& rSensor = Sensors::results[sensorId];
if (rSensor.signalQuality > 0) {
rSensor.signalQuality--;
}
}
continue;
}
// start polling
instance.setResolution(12);
instance.requestTemperatures();