Skip to content

Commit

Permalink
Implement and publish mDNS on esp32 (#3452)
Browse files Browse the repository at this point in the history
* esp32 mdns impl

* fix review comments

* use format in spec
  • Loading branch information
gjc13 authored and pull[bot] committed Dec 9, 2020
1 parent f6c5642 commit 1151148
Show file tree
Hide file tree
Showing 20 changed files with 531 additions and 23 deletions.
7 changes: 7 additions & 0 deletions examples/temperature-measurement-app/esp32/main/wifi-echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ const char * TAG = "wifi-echo-demo";

static DeviceCallbacks EchoCallbacks;
RendezvousDeviceDelegate * rendezvousDelegate = nullptr;
namespace chip {
namespace DeviceLayer {
namespace Internal {
const uint64_t TestDeviceId = kLocalNodeId; // For chip::DeviceLayer::GetDeviceId
} // namespace Internal
} // namespace DeviceLayer
} // namespace chip

namespace {

Expand Down
10 changes: 5 additions & 5 deletions examples/wifi-echo/server/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
**/
#include "DeviceCallbacks.h"

#include "CHIPDeviceManager.h"
#include "Globals.h"
#include "LEDWidget.h"
#include "WiFiWidget.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include <lib/protocols/mdns/Publisher.h>
#include <support/CodeUtils.h>

extern "C" {
Expand All @@ -41,11 +44,6 @@ using namespace ::chip::Inet;
using namespace ::chip::System;
using namespace ::chip::DeviceLayer;

// In wifi-echo.cpp
extern LEDWidget statusLED1;
extern LEDWidget statusLED2;
extern WiFiWidget wifiLED;

uint32_t identifyTimerCount;
constexpr uint32_t kIdentifyTimerDelayMS = 250;

Expand Down Expand Up @@ -96,6 +94,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
{
ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
wifiLED.Set(true);
publisher.StartPublishDevice();
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
Expand All @@ -105,6 +104,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
ESP_LOGI(TAG, "IPv6 Server ready...");
publisher.StartPublishDevice();
}
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
{
Expand Down
4 changes: 1 addition & 3 deletions examples/wifi-echo/server/esp32/main/EchoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <transport/raw/UDP.h>

#include "DataModelHandler.h"
#include "Globals.h"
#include "LEDWidget.h"

static const char * TAG = "echo_server";
Expand All @@ -54,9 +55,6 @@ using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::Transport;

extern const NodeId kLocalNodeId = 12344321;
extern LEDWidget statusLED1; // In wifi-echo.cpp

namespace {

/**
Expand Down
25 changes: 25 additions & 0 deletions examples/wifi-echo/server/esp32/main/Globals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "Globals.h"

LEDWidget statusLED1;
LEDWidget statusLED2;
BluetoothWidget bluetoothLED;
WiFiWidget wifiLED;
chip::Protocols::Mdns::Publisher publisher;
const chip::NodeId kLocalNodeId = 12344321;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "RendezvousDeviceDelegate.h"

#include "BluetoothWidget.h"
#include "Globals.h"
#include "esp_log.h"
#include <platform/ConfigurationManager.h>
#include <support/CHIPMem.h>
Expand All @@ -29,8 +30,6 @@ using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::System;

extern BluetoothWidget bluetoothLED;
extern NodeId kLocalNodeId;
extern void PairingComplete(SecurePairingSession * pairing);

static const char * TAG = "rendezvous-devicedelegate";
Expand Down
31 changes: 31 additions & 0 deletions examples/wifi-echo/server/esp32/main/include/Globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "BluetoothWidget.h"
#include "LEDWidget.h"
#include "WiFiWidget.h"
#include "lib/protocols/mdns/Publisher.h"
#include "transport/raw/MessageHeader.h"

extern LEDWidget statusLED1;
extern LEDWidget statusLED2;
extern BluetoothWidget bluetoothLED;
extern WiFiWidget wifiLED;
extern chip::Protocols::Mdns::Publisher publisher;
extern const chip::NodeId kLocalNodeId;
17 changes: 12 additions & 5 deletions examples/wifi-echo/server/esp32/main/wifi-echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "DataModelHandler.h"
#include "DeviceCallbacks.h"
#include "Display.h"
#include "Globals.h"
#include "LEDWidget.h"
#include "ListScreen.h"
#include "QRCodeScreen.h"
Expand All @@ -44,6 +45,7 @@
#include <vector>

#include <crypto/CHIPCryptoPAL.h>
#include <lib/protocols/mdns/Publisher.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
Expand Down Expand Up @@ -83,18 +85,21 @@ extern void startServer();
// Used to indicate that an IP address has been added to the QRCode
#define EXAMPLE_VENDOR_TAG_IP 1

LEDWidget statusLED1;
LEDWidget statusLED2;
BluetoothWidget bluetoothLED;
WiFiWidget wifiLED;

extern void PairingComplete(SecurePairingSession * pairing);

const char * TAG = "wifi-echo-demo";

static DeviceCallbacks EchoCallbacks;
RendezvousDeviceDelegate * rendezvousDelegate = nullptr;

namespace chip {
namespace DeviceLayer {
namespace Internal {
const uint64_t TestDeviceId = kLocalNodeId; // For chip::DeviceLayer::GetDeviceId
} // namespace Internal
} // namespace DeviceLayer
} // namespace chip

namespace {

#if CONFIG_DEVICE_TYPE_M5STACK
Expand Down Expand Up @@ -523,6 +528,8 @@ extern "C" void app_main()
}

SetupPretendDevices();
publisher.Init();
publisher.StopPublishDevice();

statusLED1.Init(STATUS_LED_GPIO_NUM);
// Our second LED doesn't map to any physical LEDs so far, just to virtual
Expand Down
5 changes: 5 additions & 0 deletions src/lib/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import("//build_overrides/chip.gni")
import("${chip_root}/src/platform/device.gni")

config("includes") {
include_dirs = [ "." ]
Expand All @@ -34,6 +35,10 @@ static_library("lib") {
"${chip_root}/src/transport",
]

if (chip_enable_mdns) {
public_deps += [ "${chip_root}/src/lib/protocols/mdns" ]
}

cflags = [ "-Wconversion" ]

output_name = "libCHIP"
Expand Down
32 changes: 32 additions & 0 deletions src/lib/protocols/mdns/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/chip.gni")

source_set("platform_header") {
sources = [ "platform/Mdns.h" ]
}

static_library("mdns") {
public_deps = [
":platform_header",
"${chip_root}/src/lib/support",
"${chip_root}/src/platform",
]

sources = [
"Publisher.cpp",
"Publisher.h",
]
}
Loading

0 comments on commit 1151148

Please sign in to comment.