-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: some code cleanup, improved WiFi reliability
- Loading branch information
1 parent
384b677
commit 1b0d59f
Showing
11 changed files
with
518 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,107 @@ | ||
# knx_platformio | ||
KNX platform for Platform IO | ||
# KNX PlatformIO Library | ||
|
||
I use this as a starting point for KaeNX applications I develop | ||
A comprehensive platform for building KNX applications for ESP8266/ESP32 devices. This library provides a robust foundation for developing KNX-enabled IoT devices with features like OTA updates, network management, and monitoring capabilities. | ||
|
||
## Compiler options | ||
## Features | ||
|
||
- **Multi-Platform Support**: Compatible with ESP8266 and ESP32 | ||
- **Network Management**: | ||
- WiFi configuration via WiFiManager | ||
- MDNS support | ||
- Telnet debugging | ||
- HTTP server capabilities | ||
- **KNX Integration**: | ||
- Full KNX protocol support | ||
- Programming mode handling | ||
- Cyclic updates | ||
- **System Features**: | ||
- OTA (Over-The-Air) updates | ||
- Heartbeat monitoring | ||
- Time synchronization (NTP) | ||
- Serial debugging | ||
- Telnet monitoring | ||
|
||
## Installation | ||
|
||
## Diagram | ||
1. Add this library to your PlatformIO project: | ||
```ini | ||
lib_deps = | ||
https://github.com/ErikMeinders/knx_platformio.git | ||
``` | ||
|
||
 | ||
2. Include the main header in your code: | ||
```cpp | ||
#include "knxp_platformio.h" | ||
``` | ||
|
||
## Configuration | ||
|
||
### Build Flags | ||
|
||
The library supports various build flags to customize functionality: | ||
|
||
- `NO_WIFI`: Disable WiFi functionality | ||
- `NO_NTP`: Disable NTP time synchronization | ||
- `NO_TELNET`: Disable Telnet debugging | ||
- `NO_KNX`: Disable KNX functionality | ||
- `NO_MDNS`: Disable MDNS support | ||
- `NO_OTA`: Disable OTA updates | ||
- `NO_HTTP`: Disable HTTP server | ||
- `NO_HEARTBEAT`: Disable heartbeat monitoring | ||
|
||
### Platform-Specific Settings | ||
|
||
#### ESP8266 | ||
```ini | ||
[env:esp8266] | ||
platform = espressif8266 | ||
board = d1 | ||
``` | ||
|
||
#### ESP32 | ||
```ini | ||
[env:esp32] | ||
platform = espressif32 | ||
board = wemos_d1_mini32 | ||
``` | ||
|
||
## Usage | ||
|
||
1. Create a new KNX application class: | ||
```cpp | ||
class MyKnxApp : public KnxApp { | ||
public: | ||
void setup() override { | ||
// Your setup code | ||
} | ||
|
||
void loop() override { | ||
// Your loop code | ||
} | ||
|
||
void status() override { | ||
// Your status update code | ||
} | ||
}; | ||
``` | ||
2. Initialize the application: | ||
```cpp | ||
MyKnxApp myApp; | ||
``` | ||
|
||
## Dependencies | ||
|
||
- [ArduinoLog](https://github.com/thijse/Arduino-Log) | ||
- [Profiler](https://github.com/erikmeinders/profiler) | ||
- [TelnetStream](https://github.com/jandrassy/TelnetStream) | ||
- [KNX](https://github.com/thelsing/knx) | ||
- [WiFiManager](https://github.com/tzapu/WiFiManager) | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! Please feel free to submit a Pull Request. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the LICENSE file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,103 @@ | ||
#ifndef NETWORK_H | ||
#define NETWORK_H | ||
#ifndef KNXP_NETWORK_H | ||
#define KNXP_NETWORK_H | ||
|
||
#include <Arduino.h> | ||
#include <knxp_espcompat.h> | ||
#include <WiFiManager.h> | ||
#include <TelnetStream.h> | ||
|
||
/** | ||
* @file knxp_network.h | ||
* @brief Network management functionality for KNX PlatformIO | ||
* | ||
* This module handles WiFi connectivity, Telnet debugging, and mDNS services. | ||
* It supports both station and access point modes, with automatic fallback | ||
* and connection monitoring. | ||
*/ | ||
|
||
/** | ||
* @brief Get current network ready status | ||
* @return true if network is ready, false otherwise | ||
*/ | ||
bool isNetworkReady(); | ||
|
||
/** | ||
* @brief Initialize and start WiFi connection | ||
* | ||
* @param hostname Device hostname for network identification | ||
* | ||
* @details | ||
* - In normal mode, attempts to connect to configured WiFi network | ||
* - In NETWORK_ONDEMAND mode, only starts when PROG button is pressed | ||
* - Supports fallback to AP mode for configuration | ||
* - Automatically restarts device on connection timeout | ||
* | ||
* Usage example: | ||
* @code | ||
* startWiFi("my-device"); | ||
* @endcode | ||
*/ | ||
void startWiFi(const char *hostname); | ||
|
||
#include <TelnetStream.h> | ||
|
||
void startWiFi(const char *Hostname); | ||
#ifndef NO_TELNET | ||
/** | ||
* @brief Initialize and start Telnet server | ||
* | ||
* @details | ||
* - Enables remote debugging and monitoring via Telnet | ||
* - When STDIO_TELNET is defined, redirects standard I/O to Telnet | ||
* - Requires active network connection | ||
* | ||
* Usage example: | ||
* @code | ||
* if (isNetworkReady()) startTelnet(); | ||
* @endcode | ||
*/ | ||
void startTelnet(); | ||
#endif | ||
void startMDNS(const char *Hostname); | ||
|
||
/** | ||
* @brief Initialize and start mDNS responder | ||
* | ||
* @param hostname Device hostname for mDNS resolution | ||
* | ||
* @details | ||
* - Sets up mDNS for local network device discovery | ||
* - Advertises HTTP service on port 80 | ||
* - Requires active network connection | ||
* - Device will be accessible as hostname.local | ||
* | ||
* Usage example: | ||
* @code | ||
* if (isNetworkReady()) startMDNS("my-device"); | ||
* @endcode | ||
*/ | ||
void startMDNS(const char *hostname); | ||
|
||
/** | ||
* @brief Process network-related tasks | ||
* | ||
* @details | ||
* - Monitors WiFi connection status | ||
* - Attempts automatic reconnection when needed | ||
* - Should be called regularly from the main loop | ||
* | ||
* Usage example: | ||
* @code | ||
* void loop() { | ||
* processNetwork(); | ||
* // other loop tasks | ||
* } | ||
* @endcode | ||
*/ | ||
void processNetwork(); | ||
|
||
#ifndef NO_HTTP | ||
extern WebServer httpServer; | ||
/** | ||
* @brief Global HTTP server instance | ||
* @details Available when NO_HTTP is not defined | ||
*/ | ||
extern WebServer httpServer; | ||
#endif | ||
|
||
#endif | ||
#endif // KNXP_NETWORK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,3 @@ extern Stream *stdOut; | |
#endif | ||
|
||
#define DELAY delay(STD_DELAY) | ||
|
||
extern bool networkReady; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.