Added Temperature board driver

This commit is contained in:
Emanuele Trabattoni
2025-07-12 16:11:05 +02:00
parent e4d28b55cb
commit 1ad98799b4
3 changed files with 204 additions and 11 deletions

View File

@@ -6,6 +6,7 @@
#include <PubSubClient.h>
#include <PCF85063_Driver.h>
#include <R4DCB08_Driver.h>
#include <ETH_Driver.h>
#include <digitalIO.h>
@@ -43,6 +44,7 @@ void loop()
const uint8_t baseRegister(0x00);
uint16_t k(0);
uint8_t ethRetries(0);
uint8_t sensors(0);
//////////////// DEVICES ////////////////
// Declared here to keep devices local to the main loop otherwise the kernel crashes //
@@ -50,7 +52,10 @@ void loop()
auto bus = drivers::MODBUS(9600, SERIAL_8N1);
auto rtc = drivers::PCF85063(i2c, PCF85063_ADDRESS);
auto eth = drivers::Ethernet("waveshare-test");
auto tmp = drivers::R4DCB08(bus, tempBoardAddr);
delay(100);
auto io = digitalIO(i2c, bus, {relayBoardAddr});
delay(100);
Network.onEvent([&eth](arduino_event_id_t event, arduino_event_info_t info)
{ eth.onEvent(event, info); });
@@ -61,6 +66,10 @@ void loop()
delay(1000);
}
// Initialize temperature sensors
sensors = tmp.getNum();
LOG_INFO("Temperature sensors connected ->", sensors);
// Get RTC time at startup
time_t ntpTime;
drivers::PCF85063::datetime_t dt;
@@ -82,22 +91,22 @@ void loop()
while (true)
{
LOG_INFO("[", k++, "] Loop");
std::vector<uint16_t> results;
std::vector<bool> values;
eth.getNtpTime(ntpTime);
dt = drivers::PCF85063::fromEpoch(ntpTime);
LOG_INFO("Netwrok Datetime", rtc.datetime2str(dt).c_str());
LOG_INFO("Network Datetime", rtc.datetime2str(dt).c_str());
LOG_INFO("Current Datetime", rtc.getTimeStr().c_str());
mqtt.publish("test/esp32-out", ("[" + std::to_string(k) + "] -> " + rtc.getTimeStr()).c_str());
if (bus.readHoldingRegisters(tempBoardAddr, baseRegister, 1, results))
{
for (auto i(0); i < results.size(); i++)
{
LOG_INFO("[", i, "]Temperature: ", results.at(i) / 10.0f);
}
results.clear();
uint8_t i(0);
delay(10);
for (auto v: tmp.getTempAll()) {
LOG_INFO("Temperature channel", i++, "->", v);
}
i=0;
delay(10);
for (auto v : tmp.getCorrection()){
LOG_INFO("Temperature correction channel", i++, "tc", v);
}
for (auto j(0); j < io.getOutNum(); j++)
@@ -107,6 +116,10 @@ void loop()
delay(500);
}
//for (auto j(0); j < io.getOutNum(); j++)
//{
// io.digitalIOWrite(j, false);
//}
delay(5000);
}