Skip to content

Latest commit

 

History

History
182 lines (113 loc) · 4.57 KB

api.md

File metadata and controls

182 lines (113 loc) · 4.57 KB

API Reference

Header files

File include/ce2727a.h

Structures and Types

Type Name
struct ce2727a_config_t
CE2727A driver configuration.
typedef struct ce2727a_driver_state_t * ce2727a_handle_t
CE2727A driver handle.
struct ce2727a_readings_energy_t
CE2727A readings.

Functions

Type Name
esp_err_t ce2727a_deinit (ce2727a_handle_t handle)
Deinitialize the CE2727A driver.
esp_err_t ce2727a_get_active_power (ce2727a_handle_t handle, uint32_t * active_power, uint16_t timeout_ms)
Get active power.
esp_err_t ce2727a_get_energy (ce2727a_handle_t handle, ce2727a_readings_energy_t* readings, uint16_t timeout_ms)
Get energy readings.
esp_err_t ce2727a_init (const ce2727a_config_t* config, ce2727a_handle_t * out_handle)
Initialize the CE2727A driver.

Structures and Types Documentation

struct ce2727a_config_t

CE2727A driver configuration. Variables:

  • uint32_t addr
    Target power meter address, default is 0x0 - broadcasting to all meters

  • uint32_t password
    Target power meter password, default is 0x0

  • uint8_t * rx_buffer
    Receive buffer. Shall be enough to hold required responses

  • uint16_t rx_buffer_size
    Size of receive buffer

  • uart_config_t * uart_config_override
    UART port configuration override parameters. defaults: 9600,8E1

  • uint8_t uart_de_pin
    UART RTS pin for RS485 DE=!RE

  • uint8_t uart_port
    UART port number

  • uint8_t uart_rx_pin
    UART RX pin

  • uint8_t uart_tx_pin
    UART TX pin

typedef ce2727a_handle_t

CE2727A driver handle.

typedef struct ce2727a_driver_state_t* ce2727a_handle_t;

struct ce2727a_readings_energy_t

CE2727A readings. Variables:

  • uint8_t active_tariff
    Current active tariff [1,2,3,4]

  • uint32_t t1
    Cumulative energy for tariff 1

  • uint32_t t2
    Cumulative energy for tariff 2

  • uint32_t t3
    Cumulative energy for tariff 3

  • uint32_t t4
    Cumulative energy for tariff 4

  • uint32_t total
    Cumulative energy consumed on all tariffs

Functions Documentation

function ce2727a_deinit

Deinitialize the CE2727A driver.

esp_err_t ce2727a_deinit (
    ce2727a_handle_t handle
) 

Parameters:

  • handle Driver handle obtained from ce2727a_init(), or NULL

Returns:

esp_err_t ESP_OK on success.

function ce2727a_get_active_power

Get active power.

esp_err_t ce2727a_get_active_power (
    ce2727a_handle_t handle,
    uint32_t * active_power,
    uint16_t timeout_ms
) 

Get current active power

Parameters:

  • handle Driver handle obtained from ce2727a_init()
  • active_power Active power
  • timeout_ms Timeout in milliseconds for receiving a response from the meter

Returns:

esp_err_t

  • ESP_OK on success
  • ESP_ERR_TIMEOUT if no message was received within the timeout
  • ESP_ERR_INVALID_ARG if the buffer too short
  • ESP_ERR_INVALID_RESPONSE
  • ESP_ERR_INVALID_CRC
  • ESP_ERR_INVALID_STATE Issues sending data

function ce2727a_get_energy

Get energy readings.

esp_err_t ce2727a_get_energy (
    ce2727a_handle_t handle,
    ce2727a_readings_energy_t * readings,
    uint16_t timeout_ms
) 

Get energy readings

Parameters:

  • handle Driver handle obtained from ce2727a_init()
  • readings Destination for readings
  • timeout_ms Timeout in milliseconds for receiving a response from the meter

Returns:

esp_err_t

  • ESP_OK on success
  • ESP_ERR_TIMEOUT if no message was received within the timeout
  • ESP_ERR_INVALID_ARG if the buffer too short
  • ESP_ERR_INVALID_RESPONSE
  • ESP_ERR_INVALID_CRC
  • ESP_ERR_INVALID_STATE Issues sending data

function ce2727a_init

Initialize the CE2727A driver.

esp_err_t ce2727a_init (
    const ce2727a_config_t * config,
    ce2727a_handle_t * out_handle
) 

Parameters:

  • config Pointer to the configuration struct. The driver makes a copy, so can point to a local variable.
  • out_handle Pointer to a variable to receive the driver handle.

Returns:

esp_err_t ESP_OK on success, ESP_ERR_NO_MEM if out of memory.