Address of tempsensors is published to MQTT
This commit is contained in:
		@@ -82,5 +82,6 @@ DS18B20 one wire temp sensor
 | 
			
		||||
 * Nicht mehrere Messungen vom Temp-Sensor nur warten, bis wir einen Wert bekommen
 | 
			
		||||
 * Partitionslayout
 | 
			
		||||
 * OW-search address in topic nutzen
 | 
			
		||||
 * Wifi bei timout deaktivieren (damit wir entweder wlan spielen oder fallback: nur pflanzen giessen)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -192,12 +192,6 @@ void mode2MQTT()
 | 
			
		||||
  sensorLipo.setProperty("CCA").send(String(battery.getCCA()));
 | 
			
		||||
  sensorSolar.setProperty("volt").send(String(mSolarVoltage));
 | 
			
		||||
 | 
			
		||||
  sensorTemp.setProperty(TEMPERATUR_SENSOR_LIPO).send(String(mTempLipo));
 | 
			
		||||
  Serial << "Lipo Temperatur " << mTempLipo << " °C " << endl;
 | 
			
		||||
 | 
			
		||||
  sensorTemp.setProperty(TEMPERATUR_SENSOR_WATER).send(String(mTempWater));
 | 
			
		||||
  Serial << "Water Temperatur " << mTempWater << " °C " << endl;
 | 
			
		||||
 | 
			
		||||
  sensorTemp.setProperty(TEMPERATUR_SENSOR_CHIP).send(String(mChipTemp));
 | 
			
		||||
  Serial << "Chip Temperatur " << mChipTemp << " °C " << endl;
 | 
			
		||||
 | 
			
		||||
@@ -261,9 +255,12 @@ void readDistance()
 | 
			
		||||
    sei();
 | 
			
		||||
 | 
			
		||||
    int mmDis = duration * 0.3432 / 2;
 | 
			
		||||
    if(mmDis > MAX_TANK_DEPTH){
 | 
			
		||||
    if (mmDis > MAX_TANK_DEPTH)
 | 
			
		||||
    {
 | 
			
		||||
      waterRawSensor.add(0);
 | 
			
		||||
    } else {
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      waterRawSensor.add(mmDis);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@@ -282,7 +279,7 @@ void readSensors()
 | 
			
		||||
  delay(20);
 | 
			
		||||
 | 
			
		||||
  int timeoutTemp = millis() + TEMPERATUR_TIMEOUT;
 | 
			
		||||
  int sensorCount = 0;
 | 
			
		||||
  uint8_t sensorCount = 0U;
 | 
			
		||||
 | 
			
		||||
  /* Required to read the temperature at least once */
 | 
			
		||||
  while ((sensorCount == 0 || !battery.isFound()) && millis() < timeoutTemp)
 | 
			
		||||
@@ -300,10 +297,33 @@ void readSensors()
 | 
			
		||||
    sensors.requestTemperatures();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < sensorCount; i++) {
 | 
			
		||||
    float temp = sensors.getTempCByIndex(i);
 | 
			
		||||
  for (uint8_t i = 0; i < sensorCount; i++)
 | 
			
		||||
  {
 | 
			
		||||
    DeviceAddress ds18b20Address;
 | 
			
		||||
    sensors.getAddress(ds18b20Address, i);
 | 
			
		||||
    float temp = sensors.getTempC(ds18b20Address);
 | 
			
		||||
    Serial << "OneWire sensor " << i << " has value " << temp << endl;
 | 
			
		||||
    /** FIXME: handle via address */
 | 
			
		||||
    char buf[sizeof(DeviceAddress) * 2];
 | 
			
		||||
    snprintf(buf, sizeof(buf), "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X",
 | 
			
		||||
             ds18b20Address[0],
 | 
			
		||||
             ds18b20Address[1],
 | 
			
		||||
             ds18b20Address[2],
 | 
			
		||||
             ds18b20Address[3],
 | 
			
		||||
             ds18b20Address[4],
 | 
			
		||||
             ds18b20Address[5],
 | 
			
		||||
             ds18b20Address[6],
 | 
			
		||||
             ds18b20Address[7]);
 | 
			
		||||
 | 
			
		||||
      if (String(lipoSensorAddr.get()).compareTo(String(buf))) {
 | 
			
		||||
        sensorTemp.setProperty(TEMPERATUR_SENSOR_LIPO).send(String(temp));
 | 
			
		||||
        Serial << "Lipo Temperatur " << temp << " °C " << endl;
 | 
			
		||||
      } else if (String(waterSensorAddr.get()).compareTo(String(buf))) {
 | 
			
		||||
        sensorTemp.setProperty(TEMPERATUR_SENSOR_WATER).send(String(temp));
 | 
			
		||||
        Serial << "Water Temperatur " << temp << " °C " << endl;      
 | 
			
		||||
      }
 | 
			
		||||
      /* Always send the sensor address with the temperatur value */
 | 
			
		||||
      sensorTemp.setProperty(String(buf)).send(String(temp));
 | 
			
		||||
      Serial << "Temperatur " << String(buf) << " : " << temp << " °C " << endl;      
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Update battery chip data
 | 
			
		||||
@@ -455,8 +475,8 @@ void systemInit()
 | 
			
		||||
  // Set default values
 | 
			
		||||
 | 
			
		||||
  //in seconds
 | 
			
		||||
  deepSleepTime.setDefaultValue(600).setValidator([] (long candidate) {
 | 
			
		||||
    return (candidate > 0) && (candidate < (60 * 60 * 2) /** 2h max sleep */ );
 | 
			
		||||
  deepSleepTime.setDefaultValue(600).setValidator([](long candidate) {
 | 
			
		||||
    return (candidate > 0) && (candidate < (60 * 60 * 2) /** 2h max sleep */);
 | 
			
		||||
  });
 | 
			
		||||
  deepSleepNightTime.setDefaultValue(600);
 | 
			
		||||
  wateringDeepSleep.setDefaultValue(5);
 | 
			
		||||
 
 | 
			
		||||
@@ -15,3 +15,5 @@ framework = arduino
 | 
			
		||||
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
 | 
			
		||||
lib_deps = OneWire
 | 
			
		||||
            DallasTemperature
 | 
			
		||||
 | 
			
		||||
upload_port = /dev/ttyUSB1
 | 
			
		||||
 
 | 
			
		||||
@@ -110,9 +110,29 @@ void setup() {
 | 
			
		||||
  Serial.print("Bat I");
 | 
			
		||||
  Serial.print("\t");
 | 
			
		||||
  Serial.println("Temp/10");
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() { 
 | 
			
		||||
  static int loop=1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  DeviceAddress t;
 | 
			
		||||
  for(int i=0; i < sizeof(t); i++) {
 | 
			
		||||
    t[i] = loop + i*2;
 | 
			
		||||
  }
 | 
			
		||||
  char buf[sizeof(DeviceAddress)*2];
 | 
			
		||||
  snprintf(buf, sizeof(buf), "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X", t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7]);
 | 
			
		||||
/*
 | 
			
		||||
  %X -> linksbündige hexzahl
 | 
			
		||||
  %2X -> 2Stellige hexzahl ... dynamisch erweitert
 | 
			
		||||
  %0.2X -> 2stellige hexzahl mit führerder "0"
 | 
			
		||||
  */
 | 
			
		||||
  printf("Print: %s\n", buf);
 | 
			
		||||
  loop++;
 | 
			
		||||
  delay(500);
 | 
			
		||||
  return;
 | 
			
		||||
 | 
			
		||||
  whatever = !whatever;
 | 
			
		||||
  digitalWrite(OUTPUT_PUMP, HIGH);
 | 
			
		||||
  delay(500);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user