Skip to content

Commit

Permalink
add dongle led
Browse files Browse the repository at this point in the history
  • Loading branch information
softwarecrash committed Sep 20, 2023
1 parent 8ad002a commit 44adf88
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/PI_Serial/PI_Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ bool PI_Serial::loop()
previousTime = millis();
requestCallback();
}
connection = (connectionCounter < 10) ? true : false;
}
return true;
}
Expand Down Expand Up @@ -209,6 +210,7 @@ String PI_Serial::requestData(String command)
commandBuffer.remove(0, strlen(startChar)); // remove the start char ( for Pi30 and ^Dxxx for Pi18

requestOK++;
connectionCounter = 0;
}
else if (getCHK(commandBuffer.substring(0, commandBuffer.length() - 1)) + 1 == commandBuffer[commandBuffer.length() - 1] &&
getCHK(commandBuffer.substring(0, commandBuffer.length() - 1)) + 1 != 0 && commandBuffer[commandBuffer.length() - 1] != 0 &&
Expand All @@ -221,6 +223,7 @@ String PI_Serial::requestData(String command)
commandBuffer.remove(0, strlen(startChar)); // remove the start char ( for Pi30 and ^Dxxx for Pi18

requestOK++;
connectionCounter = 0;
}
else if (commandBuffer.indexOf("NAK", strlen(startChar)) > 0) // catch NAK without crc
{
Expand All @@ -243,6 +246,7 @@ String PI_Serial::requestData(String command)
PI_DEBUG_WEBLN("<");

requestFail++;
connectionCounter++;
commandBuffer = "ERCRC";
}
char debugBuff[128];
Expand Down
2 changes: 2 additions & 0 deletions src/PI_Serial/PI_Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PI_Serial
const char *delimiter = " ";
bool requestStaticData = true;
byte protocol = NoD;
bool connection = false;

struct
{
Expand Down Expand Up @@ -128,6 +129,7 @@ class PI_Serial

long long int requestOK = 0;
long long int requestFail = 0;
long long int connectionCounter = 0;

byte qexCounter = 0;

Expand Down
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ bool resetCounter(bool count)
void setup()
{
analogWrite(LED_PIN, 0);
analogWrite(LED_COM, 0);
analogWrite(LED_SRV, 0);
analogWrite(LED_NET, 0);

resetCounter(true);
#ifdef DEBUG
DEBUG_BEGIN(DEBUG_BAUD); // Debugging towards UART1
Expand Down Expand Up @@ -427,6 +431,9 @@ void setup()
mqtttimer = (settings.data.mqttRefresh * 1000) * (-1);
}
analogWrite(LED_PIN, 255);
analogWrite(LED_COM, 255);
analogWrite(LED_SRV, 255);
analogWrite(LED_NET, 255);
resetCounter(false);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#endif

#define LED_PIN 02 //D4 with the LED on Wemos D1 Mini
#define LED_COM 5
#define LED_SRV 0
#define LED_NET 4

#define DEBUG_WEBLN(...) WebSerial.println(__VA_ARGS__)
#define DEBUG_WEBF(...) WebSerial.printf(__VA_ARGS__)
Expand Down
13 changes: 8 additions & 5 deletions src/status-LED.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ void notificationLED()
ledState = 4;
else if (!mqttclient.connected() && strcmp(settings.data.mqttServer, "") != 0)
ledState = 3;
//else if (strcmp(bms.get.chargeDischargeStatus, "offline") == 0)
// else if (!bms.getState())
// ledState = 2;
// else if (WiFi.status() == WL_CONNECTED && mqttclient.connected() && strcmp(bms.get.chargeDischargeStatus, "offline") != 0)
else if (WiFi.status() == WL_CONNECTED && mqttclient.connected() != 0)
else if (mppClient.connection)
ledState = 2;
else if (WiFi.status() == WL_CONNECTED && mqttclient.connected() && mppClient.connection)
ledState = 1;


digitalWrite(LED_COM, mppClient.connection);
digitalWrite(LED_SRV, mqttclient.connected());
digitalWrite(LED_NET, (WiFi.status() == WL_CONNECTED) ? true : false);
}

if (ledState > 0)
Expand Down

0 comments on commit 44adf88

Please sign in to comment.