KNX: Updated ESP-KNX-IP Lib to use only WIFIUDP Lib

This commit is contained in:
ascillato 2018-10-24 14:20:34 -03:00
parent b9fda004d2
commit 00c99e512b
3 changed files with 1 additions and 45 deletions

View File

@ -77,13 +77,10 @@ void ESPKNXIP::send(address_t const &receiver, knx_command_type_t ct, uint8_t da
DEBUG_PRINTLN(F("")); DEBUG_PRINTLN(F(""));
#endif #endif
#ifdef USE_ASYNC_UDP
udp.writeTo(buf, len, MULTICAST_IP, MULTICAST_PORT);
#else
udp.beginPacketMulticast(MULTICAST_IP, MULTICAST_PORT, WiFi.localIP()); udp.beginPacketMulticast(MULTICAST_IP, MULTICAST_PORT, WiFi.localIP());
udp.write(buf, len); udp.write(buf, len);
udp.endPacket(); udp.endPacket();
#endif
} }
void ESPKNXIP::send_1bit(address_t const &receiver, knx_command_type_t ct, uint8_t bit) void ESPKNXIP::send_1bit(address_t const &receiver, knx_command_type_t ct, uint8_t bit)

View File

@ -95,13 +95,7 @@ void ESPKNXIP::__start()
#endif #endif
server->begin(); server->begin();
} }
#ifdef USE_ASYNC_UDP
udp.listenMulticast(MULTICAST_IP, MULTICAST_PORT);
udp.onPacket([this](AsyncUDPPacket &packet) { __loop_knx(packet); });
#else
udp.beginMulticast(WiFi.localIP(), MULTICAST_IP, MULTICAST_PORT); udp.beginMulticast(WiFi.localIP(), MULTICAST_IP, MULTICAST_PORT);
#endif
} }
void ESPKNXIP::save_to_eeprom() void ESPKNXIP::save_to_eeprom()
@ -516,9 +510,7 @@ feedback_id_t ESPKNXIP::feedback_register_action(String name, feedback_action_fp
void ESPKNXIP::loop() void ESPKNXIP::loop()
{ {
#ifndef USE_ASYNC_UDP
__loop_knx(); __loop_knx();
#endif
if (server != nullptr) if (server != nullptr)
{ {
__loop_webserver(); __loop_webserver();
@ -530,15 +522,9 @@ void ESPKNXIP::__loop_webserver()
server->handleClient(); server->handleClient();
} }
#ifdef USE_ASYNC_UDP
void ESPKNXIP::__loop_knx(AsyncUDPPacket &packet)
{
size_t read = packet.length();
#else
void ESPKNXIP::__loop_knx() void ESPKNXIP::__loop_knx()
{ {
int read = udp.parsePacket(); int read = udp.parsePacket();
#endif
if (!read) if (!read)
{ {
@ -548,23 +534,15 @@ void ESPKNXIP::__loop_knx()
DEBUG_PRINT(F("LEN: ")); DEBUG_PRINT(F("LEN: "));
DEBUG_PRINTLN(read); DEBUG_PRINTLN(read);
#ifdef USE_ASYNC_UDP
uint8_t *buf = packet.data();
#else
uint8_t buf[read]; uint8_t buf[read];
udp.read(buf, read); udp.read(buf, read);
udp.flush(); udp.flush();
#endif
DEBUG_PRINT(F("Got packet:")); DEBUG_PRINT(F("Got packet:"));
#ifdef ESP_KNX_DEBUG #ifdef ESP_KNX_DEBUG
#ifdef USE_ASYNC_UDP
for (size_t i = 0; i < read; ++i)
#else
for (int i = 0; i < read; ++i) for (int i = 0; i < read; ++i)
#endif
{ {
DEBUG_PRINT(F(" 0x")); DEBUG_PRINT(F(" 0x"));

View File

@ -45,18 +45,7 @@
#include "Arduino.h" #include "Arduino.h"
#include <EEPROM.h> #include <EEPROM.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0)
#ifndef ARDUINO_ESP8266_RELEASE_2_3_0
//#define USE_ASYNC_UDP // UDP WIFI Library Selection for Multicast
#endif
#ifdef USE_ASYNC_UDP
#include <ESPAsyncUDP.h>
#else
#include <WiFiUdp.h> #include <WiFiUdp.h>
#endif
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include "DPT.h" #include "DPT.h"
@ -529,11 +518,7 @@ class ESPKNXIP {
private: private:
void __start(); void __start();
#ifdef USE_ASYNC_UDP
void __loop_knx(AsyncUDPPacket &packet);
#else
void __loop_knx(); void __loop_knx();
#endif
// Webserver functions // Webserver functions
void __loop_webserver(); void __loop_webserver();
@ -569,11 +554,7 @@ class ESPKNXIP {
ESP8266WebServer *server; ESP8266WebServer *server;
address_t physaddr; address_t physaddr;
#ifdef USE_ASYNC_UDP
AsyncUDP udp;
#else
WiFiUDP udp; WiFiUDP udp;
#endif
callback_assignment_id_t registered_callback_assignments; callback_assignment_id_t registered_callback_assignments;
callback_assignment_id_t free_callback_assignment_slots; callback_assignment_id_t free_callback_assignment_slots;