Skip to content
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
28 changes: 11 additions & 17 deletions esp-knx-ip-send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
20 changes: 18 additions & 2 deletions esp-knx-ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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()
Expand Down
25 changes: 21 additions & 4 deletions esp-knx-ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@
*/

#include "Arduino.h"

#ifdef ESP32
#include <WiFi.h>
#include <WebServer.h>
#else
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#endif

#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ESP8266WebServer.h>


#include "DPT.h"

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down