integrate CT with ESPMegaIoT
This commit is contained in:
parent
000c06809c
commit
69b2198342
|
@ -90,4 +90,8 @@ float CurrentTransformerCard::getVoltage(){
|
||||||
|
|
||||||
float CurrentTransformerCard::getPower(){
|
float CurrentTransformerCard::getPower(){
|
||||||
return this->current * *this->voltage;
|
return this->current * *this->voltage;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t CurrentTransformerCard::getType() {
|
||||||
|
return CARD_TYPE_CT;
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
#include <FRAM.h>
|
#include <FRAM.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#define CARD_TYPE_CT 5
|
#define CARD_TYPE_CT 4
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The CurrentTransformer class is a class for reading the current and energy from a current transformer that's connected to the AnalogCard.
|
* @brief The CurrentTransformer class is a class for reading the current and energy from a current transformer that's connected to the AnalogCard.
|
||||||
|
@ -29,6 +29,7 @@ class CurrentTransformerCard
|
||||||
float getVoltage();
|
float getVoltage();
|
||||||
uint8_t registerCallback(std::function<void(float, double)> callback);
|
uint8_t registerCallback(std::function<void(float, double)> callback);
|
||||||
void unregisterCallback(uint8_t handler);
|
void unregisterCallback(uint8_t handler);
|
||||||
|
uint8_t getType();
|
||||||
private:
|
private:
|
||||||
AnalogCard* analogCard;
|
AnalogCard* analogCard;
|
||||||
uint8_t pin;
|
uint8_t pin;
|
||||||
|
|
|
@ -52,7 +52,7 @@ void CurrentTransformerIoT::publishReport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t CurrentTransformerIoT::getType() {
|
uint8_t CurrentTransformerIoT::getType() {
|
||||||
return CARD_TYPE_CT;
|
return this->currentTransformerCard->getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CurrentTransformerIoT::processSetEnergyMessage(char* topic, char* payload, uint8_t topic_length) {
|
bool CurrentTransformerIoT::processSetEnergyMessage(char* topic, char* payload, uint8_t topic_length) {
|
||||||
|
|
|
@ -164,6 +164,14 @@ void ESPMegaIoT::registerCard(uint8_t card_id)
|
||||||
components[card_id]->publishReport();
|
components[card_id]->publishReport();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CARD_TYPE_CT:
|
||||||
|
components[card_id] = new CurrentTransformerIoT();
|
||||||
|
components[card_id]->begin(card_id, cards[card_id], &mqtt, this->mqtt_config.base_topic);
|
||||||
|
if (mqtt_connected)
|
||||||
|
{
|
||||||
|
components[card_id]->subscribe();
|
||||||
|
components[card_id]->publishReport();
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
ESP_LOGE("ESPMegaIoT", "Registering card %d failed: Unknown card", card_id);
|
ESP_LOGE("ESPMegaIoT", "Registering card %d failed: Unknown card", card_id);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include <DigitalOutputIoT.hpp>
|
#include <DigitalOutputIoT.hpp>
|
||||||
#include <ClimateCard.hpp>
|
#include <ClimateCard.hpp>
|
||||||
#include <ClimateIoT.hpp>
|
#include <ClimateIoT.hpp>
|
||||||
|
#include <CurrentTransformerCard.hpp>
|
||||||
|
#include <CurrentTransformerIoT.hpp>
|
||||||
#include <IoTComponent.hpp>
|
#include <IoTComponent.hpp>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <ETH.h>
|
#include <ETH.h>
|
||||||
|
|
Loading…
Reference in New Issue