make shit work more
This commit is contained in:
		@@ -36,21 +36,15 @@ int Ds18B20::readAllTemperatures(float* pTemperatures, int maxTemperatures) {
 | 
				
			|||||||
    byte addr[8];
 | 
					    byte addr[8];
 | 
				
			||||||
    uint8_t scratchPad[SCRATCHPADSIZE];
 | 
					    uint8_t scratchPad[SCRATCHPADSIZE];
 | 
				
			||||||
    int currentTemp = 0;
 | 
					    int currentTemp = 0;
 | 
				
			||||||
#ifdef DS_DEBUG
 | 
					 | 
				
			||||||
    int i;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (this->mDs->search(addr)) {
 | 
					    while (this->mDs->search(addr)) {
 | 
				
			||||||
#ifdef DS_DEBUG
 | 
					 | 
				
			||||||
        Serial.print(" ROM =");
 | 
					 | 
				
			||||||
        for (i = 0; i < 8; i++) {
 | 
					 | 
				
			||||||
            Serial.write(' ');
 | 
					 | 
				
			||||||
            Serial.print(addr[i], HEX);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
        this->mDs->reset();
 | 
					        this->mDs->reset();
 | 
				
			||||||
        this->mDs->select(addr);
 | 
					        this->mDs->select(addr);
 | 
				
			||||||
        this->mDs->write(STARTCONV);
 | 
					        this->mDs->write(STARTCONV);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    delay(750);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    while (this->mDs->search(addr)) {
 | 
				
			||||||
        this->mDs->reset();
 | 
					        this->mDs->reset();
 | 
				
			||||||
        this->mDs->select(addr);
 | 
					        this->mDs->select(addr);
 | 
				
			||||||
        this->mDs->write(READSCRATCH);
 | 
					        this->mDs->write(READSCRATCH);
 | 
				
			||||||
@@ -68,14 +62,6 @@ int Ds18B20::readAllTemperatures(float* pTemperatures, int maxTemperatures) {
 | 
				
			|||||||
        // byte 7: DS18S20: COUNT_PER_C
 | 
					        // byte 7: DS18S20: COUNT_PER_C
 | 
				
			||||||
        //         DS18B20 & DS1822: store for crc
 | 
					        //         DS18B20 & DS1822: store for crc
 | 
				
			||||||
        // byte 8: SCRATCHPAD_CRC
 | 
					        // byte 8: SCRATCHPAD_CRC
 | 
				
			||||||
#ifdef DS_DEBUG
 | 
					 | 
				
			||||||
        Serial.write("\r\nDATA:");
 | 
					 | 
				
			||||||
        for (uint8_t i = 0; i < 9; i++) {
 | 
					 | 
				
			||||||
            Serial.print(scratchPad[i], HEX);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
        delay(50);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
        for (uint8_t i = 0; i < 9; i++) {
 | 
					        for (uint8_t i = 0; i < 9; i++) {
 | 
				
			||||||
            scratchPad[i] = this->mDs->read();
 | 
					            scratchPad[i] = this->mDs->read();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,8 +51,8 @@ RTC_DATA_ATTR long lastWaterValue = 0;
 | 
				
			|||||||
const char* ntpServer = "pool.ntp.org";
 | 
					const char* ntpServer = "pool.ntp.org";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool warmBoot = true;
 | 
					bool warmBoot = true;
 | 
				
			||||||
bool mode3Active = false;   /**< Controller must not sleep */
 | 
					bool volatile mode3Active = false;   /**< Controller must not sleep */
 | 
				
			||||||
bool mDeepsleep = false;
 | 
					bool volatile mDeepsleep = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int plantSensor1 = 0;
 | 
					int plantSensor1 = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -121,7 +121,9 @@ bool prepareSleep(void *) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void espDeepSleepFor(long seconds, bool activatePump = false){
 | 
					void espDeepSleepFor(long seconds, bool activatePump = false){
 | 
				
			||||||
  delay(1500);
 | 
					  if(mode3Active){
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
 | 
					  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
 | 
				
			||||||
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
 | 
					  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
 | 
				
			||||||
@@ -147,7 +149,8 @@ void espDeepSleepFor(long seconds, bool activatePump = false){
 | 
				
			|||||||
  Serial.print(seconds);
 | 
					  Serial.print(seconds);
 | 
				
			||||||
  Serial.println(" seconds");
 | 
					  Serial.println(" seconds");
 | 
				
			||||||
  esp_sleep_enable_timer_wakeup( (seconds * 1000U * 1000U) );
 | 
					  esp_sleep_enable_timer_wakeup( (seconds * 1000U * 1000U) );
 | 
				
			||||||
  wait4sleep.in(500, prepareSleep);
 | 
					  //wait4sleep.in(500, prepareSleep);
 | 
				
			||||||
 | 
					  mDeepsleep=true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -183,27 +186,16 @@ void mode2MQTT(){
 | 
				
			|||||||
  sensorSolar.setProperty("percent").send(String((100 * solarRawSensor.getAverage() ) / 4095));
 | 
					  sensorSolar.setProperty("percent").send(String((100 * solarRawSensor.getAverage() ) / 4095));
 | 
				
			||||||
  sensorSolar.setProperty("volt").send( String(getSolarVoltage()) );
 | 
					  sensorSolar.setProperty("volt").send( String(getSolarVoltage()) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  float temp[2] = { TEMP_INIT_VALUE, TEMP_INIT_VALUE };
 | 
					  float t1 = temp1.getMedian();
 | 
				
			||||||
  float* pFloat = temp;
 | 
					  float t2 = temp2.getMedian();
 | 
				
			||||||
  int devices = dallas.readAllTemperatures(pFloat, 2);
 | 
					  sensorTemp.setProperty("control").send( String(t1));
 | 
				
			||||||
  if (devices < 2) {
 | 
					  sensorTemp.setProperty("temp").send( String(t2));
 | 
				
			||||||
    if ((pFloat[0] > TEMP_INIT_VALUE) && (pFloat[0] < TEMP_MAX_VALUE) ) {
 | 
					 | 
				
			||||||
      sensorTemp.setProperty("control").send( String(pFloat[0]));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  } else if (devices >= 2) {      
 | 
					 | 
				
			||||||
    if ((pFloat[0] > TEMP_INIT_VALUE) && (pFloat[0] < TEMP_MAX_VALUE) ) {
 | 
					 | 
				
			||||||
      sensorTemp.setProperty("temp").send( String(pFloat[0]));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if ((pFloat[1] > TEMP_INIT_VALUE) && (pFloat[1] < TEMP_MAX_VALUE) ) {
 | 
					 | 
				
			||||||
      sensorTemp.setProperty("control").send( String(pFloat[1]));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool lipoTempWarning = abs(temp[0] - temp[1]) > 5;
 | 
					  bool lipoTempWarning = t1!=85 && t2!=85 && abs(t1 - t2) > 10;
 | 
				
			||||||
  if(lipoTempWarning){
 | 
					  if(lipoTempWarning){
 | 
				
			||||||
    Serial.println("Lipo temp incorrect, panic mode deepsleep");
 | 
					    Serial.println("Lipo temp incorrect, panic mode deepsleep TODO");
 | 
				
			||||||
    espDeepSleepFor(PANIK_MODE_DEEPSLEEP);
 | 
					    //espDeepSleepFor(PANIK_MODE_DEEPSLEEP);
 | 
				
			||||||
    return;
 | 
					    //return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool hasWater = true;//FIXMEmWaterGone > waterLevelMin.get();
 | 
					  bool hasWater = true;//FIXMEmWaterGone > waterLevelMin.get();
 | 
				
			||||||
@@ -339,18 +331,12 @@ void readSensors() {
 | 
				
			|||||||
  /* Required to read the temperature once */
 | 
					  /* Required to read the temperature once */
 | 
				
			||||||
  float temp[2] = {0, 0};
 | 
					  float temp[2] = {0, 0};
 | 
				
			||||||
  float* pFloat = temp;
 | 
					  float* pFloat = temp;
 | 
				
			||||||
  for(int i=0; i < 10; i++) {
 | 
					  if (dallas.readAllTemperatures(pFloat, 2) > 0) {
 | 
				
			||||||
    // first read returns crap, ignore result and read twice
 | 
					    Serial << "t1: " << String(temp[0]) << endl;
 | 
				
			||||||
    if (dallas.readAllTemperatures(pFloat, 2) > 0) {
 | 
					    Serial << "t2: " << String(temp[1]) << endl;
 | 
				
			||||||
        Serial << "t1: " << String(temp[0]) << endl;
 | 
					 | 
				
			||||||
        Serial << "t2: " << String(temp[1]) << endl;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    delay(200);
 | 
					 | 
				
			||||||
    if (i <= 2) {
 | 
					 | 
				
			||||||
      temp1.add(temp[0]);
 | 
					 | 
				
			||||||
      temp2.add(temp[1]);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  temp1.add(temp[0]);
 | 
				
			||||||
 | 
					  temp2.add(temp[1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* Use the Ultrasonic sensor to measure waterLevel */
 | 
					  /* Use the Ultrasonic sensor to measure waterLevel */
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user