sensor_pzem.h
Go to the documentation of this file.
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
extern volatile bool sensor_pzem_measurement_received;
enum sensor_pzem_measurement_type_t {
SENSOR_PZEM_VOLTAGE = 0,
SENSOR_PZEM_CURRENT = 1,
SENSOR_PZEM_POWER = 2,
SENSOR_PZEM_ENERGY = 3,
// SENSOR_PZEM_ADDRESS = 4, // this is a setting, not a measurement
// SENSOR_PZEM_ALARM = 5, // this is a setting, not a measurement
SENSOR_PZEM_MAX
};
struct sensor_pzem_measurement_t {
enum sensor_pzem_measurement_type_t type;
bool valid;
union measurement_t {
float voltage;
float current;
uint16_t power;
uint32_t energy;
} value;
};
void sensor_pzem_setup(void);
void sensor_pzem_measurement_request(uint32_t address, enum sensor_pzem_measurement_type_t type);
struct sensor_pzem_measurement_t sensor_pzem_measurement_decode(void);
sensor_pzem_measurement_t
measurement returned by electricity meter
Definition: sensor_pzem.h:38
sensor_pzem_measurement_t::type
enum sensor_pzem_measurement_type_t type
measurement type
Definition: sensor_pzem.h:39
sensor_pzem_measurement_received
volatile bool sensor_pzem_measurement_received
a measurement response has been received
Definition: sensor_pzem.c:56
sensor_pzem_measurement_request
void sensor_pzem_measurement_request(uint32_t address, enum sensor_pzem_measurement_type_t type)
request measurement from electricity meter
Definition: sensor_pzem.c:97
sensor_pzem_setup
void sensor_pzem_setup(void)
setup peripherals to communicate with electricity meter
Definition: sensor_pzem.c:58
sensor_pzem_measurement_t::measurement_t
possible measurement values
Definition: sensor_pzem.h:42
sensor_pzem_measurement_decode
struct sensor_pzem_measurement_t sensor_pzem_measurement_decode(void)
decode received measurement
Definition: sensor_pzem.c:128
sensor_pzem_measurement_t::measurement_t::energy
uint32_t energy
measured energy in watts/hour (24 bits)
Definition: sensor_pzem.h:46
sensor_pzem_measurement_type_t
sensor_pzem_measurement_type_t
measurements (and configurations) offered by electricity meter
Definition: sensor_pzem.h:27
sensor_pzem_measurement_t::valid
bool valid
is the measurement valid (e.g.
Definition: sensor_pzem.h:40
sensor_pzem_measurement_t::measurement_t::power
uint16_t power
measured power in watts
Definition: sensor_pzem.h:45
sensor_pzem_measurement_t::value
union sensor_pzem_measurement_t::measurement_t value
measurement value
sensor_pzem_measurement_t::measurement_t::current
float current
measured current in amperes
Definition: sensor_pzem.h:44
sensor_pzem_measurement_t::measurement_t::voltage
float voltage
measured voltage in volts
Definition: sensor_pzem.h:43