Skip to content

Commit

Permalink
General purpose WIN32 examples added
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Jan 27, 2018
1 parent 40cb96f commit 9baf107
Show file tree
Hide file tree
Showing 58 changed files with 2,903 additions and 0 deletions.
Binary file added dev/VisualStudio/esp_dev_os/log_file.txt
Binary file not shown.
115 changes: 115 additions & 0 deletions dev/VisualStudio/esp_dev_os/log_file_check_it.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
+LINK_CONN:0,0,"TCP",1,"192.168.0.14",59238,80

+IPD,0,465,192.168.0.14,59238:GET / HTTP/1.1
Host: 192.168.0.13
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://192.168.0.13/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: __lnkrntdmcvrd=-1

AT+CIPSEND=0,2048

OK
>
Recv 2048 bytes

SEND OK
AT+CIPSEND=0,1936

OK
>
Recv 1936 bytes

SEND OK
+LINK_CONN:0,1,"TCP",1,"192.168.0.14",59239,80

+IPD,1,336,192.168.0.14,59239:GET /js/js1.js HTTP/1.1
Host: 192.168.0.13
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept: */*
Referer: http://192.168.0.13/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: __lnkrntdmcvrd=-1

+LINK_CONN:0,2,"TCP",1,"192.168.0.14",59240,80

+IPD,2,356,192.168.0.14,59240:GET /css/style1.css HTTP/1.1
Host: 192.168.0.13
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept: text/css,*/*;q=0.1
Referer: http://192.168.0.13/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: __lnkrntdmcvrd=-1

AT+CIPCLOSE=0
0,CLOSED

OK
AT+CIPSEND=1,147

OK
>
Recv 147 bytes

SEND OK
AT+CIPSEND=2,449

OK
>
Recv 449 bytes

SEND OK
AT+CIPCLOSE=1
1,CLOSED

OK
AT+CIPCLOSE=2
2,CLOSED

OK
+LINK_CONN:0,0,"TCP",1,"192.168.0.14",59241,80

+IPD,0,465,192.168.0.14,59241:GET / HTTP/1.1
Host: 192.168.0.13
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://192.168.0.13/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: __lnkrntdmcvrd=-1

AT+CIPSEND=0,2048

OK
>
Recv 2048 bytes

SEND OK
AT+CIPSEND=0,1936

OK
>
Recv 1936 bytes

SEND OK
+LINK_CONN:0,1,"TCP",1,"192.168.0.14",59242,80

+IPD,1,336,192.168.0.14,59242:GET /js/js1.js HTTP/1.1
Host: 192.168.0.13
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Geckoome/63.0.3239.132 Safari/537.36
Accept: */*
Referer: http://192.168.0.13/
Accept-Encoding: gz
Expand Down
Binary file not shown.
Binary file not shown.
40 changes: 40 additions & 0 deletions examples/win32/client_rtos/project/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
========================================================================
CONSOLE APPLICATION : project Project Overview
========================================================================

AppWizard has created this project application for you.

This file contains a summary of what you will find in each of the files that
make up your project application.


project.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.

project.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).

project.cpp
This is the main application source file.

/////////////////////////////////////////////////////////////////////////////
Other standard files:

StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named project.pch and a precompiled types file named StdAfx.obj.

/////////////////////////////////////////////////////////////////////////////
Other notes:

AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.

/////////////////////////////////////////////////////////////////////////////
54 changes: 54 additions & 0 deletions examples/win32/client_rtos/project/esp_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* \file esp_config.h
* \brief Configuration file
*/

/*
* Copyright (c) 2018 Tilen Majerle
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 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 AUTHORS 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 IN THE SOFTWARE.
*
* This file is part of ESP-AT.
*
* Author: Tilen MAJERLE <[email protected]>
*/
#ifndef __ESP_CONFIG_H
#define __ESP_CONFIG_H

/*
* Rename this file to "esp_config.h" for your application
*/

/* First include debug before any config changes */
#include "esp/esp_debug.h"

/*
* Check default configuration settings for more information
*/
#define ESP_CFG_SYS_PORT ESP_SYS_PORT_WIN32
#define ESP_CFG_INPUT_USE_PROCESS 1

#define ESP_CFG_NETCONN 1

/* After user configuration, call default config to merge config together */
#include "esp/esp_config_default.h"

