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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Current status is alpha quality, actively developed. AP STATION mode (ie wifi cl
## Open Source Components

* [FreeRTOS](http://www.freertos.org/) V10.2.0
* [lwIP](http://lwip.wikia.com/wiki/LwIP_Wiki) v2.0.3, with [some modifications](https://github.com/ourairquality/lwip/).
* [lwIP](http://lwip.wikia.com/wiki/LwIP_Wiki) v2.2.0, with [some modifications](https://github.com/ourairquality/lwip/).
* [newlib](https://github.com/ourairquality/newlib) v3.0.0, with patches for xtensa support and locking stubs for thread-safe operation on FreeRTOS.

For details of how third party libraries are integrated, [see the wiki page](https://github.com/SuperHouse/esp-open-rtos/wiki/Third-Party-Libraries).
Expand Down
2 changes: 1 addition & 1 deletion examples/access_point/access_point.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void user_init(void)
*/
static void telnetTask(void *pvParameters)
{
ip_addr_t first_client_ip;
ip4_addr_t first_client_ip;
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
dhcpserver_start(&first_client_ip, 4);

Expand Down
2 changes: 1 addition & 1 deletion examples/esphttpd/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void wifiInit() {
};
sdk_wifi_softap_set_config(&ap_config);

ip_addr_t first_client_ip;
ip4_addr_t first_client_ip;
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
dhcpserver_start(&first_client_ip, 4);
dhcpserver_set_dns(&ap_ip.ip);
Expand Down
1 change: 1 addition & 0 deletions examples/mdns-search/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!local.mk
7 changes: 7 additions & 0 deletions examples/mdns-search/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define configUSE_TRACE_FACILITY 1
#define configGENERATE_RUN_TIME_STATS 1
#define portGET_RUN_TIME_COUNTER_VALUE() (RTC.COUNTER)
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() {}

/* Use the defaults for everything else */
#include_next<FreeRTOSConfig.h>
11 changes: 11 additions & 0 deletions examples/mdns-search/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Makefile for mDNS search example
PROGRAM=mdns-search
EXTRA_COMPONENTS=extras/dhcpserver extras/wificfg

# For the mDNS responder included with lwip:
EXTRA_CFLAGS += -DLWIP_MDNS_RESPONDER=1 -DLWIP_NUM_NETIF_CLIENT_DATA=1 -DLWIP_NETIF_EXT_STATUS_CALLBACK=1 -DLWIP_MDNS_SEARCH=1

# Avoid writing the wifi state to flash when using wificfg.
EXTRA_CFLAGS += -DWIFI_PARAM_SAVE=0

include ../../common.mk
1 change: 1 addition & 0 deletions examples/mdns-search/local.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FLASH_SIZE ?= 32
160 changes: 160 additions & 0 deletions examples/mdns-search/mdsn-search.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* Example mDNS service search.
*
* Copyright (C) 2019 OurAirQuality.org
*
* Licensed under the Apache License, Version 2.0, January 2004 (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/
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS WITH THE SOFTWARE.
*
*/

#include <string.h>
#include <ctype.h>

#include <espressif/esp_common.h>
#include <espressif/user_interface.h>
#include <esp/uart.h>
#include <FreeRTOS.h>
#include <task.h>

#include "lwip/sockets.h"
#include "lwip/apps/mdns.h"
#include "lwip/prot/dns.h"
#include "lwip/ip6.h"
#include "lwip/ip6_addr.h"

#include "wificfg/wificfg.h"

#if !LWIP_MDNS_SEARCH
#error "The LWIP_MDNS_SEARCH feature must be set."
#endif

#define SEARCH_SERVICE "_http"
#define SEARCH_PROTO DNSSD_PROTO_TCP

static void print_domain(const u8_t *src)
{
u8_t i;

while (*src) {
u8_t label_len = *src;
src++;
for (i = 0; i < label_len; i++) {
putchar(src[i]);
}
src += label_len;
printf(".");
}
}

void result_fn(struct mdns_answer *answer, const char *varpart,
int varlen, int flags, void *arg)
{
size_t i;

printf("Domain ");
print_domain(answer->info.domain->name);
printf(" ");

switch (answer->info.type) {
case DNS_RRTYPE_PTR:
printf("PTR ");
print_domain((u8_t *)varpart);
printf("\n");
break;

case DNS_RRTYPE_SRV:
/* Priority, weight, port fields. */
printf("SRV ");
print_domain((u8_t *)varpart + 6);
printf(" port %u\n", ((u16_t)varpart[4] << 8) | varpart[5]);
break;

case DNS_RRTYPE_TXT:
printf("TXT \"%s\"\n", varpart);
break;

case DNS_RRTYPE_A:
if (varlen == sizeof(ip4_addr_t)) {
ip4_addr_t addr;
char buf[16];
char *p;
SMEMCPY(&addr, varpart, sizeof(ip4_addr_t));
p = ip4addr_ntoa_r(&addr, buf, sizeof(buf));
if (p) printf("A %s\n", p);
}
break;

#if LWIP_IPV6
case DNS_RRTYPE_AAAA:
if (varlen == sizeof(ip6_addr_p_t)) {
ip6_addr_p_t addrp;
ip6_addr_t addr;
char buf[64];
char *p;
SMEMCPY(addrp.addr, varpart, sizeof(ip6_addr_p_t));
ip6_addr_copy_from_packed(addr, addrp);
p = ip6addr_ntoa_r(&addr, buf, sizeof(buf));
if (p) printf("AAAA %s\n", p);
}
break;
#endif

default:
printf("Unexpected type %u class %u, ans %p, part %p, len %d, flags %x, arg %p\n", answer->info.type, answer->info.klass, answer, varpart, varlen, flags, arg);
for (i = 0; i < varlen; i++)
printf(" %02x", varpart[i]);
printf("\n");
}
}

static void mdns_search_task(void *pvParameters)
{
err_t err;
u8_t request_id;
struct netif *station_netif = sdk_system_get_netif(STATION_IF);

if (station_netif == NULL) {
vTaskDelete(NULL);
}

for (;;) {
printf("Starting mDNS search for %s : ", SEARCH_SERVICE);
LOCK_TCPIP_CORE();
err = mdns_search_service(NULL, SEARCH_SERVICE,
SEARCH_PROTO,
station_netif,
result_fn, NULL,
&request_id);
UNLOCK_TCPIP_CORE();
printf("request_id %d, error %d\n", request_id, err);

vTaskDelay(10000 / portTICK_PERIOD_MS);
printf("Stopping mDNS search\n");

LOCK_TCPIP_CORE();
mdns_search_stop(request_id);
UNLOCK_TCPIP_CORE();
}
}

void user_init(void)
{
uart_set_baud(0, 115200);
printf("SDK version:%s\n", sdk_system_get_sdk_version());

wificfg_init(80, NULL);

xTaskCreate(&mdns_search_task, "mDNS search", 384, NULL, 1, NULL);
}
11 changes: 5 additions & 6 deletions examples/tcp_non_blocking/tcp_non_blocking.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static void nonBlockingTCP(void *pvParameters)
struct netbuf *netbuf = NULL; // To store incoming Data
struct netconn *nc_in = NULL; // To accept incoming netconn
//
char buf[50];
char buf[64];
char* buffer;
uint16_t len_buf;

Expand All @@ -138,10 +138,9 @@ static void nonBlockingTCP(void *pvParameters)
ip_addr_t client_addr; //Address port
uint16_t client_port; //Client port
netconn_peer(nc_in, &client_addr, &client_port);
snprintf(buf, sizeof(buf), "Your address is %d.%d.%d.%d:%u.\r\n",
ip4_addr1(&client_addr), ip4_addr2(&client_addr),
ip4_addr3(&client_addr), ip4_addr4(&client_addr),
client_port);
char ip_addr_buf[48];
ipaddr_ntoa_r(&client_addr, ip_addr_buf, sizeof(ip_addr_buf));
snprintf(buf, sizeof(buf), "Your address is %s:%u.\r\n", ip_addr_buf, client_port);
netconn_write(nc_in, buf, strlen(buf), NETCONN_COPY);
}
else if(events.nc->state != NETCONN_LISTEN) // If netconn is the client and receive data
Expand Down Expand Up @@ -191,7 +190,7 @@ void user_init(void)
};
sdk_wifi_softap_set_config(&ap_config);

ip_addr_t first_client_ip;
ip4_addr_t first_client_ip;
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
dhcpserver_start(&first_client_ip, 4);
printf("DHCP started\n");
Expand Down
16 changes: 12 additions & 4 deletions extras/wificfg/wificfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,14 @@ static bool host_is_name(const char *host)
}


#if LWIP_MDNS_RESPONDER
static void mdns_srv_txt(struct mdns_service *service, void *txt_userdata)
{
err_t res = mdns_resp_add_service_txtitem(service, "path=/", 6);
LWIP_ERROR("mdns add service txt failed\n", (res == ERR_OK), return);
}
#endif

/*
* The http server uses a single thread to service all requests, one request at
* a time, to keep peak resource usage to a minimum. Keeping connections open
Expand Down Expand Up @@ -1745,16 +1753,16 @@ static void server_task(void *pvParameters)
LOCK_TCPIP_CORE();
if (wifi_sta_mdns && station_netif) {
LOCK_TCPIP_CORE();
mdns_resp_add_netif(station_netif, hostname, 120);
mdns_resp_add_netif(station_netif, hostname);
mdns_resp_add_service(station_netif, hostname, "_http",
DNSSD_PROTO_TCP, 80, 3600, NULL, NULL);
DNSSD_PROTO_TCP, 80, mdns_srv_txt, NULL);
UNLOCK_TCPIP_CORE();
}
if (wifi_ap_mdns && softap_netif) {
LOCK_TCPIP_CORE();
mdns_resp_add_netif(softap_netif, hostname, 120);
mdns_resp_add_netif(softap_netif, hostname);
mdns_resp_add_service(softap_netif, hostname, "_http",
DNSSD_PROTO_TCP, 80, 3600, NULL, NULL);
DNSSD_PROTO_TCP, 80, mdns_srv_txt, NULL);
UNLOCK_TCPIP_CORE();
}
UNLOCK_TCPIP_CORE();
Expand Down
6 changes: 5 additions & 1 deletion lwip/esp_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ low_level_init(struct netif *netif)
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP | NETIF_FLAG_MLD6;

#if LWIP_ACD
netif->acd_list = NULL;
#endif /* LWIP_ACD */

/* Do whatever else is needed to initialize interface. */
}

Expand Down Expand Up @@ -384,7 +388,7 @@ ethernetif_init(struct netif *netif)
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output()
* You can instead declare your own function and call etharp_output()
* from it if you have to do some checks before sending (e.g. if link
* is available...) */
#if LWIP_IPV4
Expand Down
Loading