Skip to content

Commit c217df2

Browse files
authored
Add zephyr civetweb example (#489)
Example from samples/net/sockets/civetweb
1 parent 2a3a83a commit c217df2

File tree

15 files changed

+805
-0
lines changed

15 files changed

+805
-0
lines changed

.github/workflows/examples.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ jobs:
5151
- "examples/zephyr-blink"
5252
- "examples/zephyr-cpp-synchronization"
5353
- "examples/zephyr-drivers-can"
54+
- "examples/zephyr-net-civetweb"
5455
- "examples/zephyr-net-https-client"
5556
- "examples/zephyr-subsys-usb-hid-mouse"
5657
- "tests/arduino-blink-different-cores"
5758
exclude:
5859
- {python-version: 2.7, example: "examples/zephyr-blink"}
5960
- {python-version: 2.7, example: "examples/zephyr-cpp-synchronization"}
6061
- {python-version: 2.7, example: "examples/zephyr-drivers-can"}
62+
- {python-version: 2.7, example: "examples/zephyr-net-civetweb"}
6163
- {python-version: 2.7, example: "examples/zephyr-net-https-client"}
6264
- {python-version: 2.7, example: "examples/zephyr-subsys-usb-hid-mouse"}
6365
runs-on: ${{ matrix.os }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.pio
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Continuous Integration (CI) is the practice, in software
2+
# engineering, of merging all developer working copies with a shared mainline
3+
# several times a day < https://docs.platformio.org/page/ci/index.html >
4+
#
5+
# Documentation:
6+
#
7+
# * Travis CI Embedded Builds with PlatformIO
8+
# < https://docs.travis-ci.com/user/integration/platformio/ >
9+
#
10+
# * PlatformIO integration with Travis CI
11+
# < https://docs.platformio.org/page/ci/travis.html >
12+
#
13+
# * User Guide for `platformio ci` command
14+
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
15+
#
16+
#
17+
# Please choose one of the following templates (proposed below) and uncomment
18+
# it (remove "# " before each line) or use own configuration according to the
19+
# Travis CI documentation (see above).
20+
#
21+
22+
23+
#
24+
# Template #1: General project. Test it using existing `platformio.ini`.
25+
#
26+
27+
# language: python
28+
# python:
29+
# - "2.7"
30+
#
31+
# sudo: false
32+
# cache:
33+
# directories:
34+
# - "~/.platformio"
35+
#
36+
# install:
37+
# - pip install -U platformio
38+
# - platformio update
39+
#
40+
# script:
41+
# - platformio run
42+
43+
44+
#
45+
# Template #2: The project is intended to be used as a library with examples.
46+
#
47+
48+
# language: python
49+
# python:
50+
# - "2.7"
51+
#
52+
# sudo: false
53+
# cache:
54+
# directories:
55+
# - "~/.platformio"
56+
#
57+
# env:
58+
# - PLATFORMIO_CI_SRC=path/to/test/file.c
59+
# - PLATFORMIO_CI_SRC=examples/file.ino
60+
# - PLATFORMIO_CI_SRC=path/to/test/directory
61+
#
62+
# install:
63+
# - pip install -U platformio
64+
# - platformio update
65+
#
66+
# script:
67+
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.. Copyright 2019-present PlatformIO <[email protected]>
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
http://www.apache.org/licenses/LICENSE-2.0
6+
Unless required by applicable law or agreed to in writing, software
7+
distributed under the License is distributed on an "AS IS" BASIS,
8+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
See the License for the specific language governing permissions and
10+
limitations under the License.
11+
12+
How to build PlatformIO based project
13+
=====================================
14+
15+
1. `Install PlatformIO Core <http://docs.platformio.org/page/core.html>`_
16+
2. Download `development platform with examples <https://github.com/platformio/platform-ststm32/archive/develop.zip>`_
17+
3. Extract ZIP archive
18+
4. Change IP configuration in platform-ststm32/examples/zephyr-net-civetweb/zephyr/prj.conf file. Default server IPv4 address: `10.0.0.111`
19+
5. Run these commands:
20+
21+
.. code-block:: bash
22+
23+
# Change directory to example
24+
> cd platform-ststm32/examples/zephyr-net-civetweb
25+
26+
# Build project
27+
> platformio run
28+
29+
# Upload firmware
30+
> platformio run --target upload
31+
32+
# Clean build files
33+
> platformio run --target clean
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2019 Antmicro Ltd
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
static void log_access(const struct mg_connection *conn)
8+
{
9+
const struct mg_request_info *ri;
10+
char src_addr[IP_ADDR_STR_LEN];
11+
12+
if (!conn || !conn->dom_ctx) {
13+
return;
14+
}
15+
16+
ri = &conn->request_info;
17+
18+
sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa);
19+
20+
printf("%s - \"%s %s%s%s HTTP/%s\" %d\n",
21+
src_addr,
22+
ri->request_method ? ri->request_method : "-",
23+
ri->request_uri ? ri->request_uri : "-",
24+
ri->query_string ? "?" : "",
25+
ri->query_string ? ri->query_string : "",
26+
ri->http_version,
27+
conn->status_code);
28+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2019 Antmicro Ltd
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
static void mg_cry_internal_impl(const struct mg_connection *conn,
8+
const char *func,
9+
unsigned line,
10+
const char *fmt,
11+
va_list ap)
12+
{
13+
(void)conn;
14+
15+
printf("[INTERNAL ERROR]: %s @ %d\n", func, line);
16+
vprintf(fmt, ap);
17+
printf("\n");
18+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2019 Antmicro Ltd
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr.h>
8+
#include <string.h>
9+
#include <stdio.h>
10+
#include <sys/types.h>
11+
#include <net/socket.h>
12+
13+
#define pollfd zsock_pollfd
14+
#define fcntl zsock_fcntl
15+
16+
#define POLLIN ZSOCK_POLLIN
17+
#define POLLOUT ZSOCK_POLLOUT
18+
19+
#define addrinfo zsock_addrinfo
20+
21+
#define F_SETFD 2
22+
#define FD_CLOEXEC 1
23+
24+
size_t strcspn(const char *s1, const char *s2);
25+
size_t strspn(const char *s1, const char *s2);
26+
int iscntrl(int c);
27+
28+
double atof(const char *str);
29+
long long int strtoll(const char *str, char **endptr, int base);
30+
int sscanf(const char *s, const char *format, ...);
31+
char *strerror(int err);
32+
unsigned long long int strtoull(const char *str, char **endptr, int base);
33+
34+
time_t time(time_t *t);
35+
struct tm *gmtime(const time_t *ptime);
36+
size_t strftime(char *dst, size_t dst_size, const char *fmt,
37+
const struct tm *tm);
38+
double difftime(time_t end, time_t beg);
39+
struct tm *localtime(const time_t *timer);
40+
41+
int fileno(FILE *stream);
42+
int ferror(FILE *stream);
43+
int fclose(FILE *stream);
44+
int fseeko(FILE *stream, off_t offset, int whence);
45+
FILE *fopen(const char *filename, const char *mode);
46+
char *fgets(char *str, int num, FILE *stream);
47+
size_t fread(void *ptr, size_t size, size_t count, FILE *stream);
48+
int remove(const char *filename);
49+
50+
int getsockname(int sock, struct sockaddr *addr, socklen_t *addrlen);
51+
int poll(struct zsock_pollfd *fds, int nfds, int timeout);
52+
53+
int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
54+
char *host, socklen_t hostlen,
55+
char *serv, socklen_t servlen, int flags);
56+
57+
ssize_t send(int sock, const void *buf, size_t len, int flags);
58+
ssize_t recv(int sock, void *buf, size_t max_len, int flags);
59+
int socket(int family, int type, int proto);
60+
int getaddrinfo(const char *host, const char *service,
61+
const struct zsock_addrinfo *hints,
62+
struct zsock_addrinfo **res);
63+
64+
void freeaddrinfo(struct zsock_addrinfo *ai);
65+
int connect(int sock, const struct sockaddr *addr, socklen_t addrlen);
66+
int getsockopt(int sock, int level, int optname,
67+
void *optval, socklen_t *optlen);
68+
int setsockopt(int sock, int level, int optname,
69+
const void *optval, socklen_t optlen);
70+
int listen(int sock, int backlog);
71+
int accept(int sock, struct sockaddr *addr, socklen_t *addrlen);
72+
int bind(int sock, const struct sockaddr *addr, socklen_t addrlen);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter, extra scripting
4+
; Upload options: custom port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
;
7+
; Please visit documentation for the other options and examples
8+
; http://docs.platformio.org/page/projectconf.html
9+
10+
[env:nucleo_f767zi]
11+
platform = ststm32
12+
framework = zephyr
13+
board = nucleo_f767zi

0 commit comments

Comments
 (0)