#endif /* __ESP_CONFIG_H */
Binary file added examples/win32/client_rtos/project/log_file.txt
Binary file not shown.
159 changes: 159 additions & 0 deletions examples/win32/client_rtos/project/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
* \file main.c
* \brief Main file
*/

/*
* Copyright (c) 2018 Tilen Majerle
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 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 AUTHORS 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 IN THE SOFTWARE.
*
* This file is part of ESP-AT.
*
* Before you start using WIN32 implementation with USB and VCP,
* check esp_ll_win32.c implementation and choose your COM port!
*/
#include "stdafx.h"
#include "esp/esp.h"
#include "station_manager.h"
#include "netconn_client.h"

static espr_t esp_callback_func(esp_cb_t* cb);
static espr_t esp_conn_callback_func(esp_cb_t* cb);

#define CONN_HOST "example.com"
#define CONN_PORT 80

/**
* \brief Minimal connection request
*/
static const uint8_t
request_data[] = ""
"GET / HTTP/1.1\r\n"
"Host: " CONN_HOST "\r\n"
"\r\n";

/**
* \brief Program entry point
*/
int
main(void) {
printf("Starting ESP application!\r\n");

/*
* Initialize ESP with default callback function
*/
esp_init(esp_callback_func);

/*
* Connect to access point.
*
* Try unlimited time until access point accepts up.
* Check for station_manager.c to define preferred access points ESP should connect to
*/
connect_to_preferred_access_point(1);

/*
* Start new connections to example.com
*
* Use non-blocking method and process further data in callback function
*/
esp_conn_start(NULL, ESP_CONN_TYPE_TCP, CONN_HOST, CONN_PORT, NULL, esp_conn_callback_func, 0);
esp_conn_start(NULL, ESP_CONN_TYPE_TCP, CONN_HOST, CONN_PORT, NULL, esp_conn_callback_func, 0);

/*
* An example of connection which should fail in connecting.
* In this case, \ref ESP_CB_CONN_ERROR event should be triggered
* in callback function processing
*/
esp_conn_start(NULL, ESP_CONN_TYPE_TCP, CONN_HOST, 10, NULL, esp_conn_callback_func, 0);

/*
* Do not stop program here as we still need to wait
* for commands to be processed
*/
while (1) {
esp_delay(1000);
}

return 0;
}

/**
* \brief Callback function for connection events
* \param[in] cb: Event information with data
* \return espOK on success, member of \ref espr_t otherwise
*/
static espr_t
esp_conn_callback_func(esp_cb_t* cb) {
esp_conn_p conn;

conn = esp_conn_get_from_evt(cb); /* Get connection handle from event */
switch (cb->type) {
case ESP_CB_CONN_ACTIVE: { /* Connection just active */
printf("Connection %d active!\r\n", (int)esp_conn_getnum(conn));
printf("Sending data on connection %d to remote server\r\n", (int)esp_conn_getnum(conn));
esp_conn_send(conn, request_data, sizeof(request_data) - 1, NULL, 0);
break;
}
case ESP_CB_CONN_DATA_RECV: { /* Connection data received */
esp_pbuf_p p;
p = cb->cb.conn_data_recv.buff; /* Get received buffer */
if (p != NULL) {
printf("Connection %d data received with %d bytes\r\n",
(int)esp_conn_getnum(conn), (int)esp_pbuf_length(p, 1));
}
break;
}
case ESP_CB_CONN_CLOSED: { /* Connection closed */
printf("Connection %d closed!\r\n", (int)esp_conn_getnum(conn));
break;
}
case ESP_CB_CONN_ERROR: { /* Error connecting to server */
const char* host = cb->cb.conn_error.host;
esp_port_t port = cb->cb.conn_error.port;
printf("Error connecting to %s:%d\r\n", host, (int)port);
break;
}
}
return espOK;
}

/**
* \brief Event callback function for ESP stack
* \param[in] cb: Event information with data
* \return espOK on success, member of \ref espr_t otherwise
*/
static espr_t
esp_callback_func(esp_cb_t* cb) {
switch (cb->type) {
case ESP_CB_INIT_FINISH: {
printf("Device initialized!\r\n");
break;
}
case ESP_CB_RESET: {
printf("Device reset!\r\n");
break;
}
default: break;
}
return espOK;
}
Loading

0 comments on commit 9baf107

Please sign in to comment.