diff --git a/esp-knx-ip-send.cpp b/esp-knx-ip-send.cpp index e3e74ea..32887ac 100644 --- a/esp-knx-ip-send.cpp +++ b/esp-knx-ip-send.cpp @@ -61,7 +61,7 @@ void ESPKNXIP::send(address_t const &receiver, knx_command_type_t ct, uint8_t da } buf[len - 1] = cs; #endif - + DEBUG_PRINT(F("Sending packet:")); for (int i = 0; i < len; ++i) { @@ -70,7 +70,11 @@ void ESPKNXIP::send(address_t const &receiver, knx_command_type_t ct, uint8_t da } DEBUG_PRINTLN(F("")); - udp.beginPacketMulticast(MULTICAST_IP, MULTICAST_PORT, WiFi.localIP()); + #ifdef ESP32 + udp.beginMulticastPacket(); + #else + udp.beginPacketMulticast(MULTICAST_IP, MULTICAST_PORT, WiFi.localIP()); + #endif udp.write(buf, len); udp.endPacket(); } @@ -125,7 +129,11 @@ void ESPKNXIP::send_2byte_float(address_t const &receiver, knx_command_type_t ct ++e; for (; v > 2047.0f; v /= 2) ++e; - long m = (long)round(v) & 0x7FF; + #ifdef ESP32 + long m = pow(round(v), 0x7FF); + #else + long m = round(v) & 0x7FF; + #endif short msb = (short) (e << 3 | m >> 8); if (val < 0.0f) msb |= 0x80; @@ -177,17 +185,3 @@ void ESPKNXIP::send_4byte_float(address_t const &receiver, knx_command_type_t ct uint8_t buf[] = {0x00, ((uint8_t *)&val)[3], ((uint8_t *)&val)[2], ((uint8_t *)&val)[1], ((uint8_t *)&val)[0]}; send(receiver, ct, 5, buf); } - -void ESPKNXIP::send_14byte_string(address_t const &receiver, knx_command_type_t ct, const char *val) -{ - // DPT16 strings are always 14 bytes long, however the data array is one larger due to the telegram structure. - // The first byte needs to be zero, string start after that. - uint8_t buf[15] = {0x00}; - int len = strlen(val); - if (len > 14) - { - len = 14; - } - memcpy(buf+1, val, len); - send(receiver, ct, 15, buf); -} diff --git a/esp-knx-ip.cpp b/esp-knx-ip.cpp index 1c118e1..4ef1782 100644 --- a/esp-knx-ip.cpp +++ b/esp-knx-ip.cpp @@ -27,15 +27,27 @@ void ESPKNXIP::load() restore_from_eeprom(); } +#ifdef ESP32 +void ESPKNXIP::start(WebServer *srv) +{ + server = srv; + __start(); +} +#else void ESPKNXIP::start(ESP8266WebServer *srv) { server = srv; __start(); } +#endif void ESPKNXIP::start() { - server = new ESP8266WebServer(80); + #ifdef ESP32 + server = new WebServer(80); + #else + server = new ESP8266WebServer(80); + #endif __start(); } @@ -82,7 +94,11 @@ void ESPKNXIP::__start() server->begin(); } - udp.beginMulticast(WiFi.localIP(), MULTICAST_IP, MULTICAST_PORT); + #ifdef ESP32 + udp.beginMulticast(MULTICAST_IP, MULTICAST_PORT); + #else + udp.beginMulticast(WiFi.localIP(), MULTICAST_IP, MULTICAST_PORT); + #endif } void ESPKNXIP::save_to_eeprom() diff --git a/esp-knx-ip.h b/esp-knx-ip.h index 147eb69..d8c3e1b 100644 --- a/esp-knx-ip.h +++ b/esp-knx-ip.h @@ -47,10 +47,18 @@ */ #include "Arduino.h" + +#ifdef ESP32 + #include + #include +#else + #include + #include +#endif + #include -#include #include -#include + #include "DPT.h" @@ -362,7 +370,11 @@ class ESPKNXIP { ESPKNXIP(); void load(); void start(); - void start(ESP8266WebServer *srv); + #ifdef ESP32 + void start(WebServer *srv); + #else + void start(ESP8266WebServer *srv); + #endif void loop(); void save_to_eeprom(); @@ -518,8 +530,13 @@ class ESPKNXIP { callback_assignment_id_t __callback_register_assignment(address_t address, callback_id_t id); void __callback_delete_assignment(callback_assignment_id_t id); + + #ifdef ESP32 + WebServer *server; + #else + ESP8266WebServer *server; + #endif - ESP8266WebServer *server; address_t physaddr; WiFiUDP udp;