Skip to content

Commit 011a55d

Browse files
committed
ESP32 Projects have been added
1 parent 93db026 commit 011a55d

File tree

12 files changed

+565
-0
lines changed

12 files changed

+565
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch

.vscode/extensions.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"platformio.platformio-ide"
6+
],
7+
"unwantedRecommendations": [
8+
"ms-vscode.cpptools-extension-pack"
9+
]
10+
}

include/README

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

lib/README

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 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

lib/switchKaKu/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# switchKaKu
2+
Arduino library for switching with the new KaKu (Klik aan Klik uit) protocol
3+
4+
Usage: switchKaku(int pin, unsigned long id, int group, int dev, bool state, int repeat, int dimlevel)
5+
- pin = pin number
6+
- id = unique id of transmitter (between 1 and 67108863)
7+
- group = between 1 and 4,
8+
- device = between 1 and 4, -1 switches the entire group
9+
- state = true (on) or false (off)
10+
- repeat = transmit repeats
11+
- dimlevel = -1 (no dimmer), between 0 and 15 for the dimlevel
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
/* This example switches KaKu device op pin 4
3+
* every 5 seconds on/off
4+
* device id = 1 and group id = 1
5+
* unique id of the simulated transmitter is 1234
6+
*/
7+
8+
#include "switchKaKu.h"
9+
#define TRANSMITTERID1 14881086
10+
#define TRANSMITTERID2 10469306
11+
12+
void setup() {
13+
Serial.begin(115200);
14+
}
15+
16+
void loop() {
17+
switchKaku(4, TRANSMITTERID2, 1, 4, true, 3, 8); //switch group 1, device 4, dimlevel 8 (max 15), repeat 3, on
18+
switchKaku(4, TRANSMITTERID1, 1, 1, true, 3); //switch group 1, device 1, repeat 3, on
19+
delay(5000);
20+
switchKaku(4, TRANSMITTERID2, 1, 4, false, 3); //switch group 1, device 4, repeat 3, off
21+
switchKaku(4, TRANSMITTERID1, 1, 1, false, 3); //switch group 1, device 1, repeat 3, off
22+
delay(5000);
23+
}
24+

lib/switchKaKu/switchKaKu.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* Switch Klik aan/Klik uit switches transmitter
2+
* Usage: switchKaku(int pin, unsigned long id, int group, int dev, bool state, int repeat)
3+
* pin = pin number
4+
* id = unique id of transmitter (max 4194303)
5+
* group = between 1 and 4,
6+
* device = between 1 and 4, -1 switches the entire group
7+
* state = true (on) or false (off)
8+
* repeat = transmit repeats
9+
* dimlevel = -1 (no dimmer), between 0 and 15 for the dimlevel
10+
*/
11+
#include "switchKaKu.h"
12+
13+
void switchKaku(int pin, unsigned long id, int group, int dev, bool state, int repeat, int dimlevel){
14+
if (dev == -1){
15+
dev = 1<<5;
16+
} else {
17+
dev -= 1;
18+
}
19+
if (dimlevel == -1) {
20+
sendKakuCode(pin, ((id<<6|dev)|state<<4)|(group-1)<<2, repeat);
21+
} else {
22+
sendKakuDimCode(pin, id, (((dev<<4)|state<<8)|(group-1)<<6)|dimlevel, repeat);
23+
}
24+
}
25+
26+
void sendKakuCode(int pin, unsigned long code, int repeat){
27+
int period = 230;
28+
pinMode(pin, OUTPUT);
29+
for (int j = 0; j < repeat; j++){
30+
sendSyc(pin, period);
31+
for (int i = 31; i>=0; i--){
32+
sendBit(((code & (1<<i))==(1<<i)), pin, period);
33+
}
34+
digitalWrite(pin,HIGH);
35+
delayMicroseconds(period);
36+
digitalWrite(pin, LOW);
37+
}
38+
}
39+
40+
void sendKakuDimCode(int pin, unsigned long id, unsigned long code, int repeat){
41+
int period = 230;
42+
pinMode(pin, OUTPUT);
43+
for (int j = 0; j < repeat; j++){
44+
sendSyc(pin, period);
45+
for (int i = 25; i>=0; i--){
46+
sendBit(((id & (1<<i))==(1<<i)), pin, period);
47+
}
48+
for (int i = 9; i>=0; i--){
49+
if (i == 8) {
50+
sendBit(-1, pin, period);
51+
} else {
52+
sendBit(((code & (1<<i))==(1<<i)), pin, period);
53+
}
54+
}
55+
digitalWrite(pin,HIGH);
56+
delayMicroseconds(period);
57+
digitalWrite(pin, LOW);
58+
};
59+
}
60+
61+
62+
void sendSyc(int pin, int period){
63+
digitalWrite(pin, LOW);
64+
delayMicroseconds(47*period);
65+
digitalWrite(pin,HIGH);
66+
delayMicroseconds(period);
67+
digitalWrite(pin, LOW);
68+
delayMicroseconds(period*12);
69+
70+
}
71+
72+
void sendBit(int value, int pin, int period){
73+
if (value == 0){
74+
digitalWrite(pin,HIGH);
75+
delayMicroseconds(period);
76+
digitalWrite(pin, LOW);
77+
delayMicroseconds(period*1.4);
78+
digitalWrite(pin,HIGH);
79+
delayMicroseconds(period);
80+
digitalWrite(pin, LOW);
81+
delayMicroseconds(period*6);
82+
} else if (value == 1) {
83+
digitalWrite(pin,HIGH);
84+
delayMicroseconds(period);
85+
digitalWrite(pin, LOW);
86+
delayMicroseconds(period*6);
87+
digitalWrite(pin,HIGH);
88+
delayMicroseconds(period);
89+
digitalWrite(pin, LOW);
90+
delayMicroseconds(period*1.4);
91+
} else {
92+
digitalWrite(pin,HIGH);
93+
delayMicroseconds(period);
94+
digitalWrite(pin, LOW);
95+
delayMicroseconds(period*1.4);
96+
digitalWrite(pin,HIGH);
97+
delayMicroseconds(period);
98+
digitalWrite(pin, LOW);
99+
delayMicroseconds(period*1.4);
100+
}
101+
}

