Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/ota.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Requirements
Implementation Overview
~~~~~~~~~~~~~~~~~~~~~~~

Updates with a web browser are implemented using ``HTTPUpdateServer`` class together with ``WebServer`` and ``LEAmDNS`` classes. The following code is required to get it work:
Updates with a web browser are implemented using ``HTTPUpdateServer`` class together with ``WebServer`` and ``LEAmDNS`` or ``SimpleMDNS`` classes. The following code is required to get it work:

setup()

Expand Down
2 changes: 1 addition & 1 deletion docs/wifi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Please note that WiFi on the Pico W is a work-in-progress and there are some imp

* FreeRTOS is supported only on core 0 and from within ``setup`` and ``loop``, not tasks, due to the requirement for a very different LWIP implementation. PRs always appreciated!

* LEAmDNS (``MDNS``) is not supported in FreeRTOS due to internal IRQ-time memory allocations.
* LEAmDNS (``MDNS``) is not supported in FreeRTOS due to internal IRQ-time memory allocations. Instead, use the SimpleMDNS library ( ``#include <SimpleMDNS.h>`` ) which has no such allocations.

The WiFi library borrows much work from the `ESP8266 Arduino Core <https://github.com/esp8266/Arduino>`__ , especially the ``WiFiClient`` and ``WiFiServer`` classes.

Expand Down
85 changes: 46 additions & 39 deletions include/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,57 @@ extern unsigned long __lwip_rand(void);
// Common settings used in most of the pico_w examples
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)

#define NO_SYS 1
#define LWIP_SOCKET 0
#define MEM_LIBC_MALLOC 0
#define NO_SYS 1
#define LWIP_SOCKET 0
#define MEM_LIBC_MALLOC 0

#define MEM_ALIGNMENT 4
#define MEM_SIZE (__LWIP_MEMMULT * 16384)
#define MEMP_NUM_TCP_SEG (32)
#define MEMP_NUM_ARP_QUEUE (10)
#define PBUF_POOL_SIZE (__LWIP_MEMMULT > 1 ? 32 : 24)
#define LWIP_ARP 2
#define LWIP_ETHERNET 1
#define LWIP_ICMP 1
#define LWIP_RAW 1
#define TCP_WND (8 * TCP_MSS)
#define TCP_MSS 1460
#define TCP_SND_BUF (8 * TCP_MSS)
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_LINK_CALLBACK 1
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_NETCONN 0
#define LWIP_STATS 0
#define LWIP_STATS_DISPLAY 0
#define MEM_STATS 0
#define SYS_STATS 0
#define MEMP_STATS 0
#define LINK_STATS 0
#define LWIP_CHKSUM_ALGORITHM 0
#define LWIP_DHCP 1
#define LWIP_IPV4 1
#define LWIP_TCP 1
#define LWIP_UDP 1
#define LWIP_DNS 1
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#define DHCP_DOES_ARP_CHECK 0
#define LWIP_DHCP_DOES_ACD_CHECK 0
#define MEM_ALIGNMENT 4
#define MEM_SIZE (__LWIP_MEMMULT * 16384)
#define MEMP_NUM_TCP_SEG (32)
#define MEMP_NUM_ARP_QUEUE (10)
//#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + 4)
#define PBUF_POOL_SIZE (__LWIP_MEMMULT > 1 ? 32 : 24)
#define LWIP_ARP 5
#define LWIP_ETHERNET 1
#define LWIP_ICMP 1
#define LWIP_RAW 1
#define TCP_WND (8 * TCP_MSS)
#define TCP_MSS 1460
#define TCP_SND_BUF (8 * TCP_MSS)
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_LINK_CALLBACK 1
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_NUM_NETIF_CLIENT_DATA 5
#define LWIP_NETCONN 0
#define LWIP_STATS 0
#define LWIP_STATS_DISPLAY 0
#define MEM_STATS 0
#define SYS_STATS 0
#define MEMP_STATS 0
#define LINK_STATS 0
#define LWIP_CHKSUM_ALGORITHM 0
#define LWIP_DHCP 1
#define LWIP_IPV4 1
#define LWIP_TCP 1
#define LWIP_UDP 1
#define LWIP_DNS 1
#define LWIP_DNS_SUPPORT_MDNS_QUERIES 1
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#define DHCP_DOES_ARP_CHECK 0
#define LWIP_DHCP_DOES_ACD_CHECK 0
#define LWIP_IGMP 1
#define LWIP_MDNS_RESPONDER 1
#define MDNS_MAX_SERVICES 4

