87 Commits
Author SHA1 Message Date
bartschdo76253 33499beb32 zero duty cycle fix 2021-06-25 15:41:34 +02:00
bartschdo76253 38c81ae182 main cleanup 2021-06-25 15:25:09 +02:00
bartschdo76253 a8ceb258b8 leds light up at boot 2021-06-25 15:17:38 +02:00
bartschdo76253 7e5a6fac9f doku 2021-06-25 11:03:17 +02:00
bartschdo76253 b7ba521c59 first approach with sensor controlled led sequence 2021-06-25 10:55:27 +02:00
schmidtsi76327 2b2a135bd5 reorganzie main 2021-06-24 19:46:24 +02:00
bartschdo76253 a400b0464d deleted Wire setClock 2021-06-24 19:34:26 +02:00
schmidtsi76327 2d9be85b09 added lib submodule 2021-06-24 18:38:30 +02:00
schmidtsi76327 33b9f0150e nicht so :) 2021-06-24 18:32:38 +02:00
schmidtsi76327 48d0dc50f7 added library 2021-06-24 18:28:00 +02:00
schmidtsi76327 cdb34a3cbf make it clear what happens with new pca lib 2021-06-24 16:51:38 +02:00
schmidtsi76327 1b34714d27 Fehler in PCA Library mit LED flicker 2021-06-24 16:40:19 +02:00
Pupsmuckel 90a9213a3c HTML Änderung 2021-06-24 13:51:12 +02:00
Pupsmuckel 7976f5258f html Änderung 2021-06-24 13:41:20 +02:00
Pupsmuckel bb3a735d37 Html Änderung 2021-06-24 13:08:28 +02:00
Pupsmuckel 3c186771fe Html Änderung 2021-06-24 11:42:12 +02:00
Pupsmuckel c40e7f80e5 Html Änderung 2021-06-24 11:34:05 +02:00
bartschdo76253 9d1105cb80 Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-23 21:25:24 +02:00
bartschdo76253 4130b64370 object oriented stairlight control 2021-06-23 21:23:31 +02:00
schmidtsi76327 bff8cdbeb7 compress errors :) 2021-06-23 17:30:15 +02:00
schmidtsi76327 d8343ea91f Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-23 17:26:28 +02:00
schmidtsi76327 78f09b3a3b compress 2021-06-23 17:26:22 +02:00
schmidtsi76327 bd0e364d22 delete compress files 2021-06-23 17:24:54 +02:00
bartschdo76253 32266b5f37 Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-23 17:20:22 +02:00
schmidtsi76327 b62f4f9f95 changed gitignore 2021-06-23 17:16:16 +02:00
bartschdo76253 a8af7543ba deleted headers 2021-06-23 17:15:22 +02:00
schmidtsi76327 85f8da3476 reorganize 2021-06-23 17:12:44 +02:00
schmidtsi76327 f323bd4cf9 reorganize 2021-06-23 17:12:40 +02:00
Pupsmuckel 708bb2cda4 Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-23 17:01:53 +02:00
Pupsmuckel a4196bb579 Änderung 2021-06-23 17:01:47 +02:00
schmidtsi76327 908c4298be Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-23 17:01:34 +02:00
schmidtsi76327 6e885673b8 e 2021-06-23 17:01:08 +02:00
bartschdo76253 93cc958800 Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-23 16:57:11 +02:00
bartschdo76253 9d30423ca3 variable PWM step calculation 2021-06-23 16:51:15 +02:00
schmidtsi76327 b3b11d0818 reorder main, add ota.h 2021-06-23 16:49:53 +02:00
schmidtsi76327 51bdd6210e changed from include/http to data/ because of littlefs 2021-06-23 16:30:27 +02:00
Pupsmuckel d51bb4c95c Änderung html 2021-06-23 16:29:30 +02:00
schmidtsi76327 2659e366ec Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-23 16:20:45 +02:00
schmidtsi76327 4951ca46c1 delete unnecessary files 2021-06-23 16:19:31 +02:00
schmidtsi76327 97a6076864 delete unnecessary files 2021-06-23 16:18:54 +02:00
schmidtsi76327 ff6b82867c added httpserver with inheritance 2021-06-23 16:12:19 +02:00
Pupsmuckel a3dc7a5fba Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-23 16:09:58 +02:00
Pupsmuckel c13b0adc82 2te Änderung 2021-06-23 16:07:19 +02:00
schmidtsi76327 da20f74db8 „include/http/index.html“ ändern 2021-06-23 14:06:55 +00:00
Pupsmuckel d5b9827543 wichtige Änderung 2021-06-23 16:03:49 +02:00
Pupsmuckel 3c6889854e Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-23 15:58:48 +02:00
Pupsmuckel 8d8ffe4173 änderung an der website 2021-06-23 15:56:27 +02:00
schmidtsi76327 006404fccf ugly hack 2021-06-23 15:22:38 +02:00
schmidtsi76327 d17091651f Merge branch 'littlefs' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht into littlefs 2021-06-23 13:37:59 +02:00
schmidtsi76327 4b608c42ca tryin on win 2021-06-23 13:37:13 +02:00
Simon Schmidt 278f746b33 templ ini 2021-06-23 13:34:54 +02:00
Simon Schmidt 642ee7d0a6 gzip works from FS 2021-06-23 02:13:48 +02:00
Simon Schmidt 6596346d3d ls -l implement and ota fw fix 2021-06-23 01:30:28 +02:00
Simon Schmidt b696703d45 littefs working 2021-06-22 23:38:39 +02:00
Simon Schmidt baecaf02da cleanup 2021-06-22 20:36:53 +02:00
Simon Schmidt 1d7f2f368b debugging support :) over gdbstub 2021-06-22 20:25:27 +02:00
Simon Schmidt c8938f4b36 added webtest.sh for linux 2021-06-22 17:26:58 +02:00
Simon Schmidt cd80b9b7ba add lib PCA9685 locally, because of warnings 2021-06-22 17:22:00 +02:00
Simon Schmidt 657f77e73d test example 2021-06-22 16:12:04 +02:00
Simon Schmidt b51cce709a added test 2021-06-22 15:33:48 +02:00
schmidtsi76327 09aff91b31 Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-21 15:35:20 +02:00
schmidtsi76327 36fd363d67 new 2021-06-21 15:32:38 +02:00
bartschdo76253 ee72092a3a Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-21 14:19:10 +02:00
schmidtsi76327 a66ab2b1d0 add doku.txt 2021-06-21 13:11:24 +02:00
bartschdo76253 6a7f2e6a4e led dimm via timer 2021-06-21 13:11:18 +02:00
schmidtsi76327 49f9c9c217 added software timer 2021-06-21 12:26:52 +02:00
bartschdo76253 61d6cde899 Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-21 11:10:55 +02:00
bartschdo76253 65e922b090 ledsequence updated 2021-06-21 11:10:01 +02:00
schmidtsi76327 461c887ddf Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-21 10:54:30 +02:00
schmidtsi76327 e7cf45c45e added favicon ... 2021-06-21 10:54:28 +02:00
bartschdo76253 055a6193df Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-21 10:53:49 +02:00
bartschdo76253 c6e288280e added ledsequence 2021-06-21 10:48:27 +02:00
schmidtsi76327 d0b824963b add webtest.cmd for python testing of webserver 2021-06-21 09:55:03 +02:00
schmidtsi76327 407581451b d 2021-06-21 09:44:30 +02:00
schmidtsi76327 5443800b40 reorganize main.cpp 2021-06-21 09:43:06 +02:00
schmidtsi76327 769e132baa „templ_platformio_ini“ ändern 2021-06-21 07:23:28 +00:00
schmidtsi76327 b5a5257a37 „template_platformio.ini“ ändern 2021-06-21 07:22:36 +00:00
schmidtsi76327 f317600d03 „platformio.ini“ ändern 2021-06-21 07:18:02 +00:00
schmidtsi76327 306d9721c4 delete wierd gzip 2021-06-21 09:14:10 +02:00
schmidtsi76327 71e5c47852 modify 2021-06-21 09:12:15 +02:00
schmidtsi76327 29e130b837 changed gitignore 2021-06-21 09:08:04 +02:00
schmidtsi76327 36fb748f6d Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-21 09:07:04 +02:00
schmidtsi76327 d4584f57e8 changed gitignore 2021-06-21 09:06:24 +02:00
schmidtsi76327 caff8a7e56 meine Änderung 2021-06-14 16:59:22 +02:00
schmidtsi76327 03d9f87159 added gzip for webpage and preprocessor timing wrapper 2021-06-11 00:01:04 +02:00
schmidtsi76327 dbf2d51769 Merge branch 'master' of https://git.efi.th-nuernberg.de/gitea/schmidtsi76327/ESP8266_Treppenlicht 2021-06-10 20:59:33 +02:00
schmidtsi76327 83e5cba4ec websrc to .h converter 2021-06-10 20:58:48 +02:00
30 changed files with 1056 additions and 261 deletions

