Initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
# -*- yaml -*-
|
||||||
|
|
||||||
|
---
|
||||||
|
BasedOnStyle: WebKit
|
||||||
|
IndentWidth: 4
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments: true
|
||||||
|
|
||||||
|
AllowAllArgumentsOnNextLine: false
|
||||||
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
IndentPPDirectives: BeforeHash
|
||||||
|
|
||||||
|
BraceWrapping:
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: true
|
||||||
|
BeforeCatch: true
|
||||||
|
BeforeElse: true
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BreakInheritanceList: BeforeComma
|
||||||
|
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
NamespaceIndentation: None
|
||||||
|
FixNamespaceComments: true
|
||||||
|
Standard: c++20
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: AlignWithSpaces
|
||||||
|
...
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
* Powerbutton
|
||||||
|
|
||||||
|
** Init
|
||||||
|
|
||||||
|
platformio init --board esp32-c3-devkitm-1
|
||||||
|
|
||||||
|
** Build
|
||||||
|
|
||||||
|
platformio run
|
||||||
|
|
||||||
|
** Upload
|
||||||
|
|
||||||
|
platformio run --target upload
|
||||||
|
|
||||||
|
** Console
|
||||||
|
|
||||||
|
platformio device monitor
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.pio
|
||||||
|
|
||||||
|
src/secrets.h
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into the executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a separate directory
|
||||||
|
("lib/your_library_name/[Code]").
|
||||||
|
|
||||||
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
Example contents of `src/main.c` using Foo and Bar:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries by scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32-c3-devkitm-1]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32-c3-devkitm-1
|
||||||
|
board_build.mcu = esp32c3
|
||||||
|
framework = arduino
|
||||||
|
|
||||||
|
build_flags =
|
||||||
|
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||||
|
-DARDUINO_USB_MODE=1
|
||||||
|
-DARDUINO_TINYUSB=1
|
||||||
|
-DCORE_DEBUG_LEVEL=5 ; set the debug level (0-5, with 5 being the most verbose)
|
||||||
|
|
||||||
|
lib_deps =
|
||||||
|
|
||||||
|
monitor_filters =
|
||||||
|
esp32_exception_decoder
|
||||||
|
time ; add timestamp with milliseconds for each new line
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WiFiClient.h>
|
||||||
|
|
||||||
|
#include "secrets.h"
|
||||||
|
|
||||||
|
// Default IP address = 192.168.4.1
|
||||||
|
|
||||||
|
#define HOST "192.168.4.1"
|
||||||
|
#define PORT 1234
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(9600);
|
||||||
|
Serial.setDebugOutput(true);
|
||||||
|
|
||||||
|
pinMode(2, OUTPUT);
|
||||||
|
|
||||||
|
// Wait for a USB connection to be established
|
||||||
|
while (!Serial)
|
||||||
|
(void)0;
|
||||||
|
delay(1000);
|
||||||
|
Serial.println("Client booted!");
|
||||||
|
|
||||||
|
// Connect to button server
|
||||||
|
WiFi.begin(SSID, PASSWORD);
|
||||||
|
Serial.print("Connecting");
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.println("\nConnected to AP");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
digitalWrite(2, HIGH);
|
||||||
|
delay(500);
|
||||||
|
digitalWrite(2, LOW);
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.println("ESP32 loopy!");
|
||||||
|
|
||||||
|
WiFiClient client;
|
||||||
|
if (client.connect(HOST, PORT)) {
|
||||||
|
client.print("button_pressed\n");
|
||||||
|
Serial.println("Sent button press");
|
||||||
|
|
||||||
|
while (client.connected()) {
|
||||||
|
if (client.available()) {
|
||||||
|
// Wait for acknowledgment from the receiver
|
||||||
|
String response = client.readStringUntil('\n');
|
||||||
|
if (response == "ACK") {
|
||||||
|
Serial.println("Received ACK");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(2000);
|
||||||
|
client.stop();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.println("Connection failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define SSID "EXAMPLE"
|
||||||
|
#define PASSWORD "12345678"
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
.PHONY: server server-log server-run client client-log client-run
|
||||||
|
|
||||||
|
server:
|
||||||
|
@-cd server ; \
|
||||||
|
platformio run --target upload ; \
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
server-log:
|
||||||
|
@-cd server ; \
|
||||||
|
platformio device monitor ; \
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
server-run:
|
||||||
|
@-cd server ; \
|
||||||
|
platformio run --target upload ; \
|
||||||
|
platformio device monitor ; \
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
client:
|
||||||
|
@-cd client ; \
|
||||||
|
platformio run --target upload ; \
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
client-log:
|
||||||
|
@-cd client ; \
|
||||||
|
platformio device monitor ; \
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
client-run:
|
||||||
|
@-cd client ; \
|
||||||
|
platformio run --target upload ; \
|
||||||
|
platformio device monitor ; \
|
||||||
|
cd ..
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.pio
|
||||||
|
|
||||||
|
src/secrets.h
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into the executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a separate directory
|
||||||
|
("lib/your_library_name/[Code]").
|
||||||
|
|
||||||
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
Example contents of `src/main.c` using Foo and Bar:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries by scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32-c3-devkitm-1]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32-c3-devkitm-1
|
||||||
|
board_build.mcu = esp32c3
|
||||||
|
framework = arduino
|
||||||
|
|
||||||
|
build_flags =
|
||||||
|
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||||
|
-DARDUINO_USB_MODE=1
|
||||||
|
-DARDUINO_TINYUSB=1
|
||||||
|
-DCORE_DEBUG_LEVEL=5 ; set the debug level (0-5, with 5 being the most verbose)
|
||||||
|
|
||||||
|
lib_deps =
|
||||||
|
|
||||||
|
monitor_filters =
|
||||||
|
esp32_exception_decoder
|
||||||
|
time ; add timestamp with milliseconds for each new line
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WiFiClient.h>
|
||||||
|
#include <WiFiServer.h>
|
||||||
|
|
||||||
|
#include "secrets.h"
|
||||||
|
|
||||||
|
// Default IP address = 192.168.4.1
|
||||||
|
|
||||||
|
#define PORT 1234
|
||||||
|
#define CHANNEL 11
|
||||||
|
#define HIDDEN true
|
||||||
|
#define MAX_CONNECTION 1
|
||||||
|
|
||||||
|
WiFiServer server(PORT);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(9600);
|
||||||
|
Serial.setDebugOutput(true);
|
||||||
|
|
||||||
|
pinMode(2, OUTPUT);
|
||||||
|
|
||||||
|
// Wait for a USB connection to be established
|
||||||
|
while (!Serial)
|
||||||
|
(void)0;
|
||||||
|
delay(3000);
|
||||||
|
Serial.println("Server booted!");
|
||||||
|
|
||||||
|
// Start button server
|
||||||
|
WiFi.softAP(SSID, PASSWORD, CHANNEL, HIDDEN, MAX_CONNECTION);
|
||||||
|
Serial.println("AP Started");
|
||||||
|
server.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
digitalWrite(2, HIGH);
|
||||||
|
delay(500);
|
||||||
|
digitalWrite(2, LOW);
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
Serial.println("ESP32 loopy!");
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
|
WiFiClient client = server.available();
|
||||||
|
if (client) {
|
||||||
|
Serial.println("Client connected");
|
||||||
|
|
||||||
|
// unsigned long start = 0;
|
||||||
|
while (client.connected()) {
|
||||||
|
if (client.available()) {
|
||||||
|
String msg = client.readStringUntil('\n');
|
||||||
|
Serial.print("Received: ");
|
||||||
|
Serial.println(msg);
|
||||||
|
|
||||||
|
// Do something with the message, like toggling an LED
|
||||||
|
|
||||||
|
client.print("ACK\n");
|
||||||
|
Serial.println("Sent ACK");
|
||||||
|
// start = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Kill lingering connections
|
||||||
|
// if (start != 0 && millis() - start < 1000) {
|
||||||
|
// Serial.println("Client kill..");
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
client.stop();
|
||||||
|
Serial.println("Client disconnected");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define SSID "EXAMPLE"
|
||||||
|
#define PASSWORD "12345678"
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
Reference in New Issue
Block a user