Skip to content

Commit 53362d3

Browse files
committed
Add individual example for briki boards
1 parent 035c8cd commit 53362d3

File tree

12 files changed

+352
-20
lines changed

12 files changed

+352
-20
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ python:
55

66
env:
77
- PLATFORMIO_PROJECT_DIR=examples/arduino-blink
8+
- PLATFORMIO_PROJECT_DIR=examples/arduino-briki-internal-libs
89
- PLATFORMIO_PROJECT_DIR=examples/arduino-wifiscan
910
- PLATFORMIO_PROJECT_DIR=examples/espidf-arduino-blink
1011
- PLATFORMIO_PROJECT_DIR=examples/espidf-arduino-wifiscan

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ environment:
33

44
matrix:
55
- PLATFORMIO_PROJECT_DIR: "examples/arduino-blink"
6+
- PLATFORMIO_PROJECT_DIR: "examples/arduino-briki-internal-libs"
67
- PLATFORMIO_PROJECT_DIR: "examples/arduino-wifiscan"
78
- PLATFORMIO_PROJECT_DIR: "examples/espidf-arduino-blink"
89
- PLATFORMIO_PROJECT_DIR: "examples/espidf-arduino-wifiscan"

examples/arduino-blink/platformio.ini

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@
77
; Please visit documentation for the other options and examples
88
; http://docs.platformio.org/page/projectconf.html
99

10-
[env:briki_abc_esp32]
11-
platform = espressif32
12-
board = briki_abc_esp32
13-
framework = arduino
14-
15-
[env:briki_mbc-wb_esp32]
16-
platform = espressif32
17-
board = briki_mbc-wb_esp32
18-
framework = arduino
19-
2010
[env:esp wrover kit]
2111
platform = espressif32
2212
framework = arduino
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.pioenvs
2+
.piolibdeps
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. Copyright 2014-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-espressif32/archive/develop.zip>`_
17+
3. Extract ZIP archive
18+
4. Run these commands:
19+
20+
.. code-block:: bash
21+
22+
# Change directory to example
23+
> cd platform-espressif32/examples/arduino-briki-internal-libs
24+
25+
# Build project
26+
> platformio run
27+
28+
# Upload firmware
29+
> platformio run --target upload
30+
31+
# Build specific environment
32+
> platformio run -e briki_abc_esp32
33+
34+
# Upload firmware for the specific environment
35+
> platformio run -e briki_abc_esp32 --target upload
36+
37+
# Clean build files
38+
> 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: 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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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:briki_abc_esp32]
11+
platform = espressif32
12+
board = briki_abc_esp32
13+
framework = arduino
14+
15+
[env:briki_mbc-wb_esp32]
16+
platform = espressif32
17+
board = briki_mbc-wb_esp32
18+
framework = arduino
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
WiFiTelnetToSerial - Example Transparent UART to Telnet Server for ESP32
3+
4+
Copyright (c) 2017 Hristo Gochkov. All rights reserved.
5+
This file is part of the ESP32 WiFi library for Arduino environment.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
21+
#include <WiFi.h>
22+
#include <WiFiMulti.h>
23+
24+
WiFiMulti wifiMulti;
25+
26+
//how many clients should be able to telnet to this ESP32
27+
#define MAX_SRV_CLIENTS 1
28+
const char* ssid = "**********";
29+
const char* password = "**********";
30+
31+
WiFiServer server(23);
32+
WiFiClient serverClients[MAX_SRV_CLIENTS];
33+
34+
void setup() {
35+
Serial.begin(115200);
36+
Serial.println("\nConnecting");
37+
38+
wifiMulti.addAP(ssid, password);
39+
wifiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2");
40+
wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3");
41+
42+
Serial.println("Connecting Wifi ");
43+
for (int loops = 10; loops > 0; loops--) {
44+
if (wifiMulti.run() == WL_CONNECTED) {
45+
Serial.println("");
46+
Serial.print("WiFi connected ");
47+
Serial.print("IP address: ");
48+
Serial.println(WiFi.localIP());
49+
break;
50+
}
51+
else {
52+
Serial.println(loops);
53+
delay(1000);
54+
}
55+
}
56+
if (wifiMulti.run() != WL_CONNECTED) {
57+
Serial.println("WiFi connect failed");
58+
delay(1000);
59+
ESP.restart();
60+
}
61+
62+
//start UART and the server
63+
Serial2.begin(9600);
64+
server.begin();
65+
server.setNoDelay(true);
66+
67+
Serial.print("Ready! Use 'telnet ");
68+
Serial.print(WiFi.localIP());
69+
Serial.println(" 23' to connect");
70+
}
71+
72+
void loop() {
73+
uint8_t i;
74+
if (wifiMulti.run() == WL_CONNECTED) {
75+
//check if there are any new clients
76+
if (server.hasClient()){
77+
for(i = 0; i < MAX_SRV_CLIENTS; i++){
78+
//find free/disconnected spot
79+
if (!serverClients[i] || !serverClients[i].connected()){
80+
if(serverClients[i]) serverClients[i].stop();
81+
serverClients[i] = server.available();
82+
if (!serverClients[i]) Serial.println("available broken");
83+
Serial.print("New client: ");
84+
Serial.print(i); Serial.print(' ');
85+
Serial.println(serverClients[i].remoteIP());
86+
break;
87+
}
88+
}
89+
if (i >= MAX_SRV_CLIENTS) {
90+
//no free/disconnected spot so reject
91+
server.available().stop();
92+
}
93+
}
94+
//check clients for data
95+
for(i = 0; i < MAX_SRV_CLIENTS; i++){
96+
if (serverClients[i] && serverClients[i].connected()){
97+
if(serverClients[i].available()){
98+
//get data from the telnet client and push it to the UART
99+
while(serverClients[i].available()) Serial2.write(serverClients[i].read());
100+
}
101+
}
102+
else {
103+
if (serverClients[i]) {
104+
serverClients[i].stop();
105+
}
106+
}
107+
}
108+
//check UART for data
109+
if(Serial2.available()){
110+
size_t len = Serial2.available();
111+
uint8_t sbuf[len];
112+
Serial2.readBytes(sbuf, len);
113+
//push UART data to all connected telnet clients
114+
for(i = 0; i < MAX_SRV_CLIENTS; i++){
115+
if (serverClients[i] && serverClients[i].connected()){
116+
serverClients[i].write(sbuf, len);
117+
delay(1);
118+
}
119+
}
120+
}
121+
}
122+
else {
123+
Serial.println("WiFi not connected!");
124+
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
125+
if (serverClients[i]) serverClients[i].stop();
126+
}
127+
delay(1000);
128+
}
129+
}

0 commit comments

Comments
 (0)