// See #1285
#define MEMP_NUM_UDP_PCB (__LWIP_MEMMULT * 6)
#define MEMP_NUM_TCP_PCB (__LWIP_MEMMULT * 5)
#define MEMP_NUM_UDP_PCB (__LWIP_MEMMULT * 7)
#define MEMP_NUM_TCP_PCB (__LWIP_MEMMULT * 5)

#if LWIP_IPV6
#define LWIP_IPV6_DHCP6 1
#define LWIP_IPV6_DHCP6 1
#define LWIP_IPV6_MLD 1
#endif

// NTP
Expand Down
Binary file modified lib/rp2040/libipv4-big.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-bt-big.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-bt.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-ipv6-big.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-ipv6-bt-big.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-ipv6-bt.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4-ipv6.a
Binary file not shown.
Binary file modified lib/rp2040/libipv4.a
Binary file not shown.
Binary file modified lib/rp2040/libpico.a
Binary file not shown.
Binary file modified lib/rp2350-riscv/libipv4-big.a
Binary file not shown.
Binary file modified lib/rp2350-riscv/libipv4-ipv6-big.a
Binary file not shown.
Binary file modified lib/rp2350-riscv/libipv4-ipv6.a
Binary file not shown.
Binary file modified lib/rp2350-riscv/libipv4.a
Binary file not shown.
Binary file modified lib/rp2350-riscv/libpico.a
Binary file not shown.
Binary file modified lib/rp2350/libipv4-big.a
Binary file not shown.
Binary file modified lib/rp2350/libipv4-ipv6-big.a
Binary file not shown.
Binary file modified lib/rp2350/libipv4-ipv6.a
Binary file not shown.
Binary file modified lib/rp2350/libipv4.a
Binary file not shown.
Binary file modified lib/rp2350/libpico.a
Binary file not shown.
2 changes: 1 addition & 1 deletion libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <WiFi.h>
#include <LEAmDNS.h>
#include <SimpleMDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

Expand Down
2 changes: 1 addition & 1 deletion libraries/ArduinoOTA/examples/OTALeds/OTALeds.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <WiFi.h>
#include <LEAmDNS.h>
#include <SimpleMDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

Expand Down
2 changes: 1 addition & 1 deletion libraries/ArduinoOTA/examples/SignedOTA/SignedOTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


#include <WiFi.h>
#include <LEAmDNS.h>
#include <SimpleMDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

Expand Down
5 changes: 1 addition & 4 deletions libraries/ArduinoOTA/src/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@

#include <lwip/udp.h>
#include <include/UdpContext.h>

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_MDNS)
#include <LEAmDNS.h>
#endif
#include <SimpleMDNS.h>

#ifdef DEBUG_RP2040_CORE
#ifdef DEBUG_RP2040_PORT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <LEAmDNS.h>
#include <SimpleMDNS.h>
#include <HTTPUpdateServer.h>

#ifndef STASSID
Expand Down
5 changes: 5 additions & 0 deletions libraries/LEAmDNS/src/LEAmDNS.h
Original file line number Diff line number Diff line change
Expand Up @@ -1348,3 +1348,8 @@ class MDNSResponder {
} // namespace esp8266

#include <ESP8266mDNS.h>

#define __LEAMDNS_H 1
#ifdef __SIMPLEMDNS_H
#error SimpleMDNS and LeaMDNS both included. Only one allowed at a time.
#endif
21 changes: 21 additions & 0 deletions libraries/SimpleMDNS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SimpleMDNS Library for Arduino-Pico

This library implements a very basic MDNS responder (xxx.local) for the
Pico to enable things like local name resolution and Arduino IDE OTA
connections. It uses the LWIP-provided simplified MDNS application.

Unlike LEAmDNS, this library only supports very simple configurations.
They should be sufficient for OTA and name resolution and simple web
servers, but for more complicated needs please use LEAmDNS.

The benefit of this simplicity is that it is low code and has no runtime
memory allocations. This means it can be run under FreeRTOS (which LEAmDNS
does not presently support).

This should be a drop-in replacement, just replace `#include <LEAmDNS.h>`
with `#include <SimpleMDNS.h>`.

Be sure to `MDNS.begin()` after enabling WiFi/Ethernet.begin().

-Earle F. Philhower, III
<[email protected]>
23 changes: 23 additions & 0 deletions libraries/SimpleMDNS/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#######################################
# Syntax Coloring Map
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

SimpleMDNS KEYWORD1
MDNS KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
addService KEYWORD2
enableArduino KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

10 changes: 10 additions & 0 deletions libraries/SimpleMDNS/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=SimpleMDNS
version=1.0
author=Earle F. Philhower, III <[email protected]>
maintainer=Earle F. Philhower, III <[email protected]>
sentence=Creates a simple mDNS responder using LWIP features
paragraph=Creates a mDNS responder to ensure host domain uniqueness in local networks and to allow for mDNS service discovery and announcement.
category=Communication
url=https://github.com/earlephilhower/arduino-pico
architectures=rp2040
dot_a_linkage=true
96 changes: 96 additions & 0 deletions libraries/SimpleMDNS/src/SimpleMDNS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
SimpleMDNS for Rasperry Pi Pico
Implements a basic MDNS responder (xxx.local)

