Skip to content

Commit

Permalink
Merge branch 'main' into feat-config-payload
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bs committed May 31, 2024
2 parents 7afc3bc + e7fb357 commit 370037b
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/AppLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,46 @@

#include "AppLayer.h"

#ifdef ONEWIRE_EN
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
static OneWire oneWire(PIN_ONEWIRE_BUS); //!< OneWire bus

// Pass our oneWire reference to Dallas Temperature.
static DallasTemperature owTempSensors(&oneWire); //!< Dallas temperature sensors connected to OneWire bus
#endif

#ifdef ONEWIRE_EN
/*!
* \brief Get temperature from Maxim OneWire Sensor
*
* \param index sensor index
*
* \returns temperature in degrees Celsius or DEVICE_DISCONNECTED_C
*/
float
AppLayer::getOneWireTemperature(uint8_t index)
{
// Call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
owTempSensors.requestTemperatures();

// Get temperature by index
float tempC = owTempSensors.getTempCByIndex(index);

// Check if reading was successful
if (tempC != DEVICE_DISCONNECTED_C)
{
log_d("Temperature = %.2f°C", tempC);
}
else
{
log_d("Error: Could not read temperature data");
}

return tempC;
};
#endif

uint8_t
AppLayer::decodeDownlink(uint8_t port, uint8_t *payload, size_t size)
{
Expand Down Expand Up @@ -464,4 +504,5 @@ void AppLayer::setAppPayloadCfg(uint8_t *bytes, uint8_t size)
appPrefs.putBytes("payloadcfg", bytes, size);
appPrefs.end();
memcpy(appPayloadCfg, bytes, size);
}
}

0 comments on commit 370037b

Please sign in to comment.