From c67894f4a1cfc1ed1362b2dffe6fbf537b4c4ba0 Mon Sep 17 00:00:00 2001 From: Andrew Woodlee Date: Fri, 22 Mar 2024 22:52:23 -0500 Subject: [PATCH] updates to library, comments, etc --- include/transformerMonitor.h | 15 +++++++++------ lib/transformerEnergyMonitor/ATM90E36_IC.cpp | 4 +++- src/transformerMonitor.cpp | 9 ++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/transformerMonitor.h b/include/transformerMonitor.h index dc7a3c7..c68f239 100644 --- a/include/transformerMonitor.h +++ b/include/transformerMonitor.h @@ -70,7 +70,7 @@ ATM90E26_IC eic; // extract the ATM90E36 CT LINE from its macro #ifdef 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'; #endif #include @@ -80,12 +80,12 @@ ATM90E36_IC eic(ctLine, ic); #endif -// we are using the ESP32's MAC address to provide a unique ID -String client_id = "xformermon-"; +// we are using the transformer's name to provide a unique ID +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 cabinetTempBus = 9; @@ -104,9 +104,9 @@ OneWire cabinetTempBusOneWire(cabinetTempBus); DallasTemperature oilTempSensor(&oilTempBusOneWire); DallasTemperature cabinetTempSensor(&cabinetTempBusOneWire); +// temp sensor objects tempSensors monitorTempSensors{oilTempSensor, cabinetTempSensor}; -StaticJsonDocument<256> dataStore[60]; time_t now; // Data structs for queue @@ -138,7 +138,7 @@ struct xformerMonitorData { // Global to be used in ISR xformerMonitorData sensorData; -// Variables for tasks +// Variables for tasks and queue TaskHandle_t taskReadEIC; TaskHandle_t taskSendData; @@ -161,6 +161,9 @@ void IRAM_ATTR ReadData(); #define PIN_BLUE 21 // GPIO21 // LED color Function +// Red - 0 to 255 +// Green - 0 to 255 +// Blue - 0 to 255 void setColor(int R, int G, int B); diff --git a/lib/transformerEnergyMonitor/ATM90E36_IC.cpp b/lib/transformerEnergyMonitor/ATM90E36_IC.cpp index 2df5076..66f5834 100644 --- a/lib/transformerEnergyMonitor/ATM90E36_IC.cpp +++ b/lib/transformerEnergyMonitor/ATM90E36_IC.cpp @@ -17,7 +17,7 @@ } 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() { @@ -26,8 +26,10 @@ void ATM90E36_IC::begin(){ { case 'A': lv = eic->GetLineVoltageA(); + break; case 'B': lv = eic->GetLineVoltageB(); + break; case 'C': lv = eic->GetLineVoltageC(); break; diff --git a/src/transformerMonitor.cpp b/src/transformerMonitor.cpp index 6078297..8e7b6c9 100644 --- a/src/transformerMonitor.cpp +++ b/src/transformerMonitor.cpp @@ -17,6 +17,7 @@ void setupEnergyMonitor(); // const char* test_client_cert = ""; //to verify the client void setup() { + // set LED pins pinMode(PIN_RED, OUTPUT); pinMode(PIN_GREEN, OUTPUT); pinMode(PIN_BLUE, OUTPUT); @@ -26,6 +27,7 @@ void setup() delay(10000); Serial.begin(9600); + // create data queue eicDataQueue = xQueueCreate( 50, sizeof( xformerMonitorData ) ); if (eicDataQueue == 0) { @@ -240,7 +242,7 @@ void sendSensorDataOverMQTT(void *pvParameters) delay(50); mqttClient.publish("xfmormermon/", buffer, n); } - delay(1000); // <- fixes some issues with WiFi stability + delay(100); // <- fixes some issues with WiFi stability mqttClient.loop(); if (!mqttClient.connected()) @@ -278,15 +280,16 @@ void IRAM_ATTR ReadData(){ sensorData.timeInfo = gmtime(&now); sensorData.lineVoltage = eic.GetLineVoltage(); + sensorData.lineCurrent = eic.GetLineCurrent(); sensorData.neutralCurrent = eic.GetLineCurrentN(); - // sensorData.energy.exp = + sensorData.power.factor = eic.GetPowerFactor(); xQueueSend(eicDataQueue, &sensorData, portMAX_DELAY); + Serial.println("hello from ISR"); } void setColor(int R, int G, int B) { analogWrite(PIN_RED, R); analogWrite(PIN_GREEN, G); analogWrite(PIN_BLUE, B); - Serial.println("hello from ISR"); } \ No newline at end of file