Copyright (c) 2024 Earle F. Philhower, III <[email protected]>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <Arduino.h>
#include "SimpleMDNS.h"
#include <LwipEthernet.h>
#include <lwip/apps/mdns.h>

void SimpleMDNS::begin(const char *hostname, unsigned int ttl) {
if (_running) {
return;
}
mdns_resp_init();
struct netif *n = netif_list;
while (n) {
mdns_resp_add_netif(n, hostname);
n = n->next;
}
__setStateChangeCallback(_statusCB);
_hostname = strdup(hostname);
_running = true;
}

void SimpleMDNS::enableArduino(unsigned int port, bool passwd) {
if (!_running) {
return;
}
struct netif *n = netif_list;
while (n) {
mdns_resp_add_service(n, _hostname, "_arduino", DNSSD_PROTO_TCP, port, _arduinoGetTxt, (void *)passwd);
n = n->next;
}
}

void SimpleMDNS::addService(const char *service, const char *proto, unsigned int port) {
if (!_running) {
return;
}
char s[128];
snprintf(s, sizeof(s), "_%s", service);
s[sizeof(s) - 1] = 0;
struct netif *n = netif_list;
while (n) {
mdns_resp_add_service(n, _hostname, s, !strcasecmp("tcp", proto) ? DNSSD_PROTO_TCP : DNSSD_PROTO_UDP, port, _nullGetTxt, nullptr);
n = n->next;
}
}

void SimpleMDNS::update() {
/* No-op */
}

void SimpleMDNS::end() {
/* No-op */
}

void SimpleMDNS::_statusCB(struct netif *netif) {
mdns_resp_netif_settings_changed(netif);
}

void SimpleMDNS::_addServiceTxt(struct mdns_service *service, const char *str) {
mdns_resp_add_service_txtitem(service, str, strlen(str));
}

void SimpleMDNS::_arduinoGetTxt(struct mdns_service *service, void *txt_userdata) {
_addServiceTxt(service, "tcp_check=no");
_addServiceTxt(service, "ssh_upload=no");
_addServiceTxt(service, "board=" ARDUINO_VARIANT);
_addServiceTxt(service, (bool)txt_userdata ? "auth_upload=yes" : "auth_upload=no");
}

void SimpleMDNS::_nullGetTxt(struct mdns_service *service, void *txt_userdata) {
/* nop */
}

const char *SimpleMDNS::_hostname = nullptr;

SimpleMDNS MDNS;
51 changes: 51 additions & 0 deletions libraries/SimpleMDNS/src/SimpleMDNS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
SimpleMDNS for Rasperry Pi Pico
Implements a basic MDNS responder (xxx.local)

Copyright (c) 2024 Earle F. Philhower, III <[email protected]>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once
#include <Arduino.h>

class SimpleMDNS {

public:
void begin(const char *hostname, unsigned int ttl = 60);
void enableArduino(unsigned int port, bool passwd = false);
void addService(const char *service, const char *proto, unsigned int port);

// No-ops here
void end();
void update();

private:
static void _statusCB(struct netif *netif);
static void _addServiceTxt(struct mdns_service *service, const char *str);
static void _arduinoGetTxt(struct mdns_service *service, void *txt_userdata);
static void _nullGetTxt(struct mdns_service *service, void *txt_userdata);

bool _running = false;
static const char *_hostname;
};

extern SimpleMDNS MDNS;

#define __SIMPLEMDNS_H 1
#ifdef __LEAMDNS_H
#error SimpleMDNS and LeaMDNS both included. Only one allowed at a time.
#endif
5 changes: 5 additions & 0 deletions libraries/lwIP_Ethernet/src/LwipEthernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,8 @@ void lwipPollingPeriod(int ms) {
_pollingPeriod = ms;
}
}

std::function<void(struct netif *)> _scb;
void __setStateChangeCallback(std::function<void(struct netif *)> s) {
_scb = s;
}
3 changes: 3 additions & 0 deletions libraries/lwIP_Ethernet/src/LwipEthernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ int hostByName(const char *aHostname, IPAddress &aResult, int timeout_ms = 5000)

// Set the LWIP polling time (default 50ms). Lower polling times == lower latency but higher CPU usage
void lwipPollingPeriod(int ms);

// Sets the global netif state change callback
void __setStateChangeCallback(std::function<void(struct netif *)> s);
Loading
Loading