Merge branch 'master' into master
This commit is contained in:
commit
2a0150cbbb
191 changed files with 11189 additions and 11970 deletions
|
|
@ -1,11 +1,11 @@
|
|||
/* Very basic example showing usage of access point mode and the DHCP server.
|
||||
|
||||
The ESP in the example runs a telnet server on 172.16.0.1 (port 23) that
|
||||
outputs some status information if you connect to it, then closes
|
||||
the connection.
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
/**
|
||||
* Very basic example showing usage of access point mode and the DHCP server.
|
||||
* The ESP in the example runs a telnet server on 172.16.0.1 (port 23) that
|
||||
* outputs some status information if you connect to it, then closes
|
||||
* the connection.
|
||||
*
|
||||
* This example code is in the public domain.
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
#include <espressif/esp_common.h>
|
||||
|
|
@ -36,62 +36,55 @@ void user_init(void)
|
|||
IP4_ADDR(&ap_ip.netmask, 255, 255, 0, 0);
|
||||
sdk_wifi_set_ip_info(1, &ap_ip);
|
||||
|
||||
struct sdk_softap_config ap_config = {
|
||||
.ssid = AP_SSID,
|
||||
.ssid_hidden = 0,
|
||||
.channel = 3,
|
||||
.ssid_len = strlen(AP_SSID),
|
||||
.authmode = AUTH_WPA_WPA2_PSK,
|
||||
.password = AP_PSK,
|
||||
.max_connection = 3,
|
||||
.beacon_interval = 100,
|
||||
};
|
||||
struct sdk_softap_config ap_config = { .ssid = AP_SSID, .ssid_hidden = 0, .channel = 3, .ssid_len = strlen(AP_SSID), .authmode =
|
||||
AUTH_WPA_WPA2_PSK, .password = AP_PSK, .max_connection = 3, .beacon_interval = 100, };
|
||||
sdk_wifi_softap_set_config(&ap_config);
|
||||
|
||||
ip_addr_t first_client_ip;
|
||||
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
||||
dhcpserver_start(&first_client_ip, 4);
|
||||
|
||||
xTaskCreate(telnetTask, "telnetTask", 512, NULL, 2, NULL);
|
||||
}
|
||||
|
||||
/* Telnet task listens on port 23, returns some status information and then closes
|
||||
the connection if you connect to it.
|
||||
*/
|
||||
the connection if you connect to it.
|
||||
*/
|
||||
static void telnetTask(void *pvParameters)
|
||||
{
|
||||
struct netconn *nc = netconn_new (NETCONN_TCP);
|
||||
if(!nc) {
|
||||
printf("Status monitor: Failed to allocate socket.\r\n");
|
||||
return;
|
||||
}
|
||||
netconn_bind(nc, IP_ADDR_ANY, TELNET_PORT);
|
||||
netconn_listen(nc);
|
||||
ip_addr_t first_client_ip;
|
||||
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
||||
dhcpserver_start(&first_client_ip, 4);
|
||||
|
||||
while(1) {
|
||||
struct netconn *client = NULL;
|
||||
err_t err = netconn_accept(nc, &client);
|
||||
|
||||
if ( err != ERR_OK ) {
|
||||
if(client)
|
||||
netconn_delete(client);
|
||||
continue;
|
||||
struct netconn *nc = netconn_new(NETCONN_TCP);
|
||||
if (!nc)
|
||||
{
|
||||
printf("Status monitor: Failed to allocate socket.\r\n");
|
||||
return;
|
||||
}
|
||||
netconn_bind(nc, IP_ANY_TYPE, TELNET_PORT);
|
||||
netconn_listen(nc);
|
||||
|
||||
ip_addr_t client_addr;
|
||||
uint16_t port_ignore;
|
||||
netconn_peer(client, &client_addr, &port_ignore);
|
||||
while (1)
|
||||
{
|
||||
struct netconn *client = NULL;
|
||||
err_t err = netconn_accept(nc, &client);
|
||||
|
||||
char buf[80];
|
||||
snprintf(buf, sizeof(buf), "Uptime %d seconds\r\n",
|
||||
xTaskGetTickCount()*portTICK_PERIOD_MS/1000);
|
||||
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
|
||||
snprintf(buf, sizeof(buf), "Free heap %d bytes\r\n", (int)xPortGetFreeHeapSize());
|
||||
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
|
||||
snprintf(buf, sizeof(buf), "Your address is %d.%d.%d.%d\r\n\r\n",
|
||||
ip4_addr1(&client_addr), ip4_addr2(&client_addr),
|
||||
ip4_addr3(&client_addr), ip4_addr4(&client_addr));
|
||||
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
|
||||
netconn_delete(client);
|
||||
}
|
||||
if (err != ERR_OK)
|
||||
{
|
||||
if (client)
|
||||
netconn_delete(client);
|
||||
continue;
|
||||
}
|
||||
|
||||
ip_addr_t client_addr;
|
||||
uint16_t port_ignore;
|
||||
netconn_peer(client, &client_addr, &port_ignore);
|
||||
|
||||
char buf[80];
|
||||
snprintf(buf, sizeof(buf), "Uptime %d seconds\r\n", xTaskGetTickCount() * portTICK_PERIOD_MS / 1000);
|
||||
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
|
||||
snprintf(buf, sizeof(buf), "Free heap %d bytes\r\n", (int) xPortGetFreeHeapSize());
|
||||
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
|
||||
char abuf[40];
|
||||
snprintf(buf, sizeof(buf), "Your address is %s\r\n\r\n", ipaddr_ntoa_r(&client_addr, abuf, sizeof(abuf)));
|
||||
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
|
||||
netconn_delete(client);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@ const int freq_frc2 = 10;
|
|||
static volatile uint32_t frc1_count;
|
||||
static volatile uint32_t frc2_count;
|
||||
|
||||
void frc1_interrupt_handler(void)
|
||||
void frc1_interrupt_handler(void *arg)
|
||||
{
|
||||
frc1_count++;
|
||||
gpio_toggle(gpio_frc1);
|
||||
}
|
||||
|
||||
void frc2_interrupt_handler(void)
|
||||
void frc2_interrupt_handler(void *arg)
|
||||
{
|
||||
/* FRC2 needs the match register updated on each timer interrupt */
|
||||
timer_set_frequency(FRC2, freq_frc2);
|
||||
|
|
@ -47,8 +47,8 @@ void user_init(void)
|
|||
timer_set_run(FRC2, false);
|
||||
|
||||
/* set up ISRs */
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC2, frc2_interrupt_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler, NULL);
|
||||
_xt_isr_attach(INUM_TIMER_FRC2, frc2_interrupt_handler, NULL);
|
||||
|
||||
/* configure timer frequencies */
|
||||
timer_set_frequency(FRC1, freq_frc1);
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ void timerRegTask(void *pvParameters)
|
|||
}
|
||||
}
|
||||
|
||||
IRAM void frc1_handler(void)
|
||||
IRAM void frc1_handler(void *arg)
|
||||
{
|
||||
frc1_handler_call_count++;
|
||||
frc1_last_count_val = TIMER(0).COUNT;
|
||||
|
|
@ -106,7 +106,7 @@ IRAM void frc1_handler(void)
|
|||
//TIMER_FRC1_MATCH_REG = frc1_last_count_val + 0x100000;
|
||||
}
|
||||
|
||||
void frc2_handler(void)
|
||||
void frc2_handler(void *arg)
|
||||
{
|
||||
frc2_handler_call_count++;
|
||||
frc2_last_count_val = TIMER(1).COUNT;
|
||||
|
|
@ -127,9 +127,9 @@ void user_init(void)
|
|||
TIMER(1).LOAD = VAL2FIELD(TIMER_CTRL_CLKDIV, TIMER_CLKDIV_256);
|
||||
|
||||
DPORT.INT_ENABLE |= DPORT_INT_ENABLE_TIMER0 | DPORT_INT_ENABLE_TIMER1;
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_handler, NULL);
|
||||
_xt_isr_unmask(1<<INUM_TIMER_FRC1);
|
||||
_xt_isr_attach(INUM_TIMER_FRC2, frc2_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC2, frc2_handler, NULL);
|
||||
_xt_isr_unmask(1<<INUM_TIMER_FRC2);
|
||||
|
||||
TIMER(0).CTRL |= TIMER_CTRL_RUN;
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ static volatile bool frc1_ran;
|
|||
static volatile bool frc1_finished;
|
||||
static volatile char frc1_buf[80];
|
||||
|
||||
static void frc1_interrupt_handler(void)
|
||||
static void frc1_interrupt_handler(void *arg)
|
||||
{
|
||||
frc1_ran = true;
|
||||
timer_set_run(FRC1, false);
|
||||
|
|
@ -250,7 +250,7 @@ static void test_isr()
|
|||
printf("Testing behaviour inside ISRs...\r\n");
|
||||
timer_set_interrupts(FRC1, false);
|
||||
timer_set_run(FRC1, false);
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler, NULL);
|
||||
timer_set_frequency(FRC1, 1000);
|
||||
timer_set_interrupts(FRC1, true);
|
||||
timer_set_run(FRC1, true);
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@
|
|||
|
||||
#include "ssid_config.h"
|
||||
|
||||
#define WEB_SERVER "chainxor.org"
|
||||
#define WEB_SERVER "ipv6.google.com"
|
||||
#define WEB_PORT 80
|
||||
#define WEB_URL "http://chainxor.org/"
|
||||
#define WEB_PATH "/"
|
||||
|
||||
void http_get_task(void *pvParameters)
|
||||
{
|
||||
|
|
@ -31,7 +31,7 @@ void http_get_task(void *pvParameters)
|
|||
|
||||
while(1) {
|
||||
const struct addrinfo hints = {
|
||||
.ai_family = AF_INET,
|
||||
.ai_family = AF_UNSPEC,
|
||||
.ai_socktype = SOCK_STREAM,
|
||||
};
|
||||
struct addrinfo *res;
|
||||
|
|
@ -39,7 +39,7 @@ void http_get_task(void *pvParameters)
|
|||
printf("Running DNS lookup for %s...\r\n", WEB_SERVER);
|
||||
int err = getaddrinfo(WEB_SERVER, "80", &hints, &res);
|
||||
|
||||
if(err != 0 || res == NULL) {
|
||||
if (err != 0 || res == NULL) {
|
||||
printf("DNS lookup failed err=%d res=%p\r\n", err, res);
|
||||
if(res)
|
||||
freeaddrinfo(res);
|
||||
|
|
@ -47,9 +47,28 @@ void http_get_task(void *pvParameters)
|
|||
failures++;
|
||||
continue;
|
||||
}
|
||||
/* Note: inet_ntoa is non-reentrant, look at ipaddr_ntoa_r for "real" code */
|
||||
struct in_addr *addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr;
|
||||
printf("DNS lookup succeeded. IP=%s\r\n", inet_ntoa(*addr));
|
||||
|
||||
#if LWIP_IPV6
|
||||
{
|
||||
struct netif *netif = sdk_system_get_netif(0);
|
||||
int i;
|
||||
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
|
||||
printf(" ip6 %d state %x\n", i, netif_ip6_addr_state(netif, i));
|
||||
if (!ip6_addr_isinvalid(netif_ip6_addr_state(netif, i)))
|
||||
printf(" ip6 addr %d = %s\n", i, ip6addr_ntoa(netif_ip6_addr(netif, i)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
struct sockaddr *sa = res->ai_addr;
|
||||
if (sa->sa_family == AF_INET) {
|
||||
printf("DNS lookup succeeded. IP=%s\r\n", inet_ntoa(((struct sockaddr_in *)sa)->sin_addr));
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
if (sa->sa_family == AF_INET6) {
|
||||
printf("DNS lookup succeeded. IP=%s\r\n", inet6_ntoa(((struct sockaddr_in6 *)sa)->sin6_addr));
|
||||
}
|
||||
#endif
|
||||
|
||||
int s = socket(res->ai_family, res->ai_socktype, 0);
|
||||
if(s < 0) {
|
||||
|
|
@ -75,8 +94,10 @@ void http_get_task(void *pvParameters)
|
|||
freeaddrinfo(res);
|
||||
|
||||
const char *req =
|
||||
"GET "WEB_URL"\r\n"
|
||||
"GET "WEB_PATH" HTTP/1.1\r\n"
|
||||
"Host: "WEB_SERVER"\r\n"
|
||||
"User-Agent: esp-open-rtos/0.1 esp8266\r\n"
|
||||
"Connection: close\r\n"
|
||||
"\r\n";
|
||||
if (write(s, req, strlen(req)) < 0) {
|
||||
printf("... socket send failed\r\n");
|
||||
|
|
@ -126,6 +147,6 @@ void user_init(void)
|
|||
sdk_wifi_set_opmode(STATION_MODE);
|
||||
sdk_wifi_station_set_config(&config);
|
||||
|
||||
xTaskCreate(&http_get_task, "get_task", 256, NULL, 2, NULL);
|
||||
xTaskCreate(&http_get_task, "get_task", 384, NULL, 2, NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ static inline void init_descriptors_list()
|
|||
}
|
||||
|
||||
// DMA interrupt handler. It is called each time a DMA block is finished processing.
|
||||
static void dma_isr_handler(void)
|
||||
static void dma_isr_handler(void *args)
|
||||
{
|
||||
portBASE_TYPE task_awoken = pdFALSE;
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ void play_task(void *pvParameters)
|
|||
|
||||
i2s_pins_t i2s_pins = {.data = true, .clock = true, .ws = true};
|
||||
|
||||
i2s_dma_init(dma_isr_handler, clock_div, i2s_pins);
|
||||
i2s_dma_init(dma_isr_handler, NULL, clock_div, i2s_pins);
|
||||
|
||||
while (1) {
|
||||
init_descriptors_list();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ include ../../common.mk
|
|||
# `make dump-flash` can be used to view the current contents of the sysparam
|
||||
# regions in flash.
|
||||
dump-flash:
|
||||
esptool.py read_flash 0x1f8000 8192 r1.bin
|
||||
esptool.py read_flash 0x1f7000 8192 r1.bin
|
||||
hexdump -C r1.bin
|
||||
esptool.py read_flash 0x1fa000 8192 r2.bin
|
||||
esptool.py read_flash 0x1f9000 8192 r2.bin
|
||||
hexdump -C r2.bin
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ size_t tty_readline(char *buffer, size_t buf_size, bool echo) {
|
|||
|
||||
while (true) {
|
||||
c = getchar();
|
||||
if (c == '\r') {
|
||||
if (c == '\r' || c == '\n') {
|
||||
if (echo) putchar('\n');
|
||||
break;
|
||||
} else if (c == '\b' || c == 0x7f) {
|
||||
|
|
@ -173,7 +173,7 @@ void sysparam_editor_task(void *pvParameters) {
|
|||
// stuff, so if the user uses this utility to reformat it, it will put
|
||||
// it somewhere the system will find it later
|
||||
num_sectors = DEFAULT_SYSPARAM_SECTORS;
|
||||
base_addr = sdk_flashchip.chip_size - (4 + num_sectors) * sdk_flashchip.sector_size;
|
||||
base_addr = sdk_flashchip.chip_size - (5 + num_sectors) * sdk_flashchip.sector_size;
|
||||
}
|
||||
while (true) {
|
||||
printf("==> ");
|
||||
|
|
@ -246,5 +246,7 @@ void user_init(void)
|
|||
{
|
||||
uart_set_baud(0, 115200);
|
||||
|
||||
sdk_wifi_set_opmode(NULL_MODE);
|
||||
|
||||
xTaskCreate(sysparam_editor_task, "sysparam_editor_task", 512, NULL, 2, NULL);
|
||||
}
|
||||
|
|
|
|||
5
examples/tcp_non_blocking/Makefile
Normal file
5
examples/tcp_non_blocking/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Makefile for tcp_non_blocking example
|
||||
PROGRAM=tcp_non_blocking
|
||||
EXTRA_COMPONENTS=extras/dhcpserver
|
||||
|
||||
include ../../common.mk
|
||||
203
examples/tcp_non_blocking/tcp_non_blocking.c
Normal file
203
examples/tcp_non_blocking/tcp_non_blocking.c
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
The ESP in the example runs a echo server on 172.16.0.1 (port 50 and 100 ) that
|
||||
outputs information about your ip/port then echo all text you write.
|
||||
It is manage multiple connection and multiple port with one task.
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <espressif/esp_common.h>
|
||||
#include <esp8266.h>
|
||||
#include <esp/uart.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <queue.h>
|
||||
#include <dhcpserver.h>
|
||||
#include <lwip/api.h>
|
||||
|
||||
#define AP_SSID "esp-open-rtos AP"
|
||||
#define AP_PSK "esp-open-rtos"
|
||||
#define ECHO_PORT_1 50
|
||||
#define ECHO_PORT_2 100
|
||||
#define EVENTS_QUEUE_SIZE 10
|
||||
|
||||
#ifdef CALLBACK_DEBUG
|
||||
#define debug(s, ...) printf("%s: " s "\n", "Cb:", ## __VA_ARGS__)
|
||||
#else
|
||||
#define debug(s, ...)
|
||||
#endif
|
||||
|
||||
QueueHandle_t xQueue_events;
|
||||
typedef struct {
|
||||
struct netconn *nc ;
|
||||
uint8_t type ;
|
||||
} netconn_events;
|
||||
|
||||
/*
|
||||
* This function will be call in Lwip in each event on netconn
|
||||
*/
|
||||
static void netCallback(struct netconn *conn, enum netconn_evt evt, uint16_t length)
|
||||
{
|
||||
//Show some callback information (debug)
|
||||
debug("sock:%u\tsta:%u\tevt:%u\tlen:%u\ttyp:%u\tfla:%02X\terr:%d", \
|
||||
(uint32_t)conn,conn->state,evt,length,conn->type,conn->flags,conn->last_err);
|
||||
|
||||
netconn_events events ;
|
||||
|
||||
//If netconn got error, it is close or deleted, dont do treatments on it.
|
||||
if (conn->pending_err)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//Treatments only on rcv events.
|
||||
switch (evt) {
|
||||
case NETCONN_EVT_RCVPLUS:
|
||||
events.nc = conn ;
|
||||
events.type = evt ;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
//Send the event to the queue
|
||||
xQueueSend(xQueue_events, &events, 1000);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize a server netconn and listen port
|
||||
*/
|
||||
static void set_tcp_server_netconn(struct netconn **nc, uint16_t port, netconn_callback callback)
|
||||
{
|
||||
if(nc == NULL)
|
||||
{
|
||||
printf("%s: netconn missing .\n",__FUNCTION__);
|
||||
return;
|
||||
}
|
||||
*nc = netconn_new_with_callback(NETCONN_TCP, netCallback);
|
||||
if(!*nc) {
|
||||
printf("Status monitor: Failed to allocate netconn.\n");
|
||||
return;
|
||||
}
|
||||
netconn_set_nonblocking(*nc,NETCONN_FLAG_NON_BLOCKING);
|
||||
//netconn_set_recvtimeout(*nc, 10);
|
||||
netconn_bind(*nc, IP_ADDR_ANY, port);
|
||||
netconn_listen(*nc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Close and delete a socket properly
|
||||
*/
|
||||
static void close_tcp_netconn(struct netconn *nc)
|
||||
{
|
||||
nc->pending_err=ERR_CLSD; //It is hacky way to be sure than callback will don't do treatment on a netconn closed and deleted
|
||||
netconn_close(nc);
|
||||
netconn_delete(nc);
|
||||
}
|
||||
|
||||
/*
|
||||
* This task manage each netconn connection without block anything
|
||||
*/
|
||||
static void nonBlockingTCP(void *pvParameters)
|
||||
{
|
||||
|
||||
struct netconn *nc = NULL; // To create servers
|
||||
|
||||
set_tcp_server_netconn(&nc, ECHO_PORT_1, netCallback);
|
||||
printf("Server netconn %u ready on port %u.\n",(uint32_t)nc, ECHO_PORT_1);
|
||||
set_tcp_server_netconn(&nc, ECHO_PORT_2, netCallback);
|
||||
printf("Server netconn %u ready on port %u.\n",(uint32_t)nc, ECHO_PORT_2);
|
||||
|
||||
struct netbuf *netbuf = NULL; // To store incoming Data
|
||||
struct netconn *nc_in = NULL; // To accept incoming netconn
|
||||
//
|
||||
char buf[50];
|
||||
char* buffer;
|
||||
uint16_t len_buf;
|
||||
|
||||
while(1) {
|
||||
|
||||
netconn_events events;
|
||||
xQueueReceive(xQueue_events, &events, portMAX_DELAY); // Wait here an event on netconn
|
||||
|
||||
if (events.nc->state == NETCONN_LISTEN) // If netconn is a server and receive incoming event on it
|
||||
{
|
||||
printf("Client incoming on server %u.\n", (uint32_t)events.nc);
|
||||
int err = netconn_accept(events.nc, &nc_in);
|
||||
if (err != ERR_OK)
|
||||
{
|
||||
if(nc_in)
|
||||
netconn_delete(nc_in);
|
||||
}
|
||||
printf("New client is %u.\n",(uint32_t)nc_in);
|
||||
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);
|
||||
netconn_write(nc_in, buf, strlen(buf), NETCONN_COPY);
|
||||
}
|
||||
else if(events.nc->state != NETCONN_LISTEN) // If netconn is the client and receive data
|
||||
{
|
||||
if ((netconn_recv(events.nc, &netbuf)) == ERR_OK) // data incoming ?
|
||||
{
|
||||
do
|
||||
{
|
||||
netbuf_data(netbuf, (void*)&buffer, &len_buf);
|
||||
netconn_write(events.nc, buffer, strlen(buffer), NETCONN_COPY);
|
||||
printf("Client %u send: %s\n",(uint32_t)events.nc,buffer);
|
||||
}
|
||||
while (netbuf_next(netbuf) >= 0);
|
||||
netbuf_delete(netbuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
close_tcp_netconn(events.nc);
|
||||
printf("Error read netconn %u, close it \n",(uint32_t)events.nc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
sdk_os_delay_us(500); // Wait UART
|
||||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
|
||||
sdk_wifi_set_opmode(SOFTAP_MODE);
|
||||
struct ip_info ap_ip;
|
||||
IP4_ADDR(&ap_ip.ip, 172, 16, 0, 1);
|
||||
IP4_ADDR(&ap_ip.gw, 0, 0, 0, 0);
|
||||
IP4_ADDR(&ap_ip.netmask, 255, 255, 0, 0);
|
||||
sdk_wifi_set_ip_info(1, &ap_ip);
|
||||
|
||||
struct sdk_softap_config ap_config = {
|
||||
.ssid = AP_SSID,
|
||||
.ssid_hidden = 0,
|
||||
.channel = 3,
|
||||
.ssid_len = strlen(AP_SSID),
|
||||
.authmode = AUTH_WPA_WPA2_PSK,
|
||||
.password = AP_PSK,
|
||||
.max_connection = 3,
|
||||
.beacon_interval = 100,
|
||||
};
|
||||
sdk_wifi_softap_set_config(&ap_config);
|
||||
|
||||
ip_addr_t first_client_ip;
|
||||
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
||||
dhcpserver_start(&first_client_ip, 4);
|
||||
printf("DHCP started\n");
|
||||
|
||||
//Create a queue to store events on netconns
|
||||
xQueue_events = xQueueCreate( EVENTS_QUEUE_SIZE, sizeof(netconn_events));
|
||||
|
||||
xTaskCreate(nonBlockingTCP, "lwiptest_noblock", 512, NULL, 2, NULL);
|
||||
}
|
||||
|
|
@ -94,18 +94,23 @@ static void gpiomon()
|
|||
int i = 0;
|
||||
printf("\n\n\nWelcome to gpiomon. Type 'help<enter>' for, well, help\n");
|
||||
printf("%% ");
|
||||
fflush(stdout); // stdout is line buffered
|
||||
while(1) {
|
||||
if (read(0, (void*)&ch, 1)) { // 0 is stdin
|
||||
printf("%c", ch);
|
||||
fflush(stdout);
|
||||
if (ch == '\n' || ch == '\r') {
|
||||
cmd[i] = 0;
|
||||
i = 0;
|
||||
printf("\n");
|
||||
handle_command((char*) cmd);
|
||||
printf("%% ");
|
||||
fflush(stdout);
|
||||
} else {
|
||||
if (i < sizeof(cmd)) cmd[i++] = ch;
|
||||
}
|
||||
} else {
|
||||
printf("You will never see this print as read(...) is blocking\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,9 +202,8 @@ void tls_server_task(void *pvParameters)
|
|||
socklen_t peer_addr_len = sizeof(struct sockaddr_in);
|
||||
getpeername(client_ctx.fd, (struct sockaddr *)&peer_addr, &peer_addr_len);
|
||||
unsigned char buf[256];
|
||||
int len = sprintf((char *) buf, "O hai, client %d.%d.%d.%d:%d\nFree heap size is %d bytes\n",
|
||||
ip4_addr1(&peer_addr.sin_addr), ip4_addr2(&peer_addr.sin_addr),
|
||||
ip4_addr3(&peer_addr.sin_addr), ip4_addr4(&peer_addr.sin_addr),
|
||||
int len = sprintf((char *) buf, "O hai, client " IPSTR ":%d\nFree heap size is %d bytes\n",
|
||||
IP2STR((ip4_addr_t *)&peer_addr.sin_addr.s_addr),
|
||||
peer_addr.sin_port, xPortGetFreeHeapSize());
|
||||
while((ret = mbedtls_ssl_write(&ssl, buf, len)) <= 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -146,9 +146,8 @@ void tls_server_task(void *pvParameters)
|
|||
|
||||
/* Prepare a message to the client */
|
||||
unsigned char buf[100];
|
||||
int len = sprintf((char *) buf, "O hai, client %d.%d.%d.%d:%d\r\nFree heap size is %d bytes\r\n",
|
||||
ip4_addr1(&sa.sin_addr), ip4_addr2(&sa.sin_addr),
|
||||
ip4_addr3(&sa.sin_addr), ip4_addr4(&sa.sin_addr),
|
||||
int len = sprintf((char *) buf, "O hai, client " IPSTR ":%d\r\nFree heap size is %d bytes\r\n",
|
||||
IP2STR((ip4_addr_t *)&sa.sin_addr.s_addr),
|
||||
ntohs(sa.sin_port), xPortGetFreeHeapSize());
|
||||
|
||||
/* Send the message and close the connection */
|
||||
|
|
|
|||
|
|
@ -1,464 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Simon Goldschmidt
|
||||
*
|
||||
*/
|
||||
#ifndef __LWIPOPTS_H__
|
||||
#define __LWIPOPTS_H__
|
||||
|
||||
#define LWIP_ESP 1
|
||||
#define ESP_RTOS 1
|
||||
#define PBUF_RSV_FOR_WLAN 1
|
||||
#define EBUF_LWIP 1
|
||||
#define ESP_TIMEWAIT_THRESHOLD 10000
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
|
||||
#define TCP_WND (TCP_MSS * 2)
|
||||
|
||||
#define LWIP_IGMP 1
|
||||
#include <stdint.h>
|
||||
#include <esp/hwrand.h>
|
||||
#define LWIP_RAND hwrand
|
||||
|
||||
/*
|
||||
-----------------------------------------------
|
||||
---------- Platform specific locking ----------
|
||||
-----------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
|
||||
* critical regions during buffer allocation, deallocation and memory
|
||||
* allocation and deallocation.
|
||||
*/
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
/**
|
||||
* MEMCPY: override this if you have a faster implementation at hand than the
|
||||
* one included in your C library
|
||||
*/
|
||||
#define MEMCPY(dst,src,len) memcpy(dst,src,len)
|
||||
|
||||
/**
|
||||
* SMEMCPY: override this with care! Some compilers (e.g. gcc) can inline a
|
||||
* call to memcpy() if the length is known at compile time and is small.
|
||||
*/
|
||||
#define SMEMCPY(dst,src,len) memcpy(dst,src,len)
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- Memory options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/**
|
||||
* MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library
|
||||
* instead of the lwip internal allocator. Can save code size if you
|
||||
* already use it.
|
||||
*/
|
||||
#define MEM_LIBC_MALLOC 1
|
||||
|
||||
/**
|
||||
* MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator.
|
||||
* Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution
|
||||
* speed and usage from interrupts!
|
||||
*/
|
||||
#define MEMP_MEM_MALLOC 1
|
||||
|
||||
/**
|
||||
* MEM_ALIGNMENT: should be set to the alignment of the CPU
|
||||
* 4 byte alignment -> #define MEM_ALIGNMENT 4
|
||||
* 2 byte alignment -> #define MEM_ALIGNMENT 2
|
||||
*/
|
||||
#define MEM_ALIGNMENT 4
|
||||
|
||||
/*
|
||||
------------------------------------------------
|
||||
---------- Internal Memory Pool Sizes ----------
|
||||
------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
--------------------------------
|
||||
---------- ARP options -------
|
||||
--------------------------------
|
||||
*/
|
||||
/**
|
||||
* ARP_QUEUEING==1: Multiple outgoing packets are queued during hardware address
|
||||
* resolution. By default, only the most recent packet is queued per IP address.
|
||||
* This is sufficient for most protocols and mainly reduces TCP connection
|
||||
* startup time. Set this to 1 if you know your application sends more than one
|
||||
* packet in a row to an IP address that is not in the ARP cache.
|
||||
*/
|
||||
#define ARP_QUEUEING 1
|
||||
|
||||
/*
|
||||
--------------------------------
|
||||
---------- IP options ----------
|
||||
--------------------------------
|
||||
*/
|
||||
/**
|
||||
* IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets. Note that
|
||||
* this option does not affect outgoing packet sizes, which can be controlled
|
||||
* via IP_FRAG.
|
||||
*/
|
||||
#define IP_REASSEMBLY 0
|
||||
|
||||
/**
|
||||
* IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU. Note
|
||||
* that this option does not affect incoming packet sizes, which can be
|
||||
* controlled via IP_REASSEMBLY.
|
||||
*/
|
||||
#define IP_FRAG 1
|
||||
|
||||
/**
|
||||
* IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally)
|
||||
* a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived
|
||||
* in this time, the whole packet is discarded.
|
||||
*/
|
||||
#define IP_REASS_MAXAGE 3
|
||||
|
||||
/**
|
||||
* IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled.
|
||||
* Since the received pbufs are enqueued, be sure to configure
|
||||
* PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive
|
||||
* packets even if the maximum amount of fragments is enqueued for reassembly!
|
||||
*/
|
||||
#define IP_REASS_MAX_PBUFS 10
|
||||
|
||||
/*
|
||||
----------------------------------
|
||||
---------- ICMP options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- RAW options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------
|
||||
---------- DHCP options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_DHCP==1: Enable DHCP module.
|
||||
*/
|
||||
#define LWIP_DHCP 1
|
||||
|
||||
#define LWIP_DHCP_BOOTP_FILE 0
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- AUTOIP options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/*
|
||||
----------------------------------
|
||||
---------- SNMP options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
/*
|
||||
----------------------------------
|
||||
---------- IGMP options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
/*
|
||||
----------------------------------
|
||||
---------- DNS options -----------
|
||||
----------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS
|
||||
* transport.
|
||||
*/
|
||||
#define LWIP_DNS 1
|
||||
|
||||
#define DNS_TABLE_SIZE 1
|
||||
#define DNS_MAX_NAME_LENGTH 128
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- UDP options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
/*
|
||||
---------------------------------
|
||||
---------- TCP options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
/**
|
||||
* TCP_QUEUE_OOSEQ==1: TCP will queue segments that arrive out of order.
|
||||
* Define to 0 if your device is low on memory.
|
||||
*/
|
||||
#define TCP_QUEUE_OOSEQ 0
|
||||
|
||||
/*
|
||||
* LWIP_EVENT_API==1: The user defines lwip_tcp_event() to receive all
|
||||
* events (accept, sent, etc) that happen in the system.
|
||||
* LWIP_CALLBACK_API==1: The PCB callback function is called directly
|
||||
* for the event. This is the default.
|
||||
*/
|
||||
#define TCP_MSS 1460
|
||||
|
||||
/**
|
||||
* TCP_MAXRTX: Maximum number of retransmissions of data segments.
|
||||
*/
|
||||
#define TCP_MAXRTX 6
|
||||
|
||||
|
||||
/**
|
||||
* TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments.
|
||||
*/
|
||||
#define TCP_SYNMAXRTX 3
|
||||
|
||||
/*
|
||||
----------------------------------
|
||||
---------- Pbuf options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
------------------------------------------------
|
||||
---------- Network Interfaces options ----------
|
||||
------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP tries to put all data
|
||||
* to be sent into one single pbuf. This is for compatibility with DMA-enabled
|
||||
* MACs that do not support scatter-gather.
|
||||
* Beware that this might involve CPU-memcpy before transmitting that would not
|
||||
* be needed without this flag! Use this only if you need to!
|
||||
*
|
||||
* @todo: TCP and IP-frag do not work with this, yet:
|
||||
*/
|
||||
#define LWIP_NETIF_TX_SINGLE_PBUF 1
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- LOOPIF options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- SLIPIF options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- Thread options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/**
|
||||
* TCPIP_THREAD_STACKSIZE: The stack size used by the main tcpip thread.
|
||||
* The stack size value itself is platform-dependent, but is passed to
|
||||
* sys_thread_new() when the thread is created.
|
||||
*/
|
||||
#define TCPIP_THREAD_STACKSIZE 512 //not ok:384
|
||||
|
||||
/**
|
||||
* TCPIP_THREAD_PRIO: The priority assigned to the main tcpip thread.
|
||||
* The priority value itself is platform-dependent, but is passed to
|
||||
* sys_thread_new() when the thread is created.
|
||||
*/
|
||||
#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES-5)
|
||||
|
||||
/**
|
||||
* TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages
|
||||
* The queue size value itself is platform-dependent, but is passed to
|
||||
* sys_mbox_new() when tcpip_init is called.
|
||||
*/
|
||||
#define TCPIP_MBOX_SIZE 16
|
||||
|
||||
/**
|
||||
* DEFAULT_UDP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
|
||||
* NETCONN_UDP. The queue size value itself is platform-dependent, but is passed
|
||||
* to sys_mbox_new() when the recvmbox is created.
|
||||
*/
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE 6
|
||||
|
||||
/**
|
||||
* DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
|
||||
* NETCONN_TCP. The queue size value itself is platform-dependent, but is passed
|
||||
* to sys_mbox_new() when the recvmbox is created.
|
||||
*/
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE 6
|
||||
|
||||
/**
|
||||
* DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections.
|
||||
* The queue size value itself is platform-dependent, but is passed to
|
||||
* sys_mbox_new() when the acceptmbox is created.
|
||||
*/
|
||||
#define DEFAULT_ACCEPTMBOX_SIZE 6
|
||||
|
||||
/*
|
||||
----------------------------------------------
|
||||
---------- Sequential layer options ----------
|
||||
----------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- Socket options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and
|
||||
* SO_SNDTIMEO processing.
|
||||
*/
|
||||
#define LWIP_SO_SNDTIMEO 1
|
||||
|
||||
/**
|
||||
* LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
|
||||
* SO_RCVTIMEO processing.
|
||||
*/
|
||||
#define LWIP_SO_RCVTIMEO 1
|
||||
|
||||
/**
|
||||
* LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT
|
||||
* options processing. Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set
|
||||
* in seconds. (does not require sockets.c, and will affect tcp.c)
|
||||
*/
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
/**
|
||||
* LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
|
||||
*/
|
||||
#define LWIP_SO_RCVBUF 0
|
||||
|
||||
/**
|
||||
* SO_REUSE==1: Enable SO_REUSEADDR option.
|
||||
*/
|
||||
#define SO_REUSE 1
|
||||
|
||||
/*
|
||||
----------------------------------------
|
||||
---------- Statistics options ----------
|
||||
----------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- PPP options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
--------------------------------------
|
||||
---------- Checksum options ----------
|
||||
--------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
---------------------------------------
|
||||
---------- IPv6 options ---------------
|
||||
---------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
---------------------------------------
|
||||
---------- Hook options ---------------
|
||||
---------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
---------------------------------------
|
||||
---------- Debugging options ----------
|
||||
---------------------------------------
|
||||
*/
|
||||
|
||||
// Uncomment this line, and set the individual debug options you want, for IP stack debug output
|
||||
//#define LWIP_DEBUG
|
||||
|
||||
/**
|
||||
* ETHARP_DEBUG: Enable debugging in etharp.c.
|
||||
*/
|
||||
#define ETHARP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* PBUF_DEBUG: Enable debugging in pbuf.c.
|
||||
*/
|
||||
#define PBUF_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* API_LIB_DEBUG: Enable debugging in api_lib.c.
|
||||
*/
|
||||
#define API_LIB_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* SOCKETS_DEBUG: Enable debugging in sockets.c.
|
||||
*/
|
||||
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* IP_DEBUG: Enable debugging for IP.
|
||||
*/
|
||||
#define IP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* MEMP_DEBUG: Enable debugging in memp.c.
|
||||
*/
|
||||
#define MEMP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* TCP_INPUT_DEBUG: Enable debugging in tcp_in.c for incoming debug.
|
||||
*/
|
||||
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* TCP_OUTPUT_DEBUG: Enable debugging in tcp_out.c output functions.
|
||||
*/
|
||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* UDP_DEBUG: Enable debugging in udp.c.
|
||||
*/
|
||||
#define UDP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* ICMP_DEBUG: Enable debugging in udp.c.
|
||||
*/
|
||||
#define ICMP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
/**
|
||||
* TCPIP_DEBUG: Enable debugging in tcpip.c.
|
||||
*/
|
||||
#define TCPIP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
|
||||
/**
|
||||
* DHCP_DEBUG: Enable debugging in dhcp.c.
|
||||
*/
|
||||
#define DHCP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
|
||||
|
||||
#endif /* __LWIPOPTS_H__ */
|
||||
/* Use the defaults for everything else */
|
||||
#include_next <lwipopts.h>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <string.h>
|
||||
#include <lwip/udp.h>
|
||||
#include <lwip/igmp.h>
|
||||
#include <lwip/ip_addr.h>
|
||||
#include <espressif/esp_common.h>
|
||||
#include "upnp.h"
|
||||
|
||||
|
|
@ -18,13 +19,13 @@ static const char* get_my_ip(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief This function joins a multicast group witht he specified ip/port
|
||||
* @brief This function joins a multicast group with the specified ip/port
|
||||
* @param group_ip the specified multicast group ip
|
||||
* @param group_port the specified multicast port number
|
||||
* @param recv the lwip UDP callback
|
||||
* @retval udp_pcb* or NULL if joining failed
|
||||
*/
|
||||
static struct udp_pcb* mcast_join_group(char *group_ip, uint16_t group_port, void (* recv)(void * arg, struct udp_pcb * upcb, struct pbuf * p, struct ip_addr * addr, u16_t port))
|
||||
static struct udp_pcb* mcast_join_group(char *group_ip, uint16_t group_port, void (* recv)(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port))
|
||||
{
|
||||
bool status = false;
|
||||
struct udp_pcb *upcb;
|
||||
|
|
@ -36,7 +37,7 @@ static struct udp_pcb* mcast_join_group(char *group_ip, uint16_t group_port, voi
|
|||
printf("Error, udp_new failed");
|
||||
break;
|
||||
}
|
||||
udp_bind(upcb, IP_ADDR_ANY, group_port);
|
||||
udp_bind(upcb, IP4_ADDR_ANY, group_port);
|
||||
struct netif* netif = sdk_system_get_netif(STATION_IF);
|
||||
if (!netif) {
|
||||
printf("Error, netif is null");
|
||||
|
|
@ -46,10 +47,10 @@ static struct udp_pcb* mcast_join_group(char *group_ip, uint16_t group_port, voi
|
|||
netif->flags |= NETIF_FLAG_IGMP;
|
||||
igmp_start(netif);
|
||||
}
|
||||
ip_addr_t ipgroup;
|
||||
ipaddr_aton(group_ip, &ipgroup);
|
||||
err_t err = igmp_joingroup(&netif->ip_addr, &ipgroup);
|
||||
if(ERR_OK != err) {
|
||||
ip4_addr_t ipgroup;
|
||||
ip4addr_aton(group_ip, &ipgroup);
|
||||
err_t err = igmp_joingroup_netif(netif, &ipgroup);
|
||||
if (ERR_OK != err) {
|
||||
printf("Failed to join multicast group: %d", err);
|
||||
break;
|
||||
}
|
||||
|
|
@ -68,7 +69,7 @@ static struct udp_pcb* mcast_join_group(char *group_ip, uint16_t group_port, voi
|
|||
return upcb;
|
||||
}
|
||||
|
||||
static void send(struct udp_pcb *upcb, struct ip_addr *addr, u16_t port)
|
||||
static void send_udp(struct udp_pcb *upcb, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
struct pbuf *p;
|
||||
char msg[500];
|
||||
|
|
@ -110,14 +111,14 @@ static void send(struct udp_pcb *upcb, struct ip_addr *addr, u16_t port)
|
|||
* @param port the remote port from which the packet was received
|
||||
* @retval None
|
||||
*/
|
||||
static void receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
|
||||
static void receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
if (p) {
|
||||
printf("Msg received port:%d len:%d\n", port, p->len);
|
||||
uint8_t *buf = (uint8_t*) p->payload;
|
||||
printf("Msg received port:%d len:%d\nbuf: %s\n", port, p->len, buf);
|
||||
|
||||
send(upcb, addr, port);
|
||||
send_udp(upcb, addr, port);
|
||||
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
|
|
|||
1
examples/wificfg/.gitignore
vendored
Normal file
1
examples/wificfg/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
!local.mk
|
||||
7
examples/wificfg/FreeRTOSConfig.h
Normal file
7
examples/wificfg/FreeRTOSConfig.h
Normal file
|
|
@ -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>
|
||||
5
examples/wificfg/Makefile
Normal file
5
examples/wificfg/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Makefile for wificfg example
|
||||
PROGRAM=wificfg
|
||||
EXTRA_COMPONENTS=extras/dhcpserver extras/wificfg
|
||||
|
||||
include ../../common.mk
|
||||
18
examples/wificfg/content/index.html
Normal file
18
examples/wificfg/content/index.html
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
"<!DOCTYPE html><html lang=\"en\">"
|
||||
"<head>"
|
||||
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/style.css\">"
|
||||
"<script src=\"/script.js\"></script>"
|
||||
"<title>",
|
||||
"</title>"
|
||||
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
|
||||
"</head>"
|
||||
"<body>"
|
||||
"<ul class=\"topnav\" id=\"myTopnav\">"
|
||||
"<li class=\"active\"><a href=\"/\">Home</a></li>"
|
||||
"<li><a href=\"/wificfg/\">WiFi Config</a></li>"
|
||||
"<li><a href=\"/tasks.html\">Tasks</a></li>"
|
||||
"<li class=\"icon\">"
|
||||
"<a href=\"javascript:void(0);\" onclick=\"myFunction()\">☰</a>"
|
||||
"</li>"
|
||||
"</ul>",
|
||||
"</body></html>"
|
||||
1
examples/wificfg/local.mk
Normal file
1
examples/wificfg/local.mk
Normal file
|
|
@ -0,0 +1 @@
|
|||
FLASH_SIZE ?= 32
|
||||
94
examples/wificfg/wificfg.c
Normal file
94
examples/wificfg/wificfg.c
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Example Wifi configuration via an access point.
|
||||
*
|
||||
* Copyright (C) 2016 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 "wificfg/wificfg.h"
|
||||
|
||||
#include "sysparam.h"
|
||||
|
||||
static const char http_success_header[] = "HTTP/1.1 200 \r\n"
|
||||
"Content-Type: text/html; charset=utf-8\r\n"
|
||||
"Cache-Control: no-store\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"Connection: close\r\n"
|
||||
"\r\n";
|
||||
static const char *http_index_content[] = {
|
||||
#include "content/index.html"
|
||||
};
|
||||
|
||||
static int handle_index(int s, wificfg_method method,
|
||||
uint32_t content_length,
|
||||
wificfg_content_type content_type,
|
||||
char *buf, size_t len)
|
||||
{
|
||||
if (wificfg_write_string(s, http_success_header) < 0) return -1;
|
||||
|
||||
if (method != HTTP_METHOD_HEAD) {
|
||||
if (wificfg_write_string_chunk(s, http_index_content[0], buf, len) < 0) return -1;
|
||||
if (wificfg_write_html_title(s, buf, len, "Home") < 0) return -1;
|
||||
if (wificfg_write_string_chunk(s, http_index_content[1], buf, len) < 0) return -1;
|
||||
|
||||
socklen_t addr_len;
|
||||
struct sockaddr addr;
|
||||
addr_len = sizeof(addr);
|
||||
getpeername(s, (struct sockaddr*)&addr, &addr_len);
|
||||
|
||||
if (wificfg_write_string_chunk(s, "<dl class=\"dlh\">", buf, len) < 0) return -1;
|
||||
if (addr.sa_family == AF_INET) {
|
||||
struct sockaddr_in *sa = (struct sockaddr_in *)&addr;
|
||||
if (wificfg_write_string_chunk(s, "<dt>Peer address</dt>", buf, len) < 0) return -1;
|
||||
snprintf(buf, len, "<dd>" IPSTR " : %d</dd>",
|
||||
IP2STR((ip4_addr_t *)&sa->sin_addr.s_addr), ntohs(sa->sin_port));
|
||||
if (wificfg_write_string_chunk(s, buf, buf, len) < 0) return -1;
|
||||
}
|
||||
|
||||
if (wificfg_write_string_chunk(s, "</dl>", buf, len) < 0) return -1;
|
||||
if (wificfg_write_string_chunk(s, http_index_content[2], buf, len) < 0) return -1;
|
||||
if (wificfg_write_chunk_end(s) < 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const wificfg_dispatch dispatch_list[] = {
|
||||
{"/", HTTP_METHOD_GET, handle_index, false},
|
||||
{"/index.html", HTTP_METHOD_GET, handle_index, false},
|
||||
{NULL, HTTP_METHOD_ANY, NULL}
|
||||
};
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
|
||||
sdk_wifi_set_sleep_type(WIFI_SLEEP_MODEM);
|
||||
|
||||
wificfg_init(80, dispatch_list);
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "ws2812_i2s/ws2812_i2s.h"
|
||||
|
||||
const uint32_t led_number = 60;
|
||||
const uint32_t led_number = 12;
|
||||
const uint32_t tail_fade_factor = 2;
|
||||
const uint32_t tail_length = 8;
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ static int fix_index(int index)
|
|||
|
||||
static ws2812_pixel_t next_colour()
|
||||
{
|
||||
ws2812_pixel_t colour = {0, 0, 0};
|
||||
ws2812_pixel_t colour = {0, 0, 0, 0};
|
||||
colour.red = rand() % 256;
|
||||
colour.green = rand() % 256;
|
||||
colour.blue = rand() % 256;
|
||||
|
|
@ -54,7 +54,7 @@ static void demo(void *pvParameters)
|
|||
ws2812_pixel_t pixels[led_number];
|
||||
int head_index = 0;
|
||||
|
||||
ws2812_i2s_init(led_number);
|
||||
ws2812_i2s_init(led_number, PIXEL_RGB);
|
||||
|
||||
memset(pixels, 0, sizeof(ws2812_pixel_t) * led_number);
|
||||
|
||||
|
|
@ -69,8 +69,8 @@ static void demo(void *pvParameters)
|
|||
memset(&pixels[fix_index(head_index - tail_length)], 0,
|
||||
sizeof(ws2812_pixel_t));
|
||||
|
||||
ws2812_i2s_update(pixels);
|
||||
vTaskDelay(20 / portTICK_PERIOD_MS);
|
||||
ws2812_i2s_update(pixels, PIXEL_RGB);
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -78,6 +78,14 @@ static void demo(void *pvParameters)
|
|||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
struct sdk_station_config config = {
|
||||
.ssid = "Loading...",
|
||||
.password = "morays59924_howitzer",
|
||||
};
|
||||
|
||||
/* required to call wifi_set_opmode before station_set_config */
|
||||
sdk_wifi_set_opmode(STATION_MODE);
|
||||
sdk_wifi_station_set_config(&config);
|
||||
|
||||
xTaskCreate(&demo, "ws2812_i2s", 256, NULL, 10, NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue