Skip to content

Commit

Permalink
implemented zeroconf advertising
Browse files Browse the repository at this point in the history
  • Loading branch information
d03n3rfr1tz3 committed Apr 24, 2024
1 parent 04ff7e2 commit 23a0c54
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/hardware/bluetoothctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,19 @@ bool BluetoothHandler::disconnect(void) {
void BluetoothHandler::discovered(BTAdvertisedDevice* device) {
if (!device->haveName()) return;

esp_bd_addr_t* address = device->getAddress().getNative();
// check for supported names
std::string name = device->getName();
if (name.find("Ditoo") == std::string::npos &&
name.find("Pixoo") == std::string::npos &&
name.find("Timebox") == std::string::npos &&
name.find("Tivoo") == std::string::npos) return;

// pass it into zeroconf
MDNS.addServiceTxt("_divoom_esp32", "_tcp", "device_mac", device->getAddress().toString().c_str());
MDNS.addServiceTxt("_divoom_esp32", "_tcp", "device_name", name.c_str());

// pass it into the input handlers for an advertise announcement
BaseInput::advertise((const uint8_t*)address, name.c_str(), name.size());
BaseInput::advertise((const uint8_t*)device->getAddress().getNative(), name.c_str(), name.size());
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/hardware/bluetoothctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "Arduino.h"
#include "BluetoothSerial.h"
#include "ESPmDNS.h"

class BluetoothHandler {
public:
Expand Down
3 changes: 3 additions & 0 deletions src/hardware/wifictl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ void WifiHandler::connected(WiFiEvent_t event, WiFiEventInfo_t info) {
WiFi.setAutoReconnect(true);
WiFi.setHostname(WIFI_NAME);
WiFi.persistent(true);

MDNS.begin(WIFI_NAME);
MDNS.addService("_divoom_esp32", "_tcp", TCP_PORT);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/hardware/wifictl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "config.h"

#include "Arduino.h"
#include "ESPmDNS.h"
#include "WiFi.h"

class WifiHandler {
Expand Down

0 comments on commit 23a0c54

Please sign in to comment.