ESP32 firmware to connect a pellet stove to AWS IoT. Implemented specifically for a Piazzetta P937 model.
To create a new Pellet
object you will need to provide the number of the UART port to
use on your ESP32 and an optional configuration. If not provided, the cfg
showed here is
the default which is common on most Micronova boards.
let uartNo = 2; // UART port to use on the ESP32
let cfg = {
RAM: 0x00, // Type used to access RAM values
EPR: 0x20, // Type used to access EEPROM values
READ: 0x00, // Command used READ from the device
WRITE: 0x80 // Command used WRITE to the device
};
let pellet = Pellet.create(uartNo, cfg);
You will then need an object for each parameter you want to read or change, memory locations might vary on different devices or versions so be careful. The object must contain:
mem
: the memory where the value is stored, this must be equal to theRAM
orEPR
values in the configuration;addr
: the memory address of the value;name
: this name will be used to create an entry in thestate
object returned bygetState()
.
For most values the device will use a formula to store them in a single byte which is
realValue = off + (mult * memoryValue)
. Without further configuration you would have
to work with the memory values but there are two additional (optional) attributes that
will be used to automatically convert the values sent to and read from the device:
off
(optional): the offset of the value, default is0
;mult
(optional): the multiplier of the value, default is1
.
As an example, the temperatures stored in memory are usually half the real value, so in
this case you should use off: 0
and mult: 2
. You will then be able to write and read
temperatures directly in Celsius degrees.
// Example for a Piazzetta P937 model
let P937 = {
stage: { mem: cfg.RAM, addr: 0x21, mult: 1, off: 0, name: 'stage' },
ambientTmp: { mem: cfg.RAM, addr: 0x01, mult: 1, off: 0, name: 'ambientTmp' },
probeTmp: { mem: cfg.RAM, addr: 0x44, mult: 1, off: 0, name: 'probeTmp' },
targetTmp: { mem: cfg.EPR, addr: 0x7D, mult: 1, off: 0, name: 'targetTmp' },
power: { mem: cfg.EPR, addr: 0x7F, mult: 1, off: 0, name: 'power' },
fanLeft: { mem: cfg.EPR, addr: 0x81, mult: 1, off: 0, name: 'fanLeft' },
fanRight: { mem: cfg.EPR, addr: 0x82, mult: 1, off: 0, name: 'fanRight' }
};
Here be dragons.