Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/network led #11

Open
wants to merge 5 commits into
base: v1dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ This module provides the network functionality for the OpenKNX stack.
| RP2040 | WiFi | Integrated | KNX_IP_WIFI | |
| RP2040 | LAN | Integrated | KNX_IP_LAN | |


| Define | Default | Description | Note |
|----------------|----------|-----------------------|-----------------------------------------|
| OPENKNX_IP_LED | info2Led | used LED for IP state | set to 0 to disable the IP LED feature |

## IP LED

If OPENKNX_IP_LED is defined, the LED is representing the state of the network.
Possible values for OPENKNX_IP_LED: info1Led, info2Led, info3Led. Recommended value: info2Led

| State | LED | RGB-LED | Note |
|-------------------------------|---------------|--------------------|----------------------------------------|
| WLAN configuration missing | Fast flashing | Red fast flashing | Only for HW with WLA |
| No connection to the network | Off | Red | |
| No IP adress | Slow flashing | Yellow | |
| IP adress assigned | On | Green | |

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hier wäre noch schön wenn das LED-Bild erklärt würde (welche Farbe/Zustand was bedeutet)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

und ich wäre auch noch für das passende namensschema:

OPENKNX_NETWORK_INFOLED

außerdem bin ich kein freund davon coden namen zu verwenden da es eine spätere anpassung verhindert.

wäre also eher für
-D OPENKNX_NETWORK_INFOLED=2
für info2led.

evtl bekommen wir sogar noch eine activity anzeige hin. zumindest wenn es ein IP Device ist und ein telegramm per ip eingeht.

## OTA

Mit dem Netzwerkmodul wird eine OTA (Over the air) Update Funktion der Firmware ermöglicht.
Expand Down
65 changes: 63 additions & 2 deletions src/NetworkModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,70 @@ void NetworkModule::checkLinkStatus()
{
if (!delayCheckMillis(_lastLinkCheck, 500)) return;

// Get current link state
bool newLinkState = connected();
// Get current network state
bool establishedState = established();
bool newLinkState;
if (establishedState)
newLinkState = true;
else
newLinkState = connected();
#ifdef OPENKNX_LED_IP && OPENKNX_LED_IP != 0
// update LED's
if (newLinkState && established())
{
if(_ipLedState != 1)
{
#ifdef OPENKNX_SERIALLED_ENABLE
openknx.OPENKNX_LED_IP.setColor(OPENKNX_SERIALLED_COLOR_GREEN);
#endif
openknx.OPENKNX_LED_IP.on();
_ipLedState = 1;
}
}
else if (newLinkState)
{
if(_ipLedState != 2)
{
#ifdef OPENKNX_SERIALLED_ENABLE
openknx.OPENKNX_LED_IP.setColor(OPENKNX_SERIALLED_COLOR_YELLOW);
openknx.OPENKNX_LED_IP.on();
#else
openknx.OPENKNX_LED_IP.blinking(1000);
#endif

_ipLedState = 2;
}
}
else
{
#ifdef KNX_IP_WIFI
if (_wifiSSID[0] == 0 || _wifiPassphrase[0])
{
if(_ipLedState != 4)
{
#ifdef OPENKNX_SERIALLED_ENABLE
openknx.OPENKNX_LED_IP.setColor(OPENKNX_SERIALLED_COLOR_RED);
openknx.OPENKNX_LED_IP.blinking(500);
#else
openknx.OPENKNX_LED_IP.blinking(500);
#endif
_ipLedState = 4;
}
}
else
#endif
if(_ipLedState != 3)
{
#ifdef OPENKNX_SERIALLED_ENABLE
openknx.OPENKNX_LED_IP.setColor(OPENKNX_SERIALLED_COLOR_RED);
openknx.OPENKNX_LED_IP.on();
#else
openknx.OPENKNX_LED_IP.off();
#endif
_ipLedState = 3;
}
}
#endif
// got link
if (newLinkState && !_currentLinkState)
{
Expand Down
7 changes: 7 additions & 0 deletions src/NetworkModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#include "UsbExchangeModule.h"
#endif

#if !defined(OPENKNX_LED_IP) && defined(INFO2_LED_PIN) && KNX_SERVICE_FAMILY != 0x02 // IP-Router uses own LED implementation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SERVICE_FAMILY ist kein geeignetes Unterscheidungsmerkmal für den Router.
Man sollte das auch an dieser Stelle nicht unterscheiden müssen / können.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ich bin gegen eine default Zuweisung.
Wenn man das haben will, soll man das in seiner HardwareConfig bewusst auswählen.
Und wenn es unbedingtr einen default geben muss, dann muss es eine Möglichkeit geben den Default zu verhindern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ich bin auch gegen default. wenn es jemand braucht, soll er es zuweisen. vor allem weil auch nur die progled pflicht und empfohlen infoled (infoled1) ist.

#define OPENKNX_LED_IP info2Led
#endif

typedef std::function<void(bool)> NetworkChangeCallback;

class NetworkModule : public OpenKNX::Module
Expand Down Expand Up @@ -93,6 +97,9 @@ class NetworkModule : public OpenKNX::Module
bool _useMDNS = false;
bool _otaAllowed = false;
bool _otaHandle = false;
#ifdef OPENKNX_LED_IP
uint8_t _ipLedState = 0;
#endif
#ifdef ARDUINO_ARCH_ESP32
const uint16_t _otaPort = 3232;
const char *_otaPortString = "3232";
Expand Down