No files matched your search

+4 -5
View File
@@ -1,7 +1,6 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.vscode
compress
platformio.ini
include/wifi_credentials.h
platformio.ini
include/*.gz.h
+3
View File
@@ -0,0 +1,3 @@
[submodule "lib/PCA9685-Arduino"]
path = lib/PCA9685-Arduino
url = https://github.com/NachtRaveVL/PCA9685-Arduino
+7 -7
View File
@@ -1,7 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}
+52
View File
@@ -0,0 +1,52 @@
{
"files.associations": {
"random": "cpp",
"array": "cpp",
"*.tcc": "cpp",
"deque": "cpp",
"list": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"string_view": "cpp",
"memory": "cpp",
"ranges": "cpp",
"initializer_list": "cpp",
"utility": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"map": "cpp",
"set": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"iosfwd": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
}
}
+20 -2
View File
@@ -17,5 +17,23 @@ https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html
```
##### platformio.ini
change IP of esp8266 accordingly
IP gets printed on Serial Monitor after first Upload
see templ_platformio_ini
```ini
[env:<BOARD>]
platform = espressif8266
board = <BOARD>
framework = arduino
monitor_speed = 115200
extra_scripts = pre:extra_script.py
; stuff for OTA
; https://docs.platformio.org/en/latest/platforms/espressif8266.html#over-the-air-ota-update
upload_protocol = espota
upload_port = <IPADRESS>
upload_flags =
--port=8266
--auth=admin
```
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/python3
import os, gzip
# https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/
def convert_to_gzip(src, out, f):
input_file = f'{src}{f}'
output_file = f'{out}{f}.gz.h'
output_charp = f'{f.replace(".", "_")}_gz'
top = ''
with open(input_file, 'rb') as f_in:
gz = gzip.compress(f_in.read())
gzlen = len(gz)
top += f'// filename: {f}.gz.h\n'
top += f'#define {output_charp}_len {gzlen}\n'
top += f'const char {output_charp}[] = '
top += '{'
with open(output_file, 'wb') as f_out:
for i, b in enumerate(gz):
if not i%10:
top += '\n '
top += f'0x{b:02X}, '
top = top[:-2]
top += '};'
f_out.write(top.encode(encoding='utf-8'))
src='data/'
out='compress/'
if not 'compress' in os.listdir():
os.mkdir('compress')
for f in os.listdir(src):
convert_to_gzip(src, out, f)
Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

+67
View File
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>ESP8266 Treppenlicht</title>
<!-- main style sheet -->
<link href="/favicon.png" rel="icon" type="image/png" sizes="10x10">
<link href="/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="kopfzeile" style="text-align: center;">
<b>Treppenlicht</b>
</div>
<div class="ueberschrift">
Helligkeit
<!--<label id="label_pwm">
</label>-->
<div class="slider">
<input type="range" class="regler" id="helligkeit" name="rangeInput" min="0" max="100" value="50"
oninput="amount1.value=helligkeit.value">
<br>
<output name="amount1" id="amount1" for="helligkeit">50</output>
</div>
</div>
<div class="ueberschrift">
Helligkeit bei Dunkelheit
<!--<label id="label_pwm_dark">
</label>-->
<div class="slider">
<input type="range" class="regler" id="helligkeit_dunkel" name="rangeInput" min="0" max="100" value="50"
oninput="amount2.value=helligkeit_dunkel.value">
<br>
<output name="amount2" id="amount2" for="helligkeit_dunkel">50</output>
</div>
</div>
<div class="ueberschrift">
Laufgeschwindigkeit
<!--<label id="label_geschwindigkeit">
</label>-->
<div class="slider">
<input type="range" class="regler" id="geschwindigkeit" name="rangeInput" min="0" max="100" value="50"
oninput="amount3.value=geschwindigkeit.value">
<br>
<output name="amount3" id="amount3" for="geschwindigkeit">50</output>
</div>
</div>
<div class="ueberschrift">
Licht-An-Zeit
<!-- <label id="label_time">
</label>-->
<div class="slider">
<input type="range" class="regler" id="time" name="rangeInput" min="0" max="100" value="50"
oninput="amount4.value=time.value">
<br>
<output name="amount4" id="amount4" for="time">50</output>
</div>
</div>
</body>
<script src="/input.js"></script>
</html>
+8
View File
@@ -0,0 +1,8 @@
var slider = document.getElementById("range1");
var output = document.getElementById("l_pwm");
output.innerHTML = slider.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle)
slider.oninput = function() {
output.innerHTML = this.value;
}
+106
View File
@@ -0,0 +1,106 @@
html {
font-size: 16px;
font-family: sans-serif, Arial, Helvetica;
background-color: #d4d4d4;
height: 100%;
background-image: url('Background.png');
background-repeat: repeat;
background-size: 150% 150%;
}
body {
height: 100%;
margin: 0 auto;
border: none;
border-radius: 3;
}
.topbar {
padding: 1em;
background-color: #1f1f1f;
color: white;
font-size: x-large;
text-align: center;
}
.ueberschrift{
color: #ffffff;
font-size: 50px;
width: 100%;
text-align: center;
}
.regler{
-webkit-appearance: none;
height: 30px;
width: 100%;
border-radius: 20px;
outline: black;
background-color: rgb(176, 188, 228);
}
.regler::-webkit-slider-thumb{
-webkit-appearance: none;
appearance: none;
width: 5%;
height: 20px;
border-radius: 10px;
background-color: rgb(107, 122, 192);
cursor:pointer;
}
input[type=range]::-webkit-slider-thumb{
-webkit-appearance: none;
border:none;
height: 30px;
width: 4%;
border-radius: 30px;
}
.slider {
width: 100%;
}
.kopfzeile{
color: #1f1f1f;
font-size: 50px;
width: 100%;
background-color: #8d8a8a;
}
/*-------------------------------------------------------*/
/*Switch:
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
Hide default HTML checkbox
.switch input {
opacity: 0;
width: 0;
height: 0;
}
*/
/* The slider */
/*input:checked + .slider {
background-color: #04AA6D;
}
input:focus + .slider {
box-shadow: 0 0 1px #04AA6D;
}*/
/*
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
+74
View File
@@ -0,0 +1,74 @@
Hardware Timer didnt work https://github.com/khoih-prog/ESP8266TimerInterrupt#why-using-isr-based-hardware-timer-interrupt-is-better
=> Software Timer https://ullisroboterseite.de/esp8266-timing.html#timer
### __Zum aktivieren von GDBStub:__
```c
#include <GDBStub.h>
...
void setup() {
Serial.begin(460800);
gdbstub_init();
```
### __Achtung !__
GDB muss dafür compiled werden
GDB-Version aus Arduino Toolchain hat Support
```sh
$ ./start_xtensa_gdb_stub.sh
```
### __Achtung !__
Don`t forget __\r__
ESP-OTA wird von ufw oder Defender geblockt.
- Windows -> Python needs to be granted with rights
- Linux -> open udp port in ufw ->
```sh
platform.ini
upload_flags =
--host-port <PORT>
...
$ sudo ufw allow tcp/<PORT>
```
```c++
server.streamFile(f, mime::getContentType(SRH::_path), requestMethod);
=====>
const String& p = SRH::_path;
if(p.endsWith(".gzip")) {
server.sendHeader("Content-Encoding", "gzip");
server.streamFile(f, mime::getContentType(p.substring(0, p.length()-5)), requestMethod);
}
else
server.streamFile(f, mime::getContentType(SRH::_path), requestMethod);
```
LED_sequence_v1:
TODO:
- disable led stripes after defined time (webserver paramter?)
- define what to do if people enter stairs from different directions
- CAUTION: Sensor-Deadtime at LEAST 8 seconds
- --> switch off with person leaving stairs might not be possible
Webserver on v0.3.0 now working with LittleFS
TODO:
- check dir for files automatic
- move handleNotFound to httpserver.h
- maybe compress files ?
LED Flickering issue
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
PlatformIO Library veraltet
-39
View File
@@ -1,39 +0,0 @@
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 usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
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
+16
View File
@@ -0,0 +1,16 @@
#ifndef __FILESYS_H
#define __FILESYS_H
#include <LittleFS.h>
bool mount_fs();
bool format_fs();
void ls(const char * dirname);
void readFile(const char * path);
void writeFile(const char * path, const char * message);
void appendFile(const char * path, const char * message);
void renameFile(const char * path1, const char * path2);
void deleteFile(const char * path);
#endif // __FILESYS_H
+48
View File
@@ -0,0 +1,48 @@
#ifndef __HTTPSERVER_H
#define __HTTPSERVER_H
#include "filesys.h"
#include <ESP8266WebServer.h>
class HTTPServer : public ESP8266WebServer {
private:
const char* rootDir;
bool addRootFileHandler();
bool formatFS() {
return format_fs();
}
void listRoot() {
ls(rootDir);
}
public:
HTTPServer(const int _port, const char* _rootDir) :
ESP8266WebServer(_port), rootDir(_rootDir)
{ }
~HTTPServer()
{
Serial.printf("[HTTPServer] shut down ...\n\r");
}
bool start() {
if(!mount_fs())
return false;
Serial.printf("[HTTPServer] LittleFS mounted !\n\r");
Serial.printf("[HTTPServer] root:\n\r");
this->listRoot();
Serial.printf("\n\r");
if( this->addRootFileHandler() ){
this->begin();
Serial.printf("[HTTPServer] Server active on Port 80 !\n\r");
return true;
}
Serial.printf("[HTTPServer] Not starting Server, something went wrong !\n\r");
return false;
}
};
#endif // __HTTPSERVER_H
+52
View File
@@ -0,0 +1,52 @@
#ifndef __OTA_H
#define __OTA_H
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
void ota_setup() {
ArduinoOTA.setPort(8266);
ArduinoOTA.setHostname("ESP_Treppenlicht");
ArduinoOTA.setPassword("admin");
// Password can be set with it's md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
} else { // U_FS
type = "filesystem";
}
// NOTE: if updating FS this would be the place to unmount FS using FS.end()
Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) {
Serial.println("Auth Failed");
} else if (error == OTA_BEGIN_ERROR) {
Serial.println("Begin Failed");
} else if (error == OTA_CONNECT_ERROR) {
Serial.println("Connect Failed");
} else if (error == OTA_RECEIVE_ERROR) {
Serial.println("Receive Failed");
} else if (error == OTA_END_ERROR) {
Serial.println("End Failed");
}
});
ArduinoOTA.begin();
}
#endif // __OTA_H
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include "PCA9685.h"
#define SENSOR1 15
#define SENSOR2 12
#define INT_TIME 20 // interrupt intervall [ms]
class Treppe {
private:
uint8_t stairs;
uint16_t time_per_stair = 200; // dimmtime per stair [ms]
uint16_t idle_brightness = 0;
uint16_t active_brightness = 1048;
uint8_t direction = 0;
uint8_t switch_direction = 0;
uint8_t state = 0;
uint8_t switch_state = 0;
uint8_t finish = 1;
// initialize with i2c-Address 0, use Wire Library
PCA9685 pwmController;
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
void ledsequence();
public:
Treppe(uint8_t _stairs) : stairs(_stairs){}
void task(); // call periodically
void setup();
// Parameter section
uint16_t setIdle(uint16_t _idle_brightness);
uint16_t setActive(uint16_t _active_brightness);
uint16_t setTime(uint16_t _time_per_stair);
// Runtime Parameter section
uint8_t setDirection(uint8_t _direction);
uint8_t setState(uint8_t _state);
uint8_t getState() { return state;};
uint8_t getDirection() {return direction;};
};
Submodule lib/PCA9685-Arduino added at a70be39257.
-28
View File
@@ -1,28 +0,0 @@
; 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:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
monitor_speed = 115200
; stuff for OTA
; https://docs.platformio.org/en/latest/platforms/espressif8266.html#over-the-air-ota-update
upload_protocol = espota
upload_port = 192.168.178.75
upload_flags =
--port=8266
--auth=admin
lib_deps =
# The exact version
ottowinter/PCA9685 16-Channel PWM Driver Module Library @ 1.2.9
+17
View File
@@ -0,0 +1,17 @@
set remote hardware-breakpoint-limit 1
set remote hardware-watchpoint-limit 1
set remote interrupt-on-connect on
set remote kill-packet off
set remote symbol-lookup-packet off
set remote verbose-resume-packet off
mem 0x20000000 0x3fefffff ro cache
mem 0x3ff00000 0x3fffffff rw
mem 0x40000000 0x400fffff ro cache
mem 0x40100000 0x4013ffff rw cache
mem 0x40140000 0x5fffffff ro cache
mem 0x60000000 0x60001fff rw
set serial baud 460800
file .pio/build/debug/firmware.elf
target remote /dev/ttyUSB0
thb loop
+130
View File
@@ -0,0 +1,130 @@
#include "filesys.h"
// listDir("/");
// deleteFile("/hello.txt");
// writeFile("/hello.txt", "Hello ");
// appendFile("/hello.txt", "World!\n\r");
// readFile("/hello.txt");
// listDir("/");
FSInfo fsinfo;
bool mount_fs() {
if(!LittleFS.begin()) {
Serial.println("[ERROR] LittleFS.info(), reset ...");
return false;
}
if(!LittleFS.info(fsinfo)) {
Serial.println("[ERROR] LittleFS.info(), reset ...");
return false;
}
printf("Filesystem opened:\n\r");
printf("\ttotalBytes:\t%d\n\r", fsinfo.totalBytes);
printf("\tusedBytes:\t%d\n\r", fsinfo.usedBytes);
printf("\tblockSize:\t%d\n\r", fsinfo.blockSize);
printf("\tpageSize:\t%d\n\r", fsinfo.pageSize);
printf("\tmaxOpenFiles:\t%d\n\r", fsinfo.maxOpenFiles);
printf("\tmaxPathLength:\t%d\n\r", fsinfo.maxPathLength);
printf("\n\r");
return true;
}
bool format_fs() {
printf("Formatting FS ! \n\r");
return LittleFS.format();
}
void ls(const char * dirname) {
Serial.printf("ls -l %s\n\r", dirname);
Dir root = LittleFS.openDir(dirname);
while (root.next()) {
File file = root.openFile("r");
time_t lw = file.getLastWrite();
struct tm * tmstruct = localtime(&lw);
Serial.printf("%8d %02d %02d %02d:%02d %s\n\r",
file.size(),
tmstruct->tm_mon + 1,
tmstruct->tm_mday,
tmstruct->tm_hour,
tmstruct->tm_min,
root.fileName().c_str());
file.close();
}
Serial.println();
}
void readFile(const char * path) {
Serial.printf("Reading file: %s\n\r", path);
File file = LittleFS.open(path, "r");
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
Serial.print("Read from file: ");
while (file.available()) {
Serial.write(file.read());
}
file.close();
}
void writeFile(const char * path, const char * message) {
Serial.printf("Writing file: %s\n\r", path);
File file = LittleFS.open(path, "w");
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
if (file.print(message)) {
Serial.println("File written");
} else {
Serial.println("Write failed");
}
delay(2000); // Make sure the CREATE and LASTWRITE times are different
file.close();
}
void appendFile(const char * path, const char * message) {
Serial.printf("Appending to file: %s\n\r", path);
File file = LittleFS.open(path, "a");
if (!file) {
Serial.println("Failed to open file for appending");
return;
}
if(file.print(message)) {
Serial.println("Message appended");
} else {
Serial.println("Append failed");
}
file.close();
}
void renameFile(const char * path1, const char * path2) {
Serial.printf("Renaming file %s to %s\n\r", path1, path2);
if (LittleFS.rename(path1, path2)) {
Serial.println("File renamed");
} else {
Serial.println("Rename failed");
}
}
void deleteFile(const char * path) {
Serial.printf("Deleting file: %s\n\r", path);
if (LittleFS.remove(path)) {
Serial.println("File deleted");
} else {
Serial.println("Delete failed");
}
}
+17
View File
@@ -0,0 +1,17 @@
#include "httpserver.h"
bool HTTPServer::addRootFileHandler() {
// //experimental, see doku.md
// server.serveStatic("/compressed", LittleFS, "/compressed.html.gzip");
this->serveStatic("", LittleFS, "/index.html");
this->serveStatic("/", LittleFS, "/index.html");
this->serveStatic("/#", LittleFS, "/index.html");
this->serveStatic("/style.css", LittleFS, "/style.css");
this->serveStatic("/input.js", LittleFS, "/input.js");
this->serveStatic("/favicon.png", LittleFS, "/favicon.png");
return true;
}
+74 -169
View File
@@ -1,84 +1,89 @@
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#ifdef WITH_DEBUGGING_ON
#include <GDBStub.h> // debugging support via GDBStub over UART
#endif
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include "wifi_credentials.h"
#include <Wire.h>
#include "PCA9685.h"
extern "C" {
#include "user_interface.h"
}
// OTA & WEB
#include "ota.h"
#include "wifi_credentials.h"
#include "httpserver.h"
// BOARD
#define ESP12_LED 2
#define NODEMCU_LED 16
// PWM
#include "pwm.h"
os_timer_t timer1;
uint8_t timer_flag = 0;
Treppe stairs(13);
// WIFI
const char* ssid = STASSID;
const char* password = STAPSK;
const int led = 13;
ESP8266WebServer server(80);
void handleRoot() {
digitalWrite(led, 1);
char temp[400];
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
snprintf(temp, 400,
"<html>\
<head>\
<meta http-equiv='refresh' content='5'/>\
<title>ESP8266 Demo</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<h1>Hello from ESP8266!</h1>\
<p>Uptime: %02d:%02d:%02d</p>\
<img src=\"/test.svg\" />\
</body>\
</html>",
hr, min % 60, sec % 60
);
server.send(200, "text/html", temp);
digitalWrite(led, 0);
void timerCallback(void *pArg)
{
*((int *) pArg) += 1;
stairs.task();
}
// HTTP
void handleNotFound();
HTTPServer httpServer(80, "/");
uint32_t _t=0;
#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us")
#define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > _l) { SP_US(_str, _t); }
// ===============================================
void handleNotFound() {
digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += httpServer.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += (httpServer.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += httpServer.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
for (uint8_t i = 0; i < httpServer.args(); i++) {
message += " " + httpServer.argName(i) + ": " + httpServer.arg(i) + "\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
httpServer.send(404, "text/plain", message);
}
void setup() {
#ifdef WITH_DEBUGGING_ON
Serial.begin(460800);
gdbstub_init();
#else
Serial.begin(115200);
#endif
void setup_webserver() {
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.println("");
Serial.println(F("Booting ...."));
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
pinMode(NODEMCU_LED, OUTPUT);
pinMode(ESP12_LED, OUTPUT);
Wire.begin(); // Wire must be started first
Wire.setClock(1000000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
Serial.println("");
@@ -87,120 +92,20 @@ void setup_webserver() {
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
ota_setup();
server.on("/", handleRoot);
server.on("/inline", []() {
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
httpServer.start();
httpServer.onNotFound(handleNotFound);
Serial.println("HTTP server started !");
stairs.setup();
Serial.println("PCA9685 connected !");
os_timer_setfn(&timer1, timerCallback, &timer_flag);
os_timer_arm(&timer1, 20, true);
}
PCA9685 pwmController;
void setup() {
Serial.begin(115200);
Serial.println("Booting");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Wire.begin(); // Wire must be started first
Wire.setClock(400000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
// setup OTA
ArduinoOTA.setPort(8266);
ArduinoOTA.setHostname("ESP_Treppenlicht");
ArduinoOTA.setPassword("admin");
// Password can be set with it's md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
} else { // U_FS
type = "filesystem";
}
// NOTE: if updating FS this would be the place to unmount FS using FS.end()
Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) {
Serial.println("Auth Failed");
} else if (error == OTA_BEGIN_ERROR) {
Serial.println("Begin Failed");
} else if (error == OTA_CONNECT_ERROR) {
Serial.println("Connect Failed");
} else if (error == OTA_RECEIVE_ERROR) {
Serial.println("Receive Failed");
} else if (error == OTA_END_ERROR) {
Serial.println("End Failed");
}
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
setup_webserver();
pwmController.resetDevices(); // Software resets all PCA9685 devices on Wire line
pwmController.init(B000000); // Address pins A5-A0 set to B000000
pwmController.setPWMFrequency(200); // Default is 200Hz, supports 24Hz to 1526Hz
pwmController.setChannelPWM(0, 128 << 4); // Set PWM to 128/255, but in 4096 land
Serial.println(pwmController.getChannelPWM(0)); // Should output 2048, which is 128 << 4
}
unsigned long i = 0;
unsigned long a = 0;
unsigned long s = 0;
float ard_ota_time = 0;
float server_handle = 0;
void loop() {
a = micros();
ArduinoOTA.handle();
ard_ota_time += micros()-a;
s = micros();
server.handleClient();
server_handle += micros()-s;
if(++i >= 10000) {
Serial.print("Mittlere Laufzeit\tOTA: ");
Serial.print(ard_ota_time/10000.0);
Serial.print("µs\tHTTP: ");
Serial.print(server_handle/10000.0);
Serial.println("µs");
ard_ota_time = 0;
server_handle = 0;
i = 0;
}
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
}
+183
View File
@@ -0,0 +1,183 @@
#include "pwm.h"
uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
/*
softstart task
- get's called at regular intervals (1ms at the moment)
- dimms single led (0 - 15, PCA9685 outputs) with linear intervals vom startval to stopval
- calculates pwm steps depending on startval, stopval and timeinterval
- -> results in constanst speed
- returns 1 if led dimming is running
- returns 0 if led dimming is finished
*/
static uint8_t lastled = 255;
static float current_pwm = 0;
static float stepsize = 1.0;
if(led != lastled){
pwmController.setChannelPWM(led, (uint16_t)startval);
lastled = led;
current_pwm = startval;
stepsize = INT_TIME*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval
return 1;
}
if(startval > stopval){
current_pwm -= stepsize;
}
else {
current_pwm += stepsize;
}
Serial.println((uint16_t)current_pwm);
pwmController.setChannelPWM(led, (uint16_t)current_pwm);
if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize){
if(stopval == 0) pwmController.setChannelPWM(led, 0);
return 0;
}
return 1;
}
void Treppe::ledsequence(){
static int8_t led = 0;
static uint16_t brightness = 0;
static uint16_t lastbrightness = 0;
static uint16_t status = 0;
uint16_t status_build = 0;
status_build |= direction << 8;
status_build |= state;
if(status_build != status){ // check if any parameter changed
finish = 0; // set state unfinished -> start action
if(direction) led = 0; // reset led counter depending of direction
else led = stairs-1;
if(state){
brightness = active_brightness; // set brightness value depending of on/off
lastbrightness = idle_brightness;
}
else{
brightness = idle_brightness;
lastbrightness = active_brightness;
}
status = status_build; // set parameter memory
Serial.print("----Status Changed! onoff: ");
Serial.print(state);
Serial.print(" dir: ");
Serial.println(direction);
}
if(!finish){ // finish == 0 -> action pending
if(!softstart_led(led,lastbrightness, brightness)){
Serial.print("one LED finished: ");
Serial.print(led);
Serial.print(" last: ");
Serial.print(lastbrightness);
Serial.print(" curr: ");
Serial.println(brightness);
if(direction){
led++;
if(led >= stairs) {
finish = 1;
//lastbrightness = brightness;
}
}
else{
led--;
if(led < 0){
//lastbrightness = brightness;
finish = 1;
}
}
}
}
}
void Treppe::setup(){
pwmController.resetDevices();
// Deactive PCA9685 Phase Balancer due to LED Flickering
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
// see also lib/PCA9685-Arduin/PCA9685.h:204
pwmController.init(PCA9685_PhaseBalancer_None);
pwmController.setPWMFrequency(200);
pwmController.setAllChannelsPWM(idle_brightness);
pinMode(SENSOR1, INPUT);
pinMode(SENSOR2, INPUT);
Serial.println("Hello from Treppe");
Serial.print("Treppe: initial parameters: stairs=");
Serial.println(stairs);
}
void Treppe::task(){
if(finish){
direction = switch_direction;
state = switch_state;
}
static uint8_t last_sensor_state[2] = {0,0};
uint8_t current_sensor_state[2] = {0,0};
current_sensor_state[0] = digitalRead(SENSOR1);
current_sensor_state[1] = digitalRead(SENSOR2);
if(current_sensor_state[0] && !last_sensor_state[0] && state == 0){
setDirection(1);
setState(1);
}
if(current_sensor_state[1] && !last_sensor_state[1] && state == 0){
setDirection(0);
setState(1);
}
// first switch - off approach, use timer later
if(!current_sensor_state[0] && last_sensor_state[0] && state == 1){
setDirection(1);
setState(0);
}
if(!current_sensor_state[1] && last_sensor_state[1] && state == 1){
setDirection(0);
setState(0);
}
last_sensor_state[0] = current_sensor_state[0];
last_sensor_state[1] = current_sensor_state[1];
ledsequence();
}
uint16_t Treppe::setIdle(uint16_t _idle_brightness){
idle_brightness = _idle_brightness;
Serial.println("Treppe: idle brightness changed!");
return idle_brightness;
}
uint16_t Treppe::setActive(uint16_t _active_brightness){
active_brightness = _active_brightness;
Serial.println("Treppe: active brightness changed!");
return active_brightness;
}
uint16_t Treppe::setTime(uint16_t _time_per_stair){
time_per_stair = _time_per_stair;
Serial.println("Treppe: time changed!");
return time_per_stair;
}
uint8_t Treppe::setDirection(uint8_t _direction){
switch_direction = _direction;
Serial.println("Treppe: Direction changed!");
if(finish) Serial.println("apply direction request immediately");
else Serial.println("currently active, dir change afterwards");
// to do: implement state command variable to determine dimm-state
return switch_direction;
}
uint8_t Treppe::setState(uint8_t _state){
if(state == _state) return 1;
else{
switch_state = _state;
Serial.println("Treppe: State Request changed!");
if(finish) Serial.println("apply state request immediately");
else Serial.println("currently active, state changes after activity");
}
return 0;
}
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
GDB_PATH=~/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.0-newlib4.0.0-gnu23-48f7b08/bin/xtensa-lx106-elf-gdb
cd ..
echo "Starting gdb"
$GDB_PATH -x scripts/gdboptions
+45
View File
@@ -0,0 +1,45 @@
; 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]
platform = espressif8266
board = nodemcuv2
framework = arduino
; for http files
board_build.filesystem = littlefs
board_build.ldscript = eagle.flash.4m1m.ld
extra_scripts = pre:create_gz_files.py
monitor_speed = 115200
[env:serial]
upload_protocol = esptool
upload_speed = 921600
[env:ota]
; OTA => https://docs.platformio.org/en/latest/platforms/espressif8266.html#over-the-air-ota-update
upload_protocol = espota
upload_port = <!! IP ADDRESS !!>
upload_flags =
--port=8266
--host_port=<!! PORT !!>
--auth=admin
[env:debug]
; look at doku.md
build_flags = -DWITH_DEBUGGING_ON -Os -g3 -ggdb3
upload_protocol = esptool
upload_speed = 921600
-11
View File
@@ -1,11 +0,0 @@
This directory is intended for PlatformIO Unit Testing 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/page/plus/unit-testing.html
+40
View File
@@ -0,0 +1,40 @@
#include <Arduino.h>
#include <unity.h>
String STR_TO_TEST;
void setUp(void) {
// set stuff up here
STR_TO_TEST = "Hello, world!";
}
void tearDown(void) {
// clean stuff up here
STR_TO_TEST = "";
}
void test_led_builtin_pin_number(void) {
TEST_ASSERT_EQUAL(2, LED_BUILTIN);
}
void test_string_concat(void) {
String hello = "Hello, ";
String world = "world!";
TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str());
}
void setup()
{
delay(2000); // service delay
UNITY_BEGIN();
RUN_TEST(test_led_builtin_pin_number);
RUN_TEST(test_string_concat);
UNITY_END(); // stop unit testing
}
void loop()
{
}
Executable
+2
View File
@@ -0,0 +1,2 @@
CD .\data
py.exe -m http.server
Executable
+2
View File
@@ -0,0 +1,2 @@
cd data
python3 -m http.server