Skip to content

set gcc defaults, fix xt-nm reference, remove system_get_sdk_version reference (GIT8266O-283) #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ifndef PDIR

endif

COMPILE?=gcc
ifeq ($(COMPILE), gcc)
AR = xtensa-lx106-elf-ar
CC = xtensa-lx106-elf-gcc
Expand Down Expand Up @@ -221,7 +222,7 @@ endif
@echo "!!!"

ifeq ($(app), 0)
@python ../tools/gen_appbin.py $< 0 $(mode) $(freqdiv) $(size)
COMPILE=$(COMPILE) python ../tools/gen_appbin.py $< 0 $(mode) $(freqdiv) $(size)
@mv eagle.app.flash.bin ../bin/eagle.flash.bin
@mv eagle.app.v6.irom0text.bin ../bin/eagle.irom0text.bin
@rm eagle.app.v6.*
Expand Down
1 change: 1 addition & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
PATH:=/home/src/esp8266/esp-open-sdk/xtensa-lx106-elf/bin:$(PATH)
TARGET = eagle
#FLAVOR = release
FLAVOR = debug
Expand Down
Empty file modified app/gen_misc.sh
100644 → 100755
Empty file.
5 changes: 0 additions & 5 deletions app/include/user_config.h

This file was deleted.

117 changes: 21 additions & 96 deletions app/user/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,66 +19,8 @@

#include "udhcp/dhcpd.h"

#define server_ip "192.168.101.142"
#define server_port 9669

void task2(void *pvParameters)
{
printf("Hello, welcome to client!\r\n");

while (1) {
int recbytes;
int sin_size;
int str_len;
int sta_socket;

struct sockaddr_in local_ip;
struct sockaddr_in remote_ip;

sta_socket = socket(PF_INET, SOCK_STREAM, 0);

if (-1 == sta_socket) {
close(sta_socket);
printf("C > socket fail!\n");
continue;
}

printf("C > socket ok!\n");
bzero(&remote_ip, sizeof(struct sockaddr_in));
remote_ip.sin_family = AF_INET;
remote_ip.sin_addr.s_addr = inet_addr(server_ip);
remote_ip.sin_port = htons(server_port);

if (0 != connect(sta_socket, (struct sockaddr *)(&remote_ip), sizeof(struct sockaddr))) {
close(sta_socket);
printf("C > connect fail!\n");
vTaskDelay(4000 / portTICK_RATE_MS);
continue;
}

printf("C > connect ok!\n");
char *pbuf = (char *)zalloc(1024);
sprintf(pbuf, "%s\n", "client_send info");

if (write(sta_socket, pbuf, strlen(pbuf) + 1) < 0) {
printf("C > send fail\n");
}

printf("C > send success\n");
free(pbuf);

char *recv_buf = (char *)zalloc(128);
while ((recbytes = read(sta_socket , recv_buf, 128)) > 0) {
recv_buf[recbytes] = 0;
printf("C > read data success %d!\nC > %s\n", recbytes, recv_buf);
}
free(recv_buf);

if (recbytes <= 0) {
printf("C > read data fail!\n");
}
}
}
#include "wifi_config.h"
#include "esp8266/uart_register.h"