lib/switchKaKu/switchKaKu.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Switch Klik aan/Klik uit switches transmitter
2+
* Usage: switchKaku(int pin, unsigned long id, int group, int dev, bool state, int repeat)
3+
* pin = pin number
4+
* id = unique id of transmitter (max 4194303)
5+
* group = between 1 and 4,
6+
* device = between 1 and 4, -1 switches the entire group
7+
* state = true (on) or false (off)
8+
* repeat = transmit repeats
9+
*/
10+
11+
#include "Arduino.h"
12+
13+
void switchKaku(int pin, unsigned long id, int group, int dev, bool state, int repeat, int dimlevel = -1);
14+
void sendKakuCode(int pin, unsigned long code, int repeat);
15+
void sendBit(int value, int pin, int period);
16+
void sendSyc(int pin, int period);
17+
void sendKakuDimCode(int pin, unsigned long id, unsigned long code, int repeat);

main2.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <WiFi.h>
2+
#include <WebServer.h>
3+
#include "DHT.h"
4+
5+
#define DHTPIN 25
6+
#define DHTTYPE DHT11
7+
8+
DHT dht(DHTPIN, DHTTYPE);
9+
10+
const char* ssid = "iPhone";
11+
const char* password = "12341234";
12+
13+
WebServer server(80); // Object to handle HTTP requests
14+
15+
// Define handleRoot before setup
16+
void handleRoot() {
17+
float h = dht.readHumidity();
18+
float t = dht.readTemperature();
19+
20+
String html = "<!DOCTYPE html><html><head><title>ESP32 DHT11 Sensor</title></head><body><h1>DHT11 Sensor Data</h1>";
21+
html += "<p>Temperature: " + String(t) + "°C</p>";
22+
html += "<p>Humidity: " + String(h) + "%</p>";
23+
html += "</body></html>";
24+
25+
server.send(200, "text/html", html);
26+
}
27+
28+
void setup() {
29+
Serial.begin(9600);
30+
dht.begin();
31+
32+
WiFi.begin(ssid, password);
33+
while (WiFi.status() != WL_CONNECTED) {
34+
delay(500);
35+
Serial.println("Connecting to WiFi..");
36+
}
37+
Serial.println("Connected to the WiFi network");
38+
39+
server.on("/", handleRoot); // Define the route for the root URL
40+
server.begin(); // Start the server
41+
Serial.println("HTTP server started");
42+
}
43+
44+
void loop() {
45+
server.handleClient();
46+
}

platformio.ini

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
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:esp32doit-devkit-v1]
12+
platform = espressif32
13+
board = esp32doit-devkit-v1
14+
framework = arduino
15+
lib_deps =
16+
adafruit/Adafruit Unified Sensor@^1.1.14
17+
adafruit/DHT sensor library@^1.4.6
18+
arduino-libraries/Ethernet@^2.0.2

0 commit comments

Comments
 (0)