48 Commits
Author SHA1 Message Date
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
28 changed files with 875 additions and 446 deletions
+1
View File
@@ -1,5 +1,6 @@
.pio
.vscode
compress
platformio.ini
include/wifi_credentials.h
include/*.gz.h
+38 -1
View File
@@ -10,6 +10,43 @@
"vector": "cpp",
"string_view": "cpp",
"memory": "cpp",
"ranges": "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"
}
}
-3
View File
@@ -35,8 +35,5 @@ upload_port = <IPADRESS>
upload_flags =
--port=8266
--auth=admin
lib_deps =
ottowinter/PCA9685 16-Channel PWM Driver Module Library @ 1.2.9
```
+6 -2
View File
@@ -1,3 +1,4 @@
#!/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/
@@ -27,8 +28,11 @@ def convert_to_gzip(src, out, f):
f_out.write(top.encode(encoding='utf-8'))
src='include/http/'
out='include/'
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

Before

Width:  |  Height:  |  Size: 531 B

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>
+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);
}
+68
View File
@@ -0,0 +1,68 @@
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);
```
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
-3
View File
@@ -1,3 +0,0 @@
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
+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
Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

-40
View File
@@ -1,40 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>ESP8266 Treppenlicht</title>
<!-- main style sheet -->
<link href="/favicon.png" rel="icon" type="image/png" sizes="16x16">
<link href="/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="topbar">
ESP8266 Treppenlicht Controller
</div>
<div class="control">
<div class="brightness">
</div>
<div class="onoff">
toggle all
<label id="l_onoff"></label>
<label class="switch">
<input type="checkbox">
<span class="slider round"></span>
</label>
</div>
<div class="pwm">
<label id="label_pwm"></label>
<input type="range" min="1" max="100" value="50" class="rangeslider" id="range1">
</div>
<div class="timer">
<label id="label_timer"></label>
<input type="range" min="1" max="100" value="50" class="rangeslider" id="timer_range">
</div>
</div>
</body>
<script src="/input.js"></script>
</html>
-132
View File
@@ -1,132 +0,0 @@
html {
font-size: 10px;
font-family: sans-serif, Arial, Helvetica;
background-color: #b3b3b3;
}
.topbar {
padding: 1em;
background-color: #1f1f1f;
color: white;
font-size: x-large;
text-align: center;
}
.control {
padding: 1em;
}
p, li {
font-size: 16px;
line-height: 2;
letter-spacing: 1px;
}
body {
margin: 0 auto;
border: 1px solid black;
border-radius: 3;
}
/* The switch - the box around the slider */
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
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);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
/* The slider itself */
.rangeslider {
-webkit-appearance: none; /* Override default CSS styles */
appearance: none;
width: 50%; /* Full-width */
height: 34px; /* Specified height */
border-radius: 34px; /* range round corners */
background: #d3d3d3; /* Grey background */
outline: none; /* Remove outline */
opacity: 0.7; /* Set transparency (for mouse-over effects on hover) */
-webkit-transition: .2s; /* 0.2 seconds transition on hover */
transition: opacity .2s;
}
/* Mouse-over effects */
.rangeslider:hover {
opacity: 1; /* Fully shown on mouse-over */
}
/* The slider handle (use -webkit- (Chrome, Opera, Safari, Edge) and -moz- (Firefox) to override default look) */
.rangeslider::-webkit-slider-thumb {
-webkit-appearance: none; /* Override default look */
appearance: none;
width: 26px; /* Set a specific slider handle width */
height: 26px; /* Slider handle height */
border-radius: 50%; /* Round Element */
background: #04AA6D; /* Green background */
cursor: pointer; /* Cursor on hover */
}
.rangeslider::-moz-range-thumb {
width: 26px; /* Set a specific slider handle width */
height: 26px; /* Slider handle height */
background: #04AA6D; /* Green background */
cursor: pointer; /* Cursor on hover */
}
+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
+48
View File
@@ -0,0 +1,48 @@
#ifndef __OTA_H
#define __OTA_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
+38
View File
@@ -0,0 +1,38 @@
#pragma once
#include "PCA9685.h"
class Treppe {
private:
uint8_t stairs;
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
uint16_t idle_brightness = 200;
uint16_t active_brightness = 2048;
uint8_t direction = 0;
uint8_t state = 0;
uint8_t switch_state = 0;
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;};
};
+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;
}
+63 -254
View File
@@ -1,186 +1,80 @@
#include <Arduino.h>
#include <Wire.h>
#ifdef WITH_DEBUGGING_ON
#include <GDBStub.h> // debugging support via GDBStub over UART
#endif
#include "PCA9685.h"
#include <GDBStub.h>
#define ESP12_LED 2
#define NODEMCU_LED 16
extern "C" {
#include "user_interface.h"
}
os_timer_t Timer1; // Verwaltungsstruktur des Timers
// OTA & WEB
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include "ota.h"
int c;
bool toggle = false;
uint32_t m=0;
#include "wifi_credentials.h"
#include "httpserver.h"
uint32_t dimmtimer = 0;
uint8_t direction = 1;
uint8_t onoff = 1;
// 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);
void ledsequence(uint8_t direction, uint8_t onoff, uint8_t factor);
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval, uint8_t factor);
// WIFI
const char* ssid = STASSID;
const char* password = STAPSK;
void timerCallback(void *pArg)
{
*((int *) pArg) += 1;
ledsequence(direction, onoff, 4);
// Serial.print("[");
// Serial.print(micros()-m);
// Serial.print("] timerCallback\n");
// m = micros();
stairs.task();
}
// OTA & WEB
#include "wifi_credentials.h"
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
#include "index.html.gz.h"
#include "style.css.gz.h"
#include "favicon.png.gz.h"
// images are possible
// maybe check out FS <- SPIFFS
const char* ssid = STASSID;
const char* password = STAPSK;
void setup_webserver();
void setup_ota();
void setup_pwm_pca9685();
void handleRootGz();
void handleCssGz();
// HTTP
void handleNotFound();
HTTPServer httpServer(80, "/");
const int led = 13;
ESP8266WebServer server(80);
PCA9685 pwmController;
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 handleRootGz() {
const char* dataType = "text/html";
server.sendHeader(F("Content-Encoding"), F("gzip"));
server.send(200, dataType, (const char*)index_html_gz, index_html_gz_len);
}
void handleCssGz() {
const char* dataType = "text/css";
server.sendHeader(F("Content-Encoding"), F("gzip"));
server.send(200, dataType, (const char*)style_css_gz, style_css_gz_len);
}
void handleFaviconGz() {
const char* dataType = "image/png";
server.sendHeader(F("Content-Encoding"), F("gzip"));
server.send(200, dataType, (const char*)favicon_png_gz, favicon_png_gz_len);
}
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);
}
void setup_webserver() {
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRootGz);
server.on("/style.css", handleCssGz);
server.on("/favicon.png", handleFaviconGz);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void 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();
}
void setup_pwm_pca9685() {
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
Serial.println(pwmController.getChannelPWM(0)); // Should output 2048, which is 128 << 4
httpServer.send(404, "text/plain", message);
}
void setup() {
#ifdef WITH_DEBUGGING_ON
Serial.begin(460800);
gdbstub_init();
#else
Serial.begin(115200);
#endif
Serial.println(F("Booting ...."));
@@ -188,7 +82,7 @@ void setup() {
pinMode(ESP12_LED, OUTPUT);
Wire.begin(); // Wire must be started first
Wire.setClock(400000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
Wire.setClock(1000000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
@@ -199,119 +93,34 @@ void setup() {
ESP.restart();
}
os_timer_setfn(&Timer1, timerCallback, &c);
os_timer_arm(&Timer1, 1, true);
Serial.println("Ready");
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
setup_ota();
setup_webserver();
setup_pwm_pca9685();
}
ota_setup();
uint32_t t;
#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("µs")
#define TIMEIF_US(_str,_f, _l) t=micros(); _f; t=micros()-t; if(t > _l) { SP_US(_str, t); }
httpServer.start();
httpServer.onNotFound(handleNotFound);
Serial.println("HTTP server started !");
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval, uint8_t factor){
static uint8_t lastled = 255;
static uint8_t current_pwm = 0;
stairs.setup();
Serial.println("PCA9685 connected !");
if(led != lastled){
pwmController.setChannelPWM(led, startval);
lastled = led;
current_pwm = startval;
return 1;
}
os_timer_setfn(&timer1, timerCallback, &timer_flag);
os_timer_arm(&timer1, 20, true);
if(current_pwm == stopval){
return 0;
stairs.setState(1);
stairs.setDirection(1);
}
else if(startval > stopval){
current_pwm -= 1;
}
else {
current_pwm += 1;
}
pwmController.setChannelPWM(led, current_pwm*factor);
return 1;
}
#define LEDCOUNT 16
void ledsequence(uint8_t direction, uint8_t onoff, uint8_t factor){
static int8_t led = 0;
static uint8_t brightness = 0;
static uint8_t lastbrightness = 0;
static uint8_t finish = 1;
static uint32_t status = 0;
uint32_t status_build = 0;
status_build |= direction << 16;
status_build |= onoff << 8;
status_build |= factor;
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 = LEDCOUNT-1;
if(onoff){
brightness = 127; // set brightness value depending of on/off
lastbrightness = 0;
}
else{
brightness = 0;
lastbrightness = 127;
}
status = status_build; // set parameter memory
Serial.print("----Status Changed! onoff: ");
Serial.print(onoff);
Serial.print(" dir: ");
Serial.println(direction);
}
if(!finish){ // finish == 0 -> action pending
if(!softstart_led(led,lastbrightness, brightness, factor)){
Serial.print("one LED finished, new set led: ");
Serial.print(led);
Serial.print(" last: ");
Serial.print(lastbrightness);
Serial.print(" curr: ");
Serial.println(brightness);
if(direction){
led++;
if(led >= LEDCOUNT) {
finish = 1;
//lastbrightness = brightness;
}
}
else{
led--;
if(led < 0){
//lastbrightness = brightness;
finish = 1;
}
}
}
}
}
void loop() {
if(millis() - dimmtimer > 2){
//ledsequence(direction, onoff, 4);
dimmtimer = millis();
if(millis() > 25000 && stairs.getState() == 1 && stairs.getDirection() == 1) stairs.setState(0);
if(millis() > 45000 && stairs.getDirection() == 1){
stairs.setState(1);
stairs.setDirection(0);
}
if(millis() > 25000 && onoff == 1 && direction == 1) onoff = 0;
if(millis() > 35000 && direction == 1){
onoff = 1;
direction = 0;
}
TIMEIF_US("OTA", ArduinoOTA.handle(), 1000);
TIMEIF_US("HTTP", server.handleClient(), 1000);
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
}
+136
View File
@@ -0,0 +1,136 @@
#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 = 20*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval
return 1;
}
if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize) return 0;
// todo: duty cycle zero!
if(startval > stopval){
current_pwm -= stepsize;
}
else {
current_pwm += stepsize;
}
Serial.println((uint16_t)current_pwm);
pwmController.setChannelPWM(led, (uint16_t)current_pwm);
return 1;
}
void Treppe::ledsequence(){
static int8_t led = 0;
static uint16_t brightness = 0;
static uint16_t lastbrightness = 0;
static uint8_t finish = 1;
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();
pwmController.init();
pwmController.setPWMFrequency(200);
Serial.println("Hello from Treppe");
Serial.print("Treppe: initial parameters: stairs=");
Serial.println(stairs);
}
void Treppe::task(){
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){
direction = _direction;
Serial.println("Treppe: Direction changed!");
// to do: implement state command variable to determine dimm-state
return direction;
}
uint8_t Treppe::setState(uint8_t _state){
if(state == _state) return 1;
else{
state = _state;
Serial.println("Treppe: State changed!");
}
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
+24 -7
View File
@@ -8,21 +8,38 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp01_1m]
[env]
platform = espressif8266
board = esp01_1m
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
extra_scripts = pre:extra_script.py
[env:serial]
upload_protocol = esptool
upload_speed = 921600
; stuff for OTA
; https://docs.platformio.org/en/latest/platforms/espressif8266.html#over-the-air-ota-update
[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
lib_deps =
ottowinter/PCA9685 16-Channel PWM Driver Module Library @ 1.2.9
[env:debug]
; look at doku.md
build_flags = -DWITH_DEBUGGING_ON -Os -g3 -ggdb3
upload_protocol = esptool
upload_speed = 921600
+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()
{
}
+1 -1
View File
@@ -1,2 +1,2 @@
CD .\include\http
CD .\data
py.exe -m http.server
Executable
+2
View File
@@ -0,0 +1,2 @@
cd data
python3 -m http.server