Skip to content

Commit

Permalink
app+transport: WiFi* => Network* for ESP32
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Jul 14, 2024
1 parent 6eabfb0 commit f724432
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions examples/PingClient/PingClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <ESP8266WiFi.h>
#include <WiFiClientSecureBearSSL.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <NetworkClientSecure.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#endif
#include <esp8266ndn.h>

Expand Down Expand Up @@ -42,7 +42,7 @@ setup() {
BearSSL::WiFiClientSecure fchSocketClient;
fchSocketClient.setInsecure();
#elif defined(ARDUINO_ARCH_ESP32)
WiFiClientSecure fchSocketClient;
NetworkClientSecure fchSocketClient;
fchSocketClient.setInsecure();
#endif
auto fchResponse = esp8266ndn::fchQuery(fchSocketClient);
Expand Down
4 changes: 2 additions & 2 deletions src/app/autoconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace esp8266ndn {

FchResponse
fchQuery(::WiFiClient& client, String serviceUri) {
fchQuery(ESP8266NDN_NetworkClient& client, String serviceUri) {
FchResponse res;
HTTPClient http;
http.begin(client, serviceUri);
Expand All @@ -31,7 +31,7 @@ fchQuery(::WiFiClient& client, String serviceUri) {
body.trim();
LOG(serviceUri << F(" body: ") << body);

if (!WiFi.hostByName(body.c_str(), res.ip)) {
if (!ESP8266NDN_Network.hostByName(body.c_str(), res.ip)) {
LOG(F("DNS error"));
return res;
}
Expand Down
15 changes: 12 additions & 3 deletions src/app/autoconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
#include <IPAddress.h>
#include <WString.h>

class WiFiClient;
#if defined(ARDUINO_ARCH_ESP8266)
#define ESP8266NDN_Network WiFi
#define ESP8266NDN_NetworkClient WiFiClient
#elif defined(ARDUINO_ARCH_ESP32)
#define ESP8266NDN_Network Network
#define ESP8266NDN_NetworkClient NetworkClient
#endif

class ESP8266NDN_NetworkClient;

namespace esp8266ndn {

Expand All @@ -17,11 +25,12 @@ struct FchResponse {

/**
* @brief Query NDN-FCH service to find a nearby NDN router.
* @param client @c WiFiClient or @c WiFiClientSecure instance.
* @param client @c WiFiClient or @c WiFiClientSecure instance on ESP8266;
* @c NetworkClient or @c NetworkClientSecure instance on ESP32.
* @param serviceUri NDN-FCH service base URI.
*/
FchResponse
fchQuery(::WiFiClient& client, String serviceUri = "https://fch.ndn.today/");
fchQuery(ESP8266NDN_NetworkClient& client, String serviceUri = "https://fch.ndn.today/");

} // namespace esp8266ndn

Expand Down
8 changes: 6 additions & 2 deletions src/transport/udp-transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
#if defined(ARDUINO_ARCH_ESP8266)
// cause WiFiUdp.h to use ESP8266WiFi instead of Arduino WiFi library
#include <ESP8266WiFi.h>
#endif
#include <WiFiUdp.h>
#define ESP8266NDN_NetworkUDP WiFiUDP
#elif defined(ARDUINO_ARCH_ESP32)
#include <NetworkUdp.h>
#define ESP8266NDN_NetworkUDP NetworkUDP
#endif

namespace esp8266ndn {

Expand Down Expand Up @@ -93,7 +97,7 @@ class UdpTransport : public virtual ndnph::Transport {
size_t m_bufcap = 0;
std::unique_ptr<uint8_t[]> m_ownBuf;

WiFiUDP m_udp;
ESP8266NDN_NetworkUDP m_udp;
#if LWIP_IPV6
using EndpointIdHelper = ndnph::port_transport_socket::Ipv6EndpointIdHelper<4>;
#else
Expand Down

0 comments on commit f724432

Please sign in to comment.