Browse Source

Option to publish Dallas sensor address via MQTT (disabled by default)

i18n
Xose Pérez 6 years ago
parent
commit
ccc5843e7b
3 changed files with 31 additions and 2 deletions
  1. +6
    -2
      code/espurna/config/sensors.h
  2. +12
    -0
      code/espurna/sensor.ino
  3. +13
    -0
      code/espurna/sensors/DallasSensor.h

+ 6
- 2
code/espurna/config/sensors.h View File

@ -161,8 +161,12 @@
#define DALLAS_PIN 14
#endif
#define DALLAS_RESOLUTION 9 // Not used atm
#define DALLAS_READ_INTERVAL 2000 // Force sensor read & cache every 2 seconds
#define DALLAS_RESOLUTION 9 // Not used atm
#define DALLAS_READ_INTERVAL 2000 // Force sensor read & cache every 2 seconds
#define DALLAS_PUBLISH_ADDRESSES 0 // Publish sensor addresses
#define DALLAS_ADDRESS_TOPIC "address" // Topic to publish sensor addresses
//------------------------------------------------------------------------------
// DHTXX temperature/humidity sensor


+ 12
- 0
code/espurna/sensor.ino View File

@ -634,11 +634,23 @@ void sensorLoop() {
dtostrf(filtered, 1-sizeof(buffer), decimals, buffer);
#if MQTT_SUPPORT
if (SENSOR_USE_INDEX || (_counts[magnitude.type] > 1)) {
mqttSend(_magnitudeTopic(magnitude.type).c_str(), magnitude.global, buffer);
} else {
mqttSend(_magnitudeTopic(magnitude.type).c_str(), buffer);
}
#if DALLAS_SUPPORT && DALLAS_PUBLISH_ADDRESSES
if (magnitude.sensor->getID() == SENSOR_DALLAS_ID) {
if (SENSOR_USE_INDEX || (_counts[magnitude.type] > 1)) {
mqttSend(DALLAS_ADDRESS_TOPIC, magnitude.global, (((DallasSensor *) magnitude.sensor)->getAddress(magnitude.local)).c_str());
} else {
mqttSend(DALLAS_ADDRESS_TOPIC, (((DallasSensor *) magnitude.sensor)->getAddress(magnitude.local)).c_str());
}
}
#endif // DALLAS_SUPPORT && DALLAS_PUBLISH_ADDRESSES
#endif // MQTT_SUPPORT
#if INFLUXDB_SUPPORT


+ 13
- 0
code/espurna/sensors/DallasSensor.h View File

@ -170,6 +170,19 @@ class DallasSensor : public BaseSensor {
return String(buffer);
}
// Address of the device
String getAddress(unsigned char index) {
char buffer[20] = {0};
if (index < _count) {
uint8_t * address = _devices[index].address;
snprintf(buffer, sizeof(buffer), "%02X%02X%02X%02X%02X%02X%02X%02X",
address[0], address[1], address[2], address[3],
address[4], address[5], address[6], address[7]
);
}
return String(buffer);
}
// Descriptive name of the slot # index
String slot(unsigned char index) {
_error = SENSOR_ERROR_OK;


Loading…
Cancel
Save