updates to library, comments, etc

master
Andrew Woodlee 2 months ago
parent a00ba602ab
commit c67894f4a1

@ -70,7 +70,7 @@ ATM90E26_IC eic;
// extract the ATM90E36 CT LINE from its macro // extract the ATM90E36 CT LINE from its macro
#ifdef TM_ATM90E36_CT_LINE #ifdef TM_ATM90E36_CT_LINE
char const ctLine = (char) STR(TM_ATM90E36_CT_LINE); char const ctLine = (char) STR(TM_ATM90E36_CT_LINE);
#else #else // if nothing is defined, use 'A' as the default value
char const ctLine = 'A'; char const ctLine = 'A';
#endif #endif
#include <ATM90E36_IC.h> #include <ATM90E36_IC.h>
@ -80,12 +80,12 @@ ATM90E36_IC eic(ctLine, ic);
#endif #endif
// we are using the ESP32's MAC address to provide a unique ID // we are using the transformer's name to provide a unique ID
String client_id = "xformermon-"; String client_id = "name-of-transformer";
// GPIO where the DS18B20 is connected to // GPIO pins where the DS18B20 sensors are connected
const int oilTempBus = 4; const int oilTempBus = 4;
const int cabinetTempBus = 9; const int cabinetTempBus = 9;
@ -104,9 +104,9 @@ OneWire cabinetTempBusOneWire(cabinetTempBus);
DallasTemperature oilTempSensor(&oilTempBusOneWire); DallasTemperature oilTempSensor(&oilTempBusOneWire);
DallasTemperature cabinetTempSensor(&cabinetTempBusOneWire); DallasTemperature cabinetTempSensor(&cabinetTempBusOneWire);
// temp sensor objects
tempSensors monitorTempSensors{oilTempSensor, cabinetTempSensor}; tempSensors monitorTempSensors{oilTempSensor, cabinetTempSensor};
StaticJsonDocument<256> dataStore[60];
time_t now; time_t now;
// Data structs for queue // Data structs for queue
@ -138,7 +138,7 @@ struct xformerMonitorData {
// Global to be used in ISR // Global to be used in ISR
xformerMonitorData sensorData; xformerMonitorData sensorData;
// Variables for tasks // Variables for tasks and queue
TaskHandle_t taskReadEIC; TaskHandle_t taskReadEIC;
TaskHandle_t taskSendData; TaskHandle_t taskSendData;
@ -161,6 +161,9 @@ void IRAM_ATTR ReadData();
#define PIN_BLUE 21 // GPIO21 #define PIN_BLUE 21 // GPIO21
// LED color Function // LED color Function
// Red - 0 to 255
// Green - 0 to 255
// Blue - 0 to 255
void setColor(int R, int G, int B); void setColor(int R, int G, int B);

@ -17,7 +17,7 @@
} }
void ATM90E36_IC::begin(){ void ATM90E36_IC::begin(){
this->eic->begin(5, 0x003C, 0x100, 0x100, 0x100,0x100, 0x100, 0x100); this->eic->begin(5, 0x003C, 0x1000, 0x1000, 0x1000,0x1000, 0x1000, 0x1000);
} }
double ATM90E36_IC::GetLineVoltage() double ATM90E36_IC::GetLineVoltage()
{ {
@ -26,8 +26,10 @@ void ATM90E36_IC::begin(){
{ {
case 'A': case 'A':
lv = eic->GetLineVoltageA(); lv = eic->GetLineVoltageA();
break;
case 'B': case 'B':
lv = eic->GetLineVoltageB(); lv = eic->GetLineVoltageB();
break;
case 'C': case 'C':
lv = eic->GetLineVoltageC(); lv = eic->GetLineVoltageC();
break; break;

@ -17,6 +17,7 @@ void setupEnergyMonitor();
// const char* test_client_cert = ""; //to verify the client // const char* test_client_cert = ""; //to verify the client
void setup() void setup()
{ {
// set LED pins
pinMode(PIN_RED, OUTPUT); pinMode(PIN_RED, OUTPUT);
pinMode(PIN_GREEN, OUTPUT); pinMode(PIN_GREEN, OUTPUT);
pinMode(PIN_BLUE, OUTPUT); pinMode(PIN_BLUE, OUTPUT);
@ -26,6 +27,7 @@ void setup()
delay(10000); delay(10000);
Serial.begin(9600); Serial.begin(9600);
// create data queue
eicDataQueue = xQueueCreate( 50, sizeof( xformerMonitorData ) ); eicDataQueue = xQueueCreate( 50, sizeof( xformerMonitorData ) );
if (eicDataQueue == 0) if (eicDataQueue == 0)
{ {
@ -240,7 +242,7 @@ void sendSensorDataOverMQTT(void *pvParameters)
delay(50); delay(50);
mqttClient.publish("xfmormermon/", buffer, n); mqttClient.publish("xfmormermon/", buffer, n);
} }
delay(1000); // <- fixes some issues with WiFi stability delay(100); // <- fixes some issues with WiFi stability
mqttClient.loop(); mqttClient.loop();
if (!mqttClient.connected()) if (!mqttClient.connected())
@ -278,15 +280,16 @@ void IRAM_ATTR ReadData(){
sensorData.timeInfo = gmtime(&now); sensorData.timeInfo = gmtime(&now);
sensorData.lineVoltage = eic.GetLineVoltage(); sensorData.lineVoltage = eic.GetLineVoltage();
sensorData.lineCurrent = eic.GetLineCurrent();
sensorData.neutralCurrent = eic.GetLineCurrentN(); sensorData.neutralCurrent = eic.GetLineCurrentN();
// sensorData.energy.exp = sensorData.power.factor = eic.GetPowerFactor();
xQueueSend(eicDataQueue, &sensorData, portMAX_DELAY); xQueueSend(eicDataQueue, &sensorData, portMAX_DELAY);
Serial.println("hello from ISR");
} }
void setColor(int R, int G, int B) { void setColor(int R, int G, int B) {
analogWrite(PIN_RED, R); analogWrite(PIN_RED, R);
analogWrite(PIN_GREEN, G); analogWrite(PIN_GREEN, G);
analogWrite(PIN_BLUE, B); analogWrite(PIN_BLUE, B);
Serial.println("hello from ISR");
} }
Loading…
Cancel
Save