void task3(void *pvParameters)
{
Expand All @@ -91,7 +33,7 @@ void task3(void *pvParameters)
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(80);

int recbytes;
int recbytes, sentbytes;

do {
if (-1 == (server_sock = socket(AF_INET, SOCK_STREAM, 0))) {
Expand Down Expand Up @@ -127,10 +69,12 @@ void task3(void *pvParameters)

printf("S > Client from %s %d\n", inet_ntoa(client_addr.sin_addr), htons(client_addr.sin_port));

char *recv_buf = (char *)zalloc(128);
char *recv_buf = (char *)zalloc(129);
while ((recbytes = read(client_sock , recv_buf, 128)) > 0) {
recv_buf[recbytes] = 0;
recv_buf[recbytes] = 0;
printf("S > read data success %d!\nS > %s\n", recbytes, recv_buf);
sentbytes = write(client_sock , recv_buf, recbytes);
printf("S > write %d\n", sentbytes);
}
free(recv_buf);

Expand All @@ -152,51 +96,32 @@ void task3(void *pvParameters)
void ICACHE_FLASH_ATTR
user_init(void)
{
printf("SDK version:%s\n", system_get_sdk_version());
uart_div_modify(0, UART_CLK_FREQ / 115200);
// print system info
printf("System Info:\r\n");
printf("Time=%u\r\n", system_get_time());
printf("RTC time=%u\r\n", system_get_rtc_time());
printf("Chip id=0x%x\r\n", system_get_chip_id());
printf("Free heap size=%u\r\n", system_get_free_heap_size());
printf("Mem info:\r\n");
system_print_meminfo();
printf("\r\n");
//printf("SDK version:%s\n", system_get_sdk_version());

/* need to set opmode before you set config */
wifi_set_opmode(STATIONAP_MODE);
wifi_set_opmode(STATION_MODE);

{
struct station_config *config = (struct station_config *)zalloc(sizeof(struct station_config));
sprintf(config->ssid, "CVR100W_T");
sprintf(config->password, "justfortest");
sprintf(config->ssid, WIFI_SSID);
sprintf(config->password, WIFI_PWD);

/* need to sure that you are in station mode first,
* otherwise it will be failed. */
wifi_station_set_config(config);
free(config);
}

{
struct ip_info ipinfo;

ipinfo.gw.addr = ipaddr_addr("192.168.145.253");
ipinfo.ip.addr = ipaddr_addr("192.168.145.253");
ipinfo.netmask.addr = ipaddr_addr("255.255.255.0");

wifi_set_ip_info(SOFTAP_IF, &ipinfo);
}

{
struct dhcp_info *pdhcp_info = NULL;

pdhcp_info = (struct dhcp_info *)zalloc(sizeof(struct dhcp_info));
pdhcp_info->start_ip = ipaddr_addr("192.168.145.100");
pdhcp_info->end_ip = ipaddr_addr("192.168.145.110"); // don't set the range too large, because it will cost memory.
pdhcp_info->max_leases = 10;
pdhcp_info->auto_time = 60;
pdhcp_info->decline_time = 60;
pdhcp_info->conflict_time = 60;
pdhcp_info->offer_time = 60;
pdhcp_info->min_lease_sec = 60;
dhcp_set_info(pdhcp_info);
free(pdhcp_info);
}

udhcpd_start();

xTaskCreate(task2, "tsk2", 256, NULL, 2, NULL);
xTaskCreate(task3, "tsk3", 256, NULL, 2, NULL);
}

202 changes: 202 additions & 0 deletions app/user/user_main.c-
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_main.c
*
* Description: entry file of user application
*
* Modification history:
* 2014/12/1, v1.0 create this file.
*******************************************************************************/
#include "esp_common.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "lwip/sockets.h"
#include "lwip/dns.h"
#include "lwip/netdb.h"

#include "udhcp/dhcpd.h"

#define server_ip "192.168.101.142"
#define server_port 9669

void task2(void *pvParameters)
{
printf("Hello, welcome to client!\r\n");

while (1) {
int recbytes;
int sin_size;
int str_len;
int sta_socket;

struct sockaddr_in local_ip;
struct sockaddr_in remote_ip;

sta_socket = socket(PF_INET, SOCK_STREAM, 0);

if (-1 == sta_socket) {
close(sta_socket);
printf("C > socket fail!\n");
continue;
}

printf("C > socket ok!\n");
bzero(&remote_ip, sizeof(struct sockaddr_in));
remote_ip.sin_family = AF_INET;
remote_ip.sin_addr.s_addr = inet_addr(server_ip);
remote_ip.sin_port = htons(server_port);

if (0 != connect(sta_socket, (struct sockaddr *)(&remote_ip), sizeof(struct sockaddr))) {
close(sta_socket);
printf("C > connect fail!\n");
vTaskDelay(4000 / portTICK_RATE_MS);
continue;
}

printf("C > connect ok!\n");
char *pbuf = (char *)zalloc(1024);
sprintf(pbuf, "%s\n", "client_send info");

if (write(sta_socket, pbuf, strlen(pbuf) + 1) < 0) {
printf("C > send fail\n");
}

printf("C > send success\n");
free(pbuf);

char *recv_buf = (char *)zalloc(128);
while ((recbytes = read(sta_socket , recv_buf, 128)) > 0) {
recv_buf[recbytes] = 0;
printf("C > read data success %d!\nC > %s\n", recbytes, recv_buf);
}
free(recv_buf);

if (recbytes <= 0) {
printf("C > read data fail!\n");
}
}
}

void task3(void *pvParameters)
{
while (1) {
struct sockaddr_in server_addr, client_addr;
int server_sock, client_sock;
socklen_t sin_size;
bzero(&server_addr, sizeof(struct sockaddr_in));
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(80);

int recbytes;

do {
if (-1 == (server_sock = socket(AF_INET, SOCK_STREAM, 0))) {
printf("S > socket error\n");
break;
}

printf("S > create socket: %d\n", server_sock);

if (-1 == bind(server_sock, (struct sockaddr *)(&server_addr), sizeof(struct sockaddr))) {
printf("S > bind fail\n");
break;
}

printf("S > bind port: %d\n", ntohs(server_addr.sin_port));

if (-1 == listen(server_sock, 5)) {
printf("S > listen fail\n");
break;
}

printf("S > listen ok\n");

sin_size = sizeof(client_addr);

for (;;) {
printf("S > wait client\n");

if ((client_sock = accept(server_sock, (struct sockaddr *) &client_addr, &sin_size)) < 0) {
printf("S > accept fail\n");
continue;
}

printf("S > Client from %s %d\n", inet_ntoa(client_addr.sin_addr), htons(client_addr.sin_port));

char *recv_buf = (char *)zalloc(128);
while ((recbytes = read(client_sock , recv_buf, 128)) > 0) {
recv_buf[recbytes] = 0;
printf("S > read data success %d!\nS > %s\n", recbytes, recv_buf);
}
free(recv_buf);

if (recbytes <= 0) {
printf("S > read data fail!\n");
close(client_sock);
}
}
} while (0);
}
}

/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_init(void)
{
//printf("SDK version:%s\n", system_get_sdk_version());

/* need to set opmode before you set config */
wifi_set_opmode(STATIONAP_MODE);

{
struct station_config *config = (struct station_config *)zalloc(sizeof(struct station_config));
sprintf(config->ssid, "CVR100W_T");
sprintf(config->password, "justfortest");

/* need to sure that you are in station mode first,
* otherwise it will be failed. */
wifi_station_set_config(config);
free(config);
}

{
struct ip_info ipinfo;

ipinfo.gw.addr = ipaddr_addr("192.168.145.253");
ipinfo.ip.addr = ipaddr_addr("192.168.145.253");
ipinfo.netmask.addr = ipaddr_addr("255.255.255.0");

wifi_set_ip_info(SOFTAP_IF, &ipinfo);
}

{
struct dhcp_info *pdhcp_info = NULL;

pdhcp_info = (struct dhcp_info *)zalloc(sizeof(struct dhcp_info));
pdhcp_info->start_ip = ipaddr_addr("192.168.145.100");
pdhcp_info->end_ip = ipaddr_addr("192.168.145.110"); // don't set the range too large, because it will cost memory.
pdhcp_info->max_leases = 10;
pdhcp_info->auto_time = 60;
pdhcp_info->decline_time = 60;
pdhcp_info->conflict_time = 60;
pdhcp_info->offer_time = 60;
pdhcp_info->min_lease_sec = 60;
dhcp_set_info(pdhcp_info);
free(pdhcp_info);
}

udhcpd_start();

xTaskCreate(task2, "tsk2", 256, NULL, 2, NULL);
xTaskCreate(task3, "tsk3", 256, NULL, 2, NULL);
}