# HG changeset patch # User Michiel Broek # Date 1573572411 -3600 # Node ID 1f507aba656137f4735172e5a9c4369cd12aa936 # Parent 8b630bf52092b05375f0027c611cb2a2156fc5ed Search DS18B20 sensor for the right pressure unit. diff -r 8b630bf52092 -r 1f507aba6561 main/co2meter.c --- a/main/co2meter.c Tue Nov 12 10:36:53 2019 +0100 +++ b/main/co2meter.c Tue Nov 12 16:26:51 2019 +0100 @@ -191,30 +191,44 @@ Main_Loop1 = ML1_WAITCON; ESP_LOGI(TAG, "Loop timer: Wait MQTT"); - /* Get global temperature, use for all units. */ - uint32_t temp = 0; - int state = 0; - char rom_code[17]; + uint32_t temp[DS18B20_MAX]; + int state[DS18B20_MAX], i, num_sensors = 0; + char rom_code[DS18B20_MAX][17]; + for (i = 0; i < DS18B20_MAX; i++) { + temp[i] = 0; + state[i] = 0; + rom_code[i][0] = '\0'; + } + /* Copy results from all connected DS18B20 sensors */ if (xSemaphoreTake(xSemaphoreDS18B20, 10) == pdTRUE) { - temp = (ds18b20_state->sensor[0].temperature * 1000); - state = (ds18b20_state->sensor[0].error == 0) ? 0:1; - strncpy(rom_code, ds18b20_state->sensor[0].rom_code, 17); - rom_code[16] = '\0'; + num_sensors = ds18b20_state->num_sensors; + for (i = 0; i < num_sensors; i++) { + temp[i] = (ds18b20_state->sensor[i].temperature * 1000); + state[i] = (ds18b20_state->sensor[i].error == 0) ? 0:1; + strncpy(rom_code[i], ds18b20_state->sensor[i].rom_code, 17); + rom_code[i][16] = '\0'; + } xSemaphoreGive(xSemaphoreDS18B20); } else { ESP_LOGE(TAG, "ML1_MQTT_CONNECT DS18B20 lock error"); } /* Copy measured data and calculate results */ - for (int i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) { if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) { - units[i].temperature = temp; - units[i].temperature_state = state; - units[i].alarm = 0; - if (state) - units[i].alarm |= ALARM_SYS_TEMPERATURE & ALARM_UNIT_TEMPERATURE; - strncpy(units[i].temperature_rom_code, rom_code, 17); + /* Search configured temperature sensor for this unit */ + for (int j = 0; j < num_sensors; j++) { + if (strcmp(rom_code[j], units[i].temperature_rom_code) == 0) { + units[i].temperature = temp[j]; + units[i].temperature_state = state[j]; + units[i].alarm = 0; + if (state[j]) + units[i].alarm |= ALARM_SYS_TEMPERATURE & ALARM_UNIT_TEMPERATURE; + break; + } + } + /* Get the ADC results */ if (xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE) { units[i].pressure_state = adc_state->Pressure[i].error; units[i].pressure_channel = adc_state->Pressure[i].channel; @@ -227,7 +241,6 @@ units[i].pressure = P; printf("%d volt: %d batt: %d scale: %d mbar: %d\n", i, units[i].pressure_voltage, adc_state->Batt_voltage, units[i].pressure_voltage / (adc_state->Batt_voltage / 1000) - units[i].pressure_zero, P); -// Moet die echt op 5 volt? // Verbruik 10 mA // Setup tijd max 2 mS xSemaphoreGive(xSemaphoreADC);