I have a Multical 401 district heater utility meter.
A IR-head is utilised in order to read the data from the utility meter.
The request needs a baud rate of 300. The data comes back with a baud rate of 1200.
At this moment I use two different UART configurations in my ESPHome program to deal with this.
uart:
#Multical UART, 2 instances due to different baud-rates for Tx and Rx.
- tx_pin: GPIO21
baud_rate: 300
id: uart_tx
- rx_pin: GPIO22
baud_rate: 1200
id: uart_rx
In my custom component I create 2 UARTDevices to deal with this. I use _tx
(at baud rate 300) to write and _rx
(at 1200) to read.
#include "esphome.h"
#include "esphome/core/component.h"
class Multical401 : public PollingComponent, public UARTDevice {
public:
// Not relevant for question
Multical401(uint32_t update_interval, UARTComponent *uart_tx, UARTComponent *uart_rx, SKIP : PollingComponent(update_interval), SKIP {
_tx = new UARTDevice(uart_tx);
_rx = new UARTDevice(uart_rx);
}
void setup() override { }
void update() override {
byte sendmsg1[] = { 175,163,177 };
// Not relevant for question
for (int x = 0; x < 3; x++) {
_tx->write(sendmsg1[x]);
}
// Not relevant for question
while(r != 0x0A)
{
if (_rx->available())
{
// receive byte
r = _rx->read();
//etcetera...
Is there a better way to do this? I would like to create just one UART config like:
uart:
#Multical UART
- tx_pin: GPIO21
rx_pin: GPIO22
baud_rate: 300
id: uart
In my custom component I would like to change the baud rate to 300 for Tx and 1200 for Rx.
Any suggestions if this is possible?