dirty commit of start on tasks

pull/2/head
Andrew Woodlee 4 months ago
parent fa48cac2a0
commit 8af63a4790

@ -39,10 +39,10 @@ if wifiConfig.get("ssid") == None:
print(f"wifi object variable SSID not defined. Define it in the config.yml file at the root of the project.")
os._exit(1)
if wifiConfig["password"] == None:
if wifiConfig.get("password") == None:
print(f"wifi object variable password not defined. Define it in the config.yml file at the root of the project.")
os._exit(1)
if mqttConfig["server"] == None:
if mqttConfig.get("server") == None:
print(f"mqtt object variable server not defined. Define it in the config.yml file at the root of the project.")
os._exit(1)

@ -3,6 +3,10 @@
#include <ArduinoJson.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <FreeRTOSConfig.h>
#include <freertos/task.h>
#include <freertos/FreeRTOS.h>
#include <freertos/queue.h>
@ -102,4 +106,45 @@ struct tempSensors { // Structure declaration
tempSensors monitorTempSensors{cabinetTemp, oilTemp};
// StaticJsonDocument<256> dataStore[60];
StaticJsonDocument<256> dataStore[60];
time_t now;
unsigned short volts;
struct xformerMonitorData {
unsigned short volts;
double activeCurrent, passiveCurrent,
;
};
hw_timer_t *readEICTimer = NULL;
void IRAM_ATTR ReadData(){
StaticJsonDocument<256> doc;
JsonObject temp = doc.createNestedObject("temps");
// Obtain DS18B20 sensor data
monitorTempSensors.cabinet.requestTemperatures();
monitorTempSensors.oil.requestTemperatures();
// Get temp data in Celsius and Fahrenheit
float cabinetTemperatureC = monitorTempSensors.cabinet.getTempCByIndex(0);
float cabinetTemperatureF = monitorTempSensors.cabinet.getTempFByIndex(0);
// Get the current time and store it in a variable
time(&now);
struct tm* timeinfo = gmtime(&now);
char timeBuffer[32];
strftime(timeBuffer, sizeof(timeBuffer), "%FT%TZ", timeinfo);
// set {"time":"2021-05-04T13:13:04Z"}
doc["time"] = timeBuffer;
doc["meterStatus"] = volts;
doc["voltage"] = eic.GetLineVoltage();
temp["cabinet"] = monitorTempSensors.cabinet.getTempCByIndex(0);
temp["oil"] = monitorTempSensors.oil.getTempCByIndex(0);
}
TaskHandle_t Task1;
void readEICData( void * pvParameters );

@ -21,29 +21,27 @@ void ATM90E36_IC::begin(){
}
double ATM90E36_IC::GetLineVoltage()
{
double lv;
switch (ctLine)
{
case 'A':
return eic->GetLineVoltageA();
lv = eic->GetLineVoltageA();
case 'B':
return eic->GetLineVoltageB();
lv = eic->GetLineVoltageB();
case 'C':
return eic->GetLineVoltageC();
lv = eic->GetLineVoltageC();
break;
}
return lv;
}
double ATM90E36_IC::GetSysStatus()
{
return eic->GetSysStatus0();
}
double ATM90E36_IC::GetActivePower()
{
this->meterStatus = eic->GetActivePowerA();
return meterStatus;
}
double ATM90E36_IC::GetActivePower()
{
double ap;

@ -24,14 +24,7 @@ void setup()
configTime(timezone * 3600, dst * 0, "pool.ntp.org", "time.nist.gov");
// Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial)
{
}
delay(20000);
delay(1000);
#ifdef TM_MQTT_SSL
wifiClient.setCACert(root_ca);
@ -44,25 +37,17 @@ void setup()
setupMQTTClient();
#ifdef ATM90E26_EIC
ATM90E26_IC eic;
setupEnergyMonitor();
#else
/* Initialize the serial port to host */
/*
The ATM90E36 has to be setup via SPI.
SPI for the ESP32:
- CLK: 18
- MISO: 19
- MOSI: 23
- CS: 5
*/
SPI.begin(SCK, MISO, MOSI, SS);
delay(1000);
eic.begin();
#endif
xTaskCreatePinnedToCore(
readEICData, /* Function to implement the task */
"Task1", /* Name of the task */
10000, /* Stack size in words */
NULL, /* Task input parameter */
0, /* Priority of the task */
&Task1, /* Task handle. */
0); /* Core where the task should run */
}
void connect()
@ -129,40 +114,6 @@ void loop()
// mqttClient.publish("xfmormermon", "buffer");
// // publish a message roughly every second.
if (millis() - lastMillis > 1000)
{
monitorTempSensors.cabinet.requestTemperatures();
monitorTempSensors.oil.requestTemperatures();
unsigned short volts = 121.2;
float cabinetTemperatureC = monitorTempSensors.cabinet.getTempCByIndex(0);
float cabinetTemperatureF = monitorTempSensors.cabinet.getTempFByIndex(0);
StaticJsonDocument<256> doc;
// Get the current time and store it in a variable
time_t now;
time(&now);
struct tm* timeinfo = gmtime(&now);
char timeBuffer[32];
strftime(timeBuffer, sizeof(timeBuffer), "%FT%TZ", timeinfo);
// set {"time":"2021-05-04T13:13:04Z"}
doc["time"] = timeBuffer;
doc["meterStatus"] = eic.GetLineVoltage();
// doc["meterStatus"] = 40;
doc["voltage"] = volts;
JsonObject temp = doc.createNestedObject("temps");
temp["cabinet"] = 40;
temp["oil"] = 70;
// temp["cabinet"] = monitorTempSensors.cabinet.getTempCByIndex(0);
// temp["oil"] = monitorTempSensors.oil.getTempCByIndex(0);
// dataStore->add(doc);
char mqttBuffer[256];
serializeJson(doc, mqttBuffer);
mqttClient.publish("xfomermon", mqttBuffer);
}
Serial.println("Sleeping 10s");
delay(10000);
}
@ -181,4 +132,45 @@ void setupMQTTClient()
// depending on which monitor is used, the function will have call different functions
void setupEnergyMonitor()
{
#ifdef ATM90E26_EIC
ATM90E26_IC eic;
#else
/* Initialize the serial port to host */
/*
The ATM90E36 has to be setup via SPI.
SPI for the ESP32:
- CLK: 18
- MISO: 19
- MOSI: 23
- CS: 5
*/
SPI.begin(SCK, MISO, MOSI, SS);
delay(1000);
eic.begin();
#endif
}
//readEICData: reads the EIC and inserts data into queue
void readEICData( void * pvParameters ){
Serial.print("Task1 running on core ");
Serial.println(xPortGetCoreID());
// Attach interrupt
readEICTimer = timerBegin(0, 80, true);
timerAttachInterrupt(readEICTimer, &ReadData, true);
timerAlarmWrite(readEICTimer, 1000000, true);
timerAlarmEnable(readEICTimer); //Just Enable
for(;;){
// char mqttBuffer[256];
// serializeJson(doc, mqttBuffer);
}
}
Loading…
Cancel
Save