28 Commits
Author SHA1 Message Date
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
17 changed files with 473 additions and 159 deletions

No files matched your search

+3 -5
View File
@@ -1,7 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.vscode
platformio.ini
include/wifi_credentials.h
platformio.ini
include/*.gz.h
+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"
]
}
+15
View File
@@ -0,0 +1,15 @@
{
"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"
}
}
+23 -2
View File
@@ -17,5 +17,26 @@ 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
lib_deps =
ottowinter/PCA9685 16-Channel PWM Driver Module Library @ 1.2.9
```
+3
View File
@@ -0,0 +1,3 @@
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
+34
View File
@@ -0,0 +1,34 @@
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='include/http/'
out='include/'
for f in os.listdir(src):
convert_to_gzip(src, out, f)
-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
Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

+40
View File
@@ -0,0 +1,40 @@
<!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>
+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;
}
+132
View File
@@ -0,0 +1,132 @@
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 */
}
+2
View File
@@ -0,0 +1,2 @@
CD .\include\http
py.exe -m http.server
+203 -92
View File
@@ -1,53 +1,84 @@
#include <Arduino.h>
#include <Wire.h>
#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
int c;
bool toggle = false;
uint32_t m=0;
uint32_t dimmtimer = 0;
uint8_t direction = 1;
uint8_t onoff = 1;
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);
void timerCallback(void *pArg)
{
*((int *) pArg) += 1;
ledsequence(direction, onoff, 4);
// Serial.print("[");
// Serial.print(micros()-m);
// Serial.print("] timerCallback\n");
// m = micros();
}
// OTA & WEB
#include "wifi_credentials.h"
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include "wifi_credentials.h"
#include <Wire.h>
#include "PCA9685.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();
void handleNotFound();
const int led = 13;
ESP8266WebServer server(80);
PCA9685 pwmController;
void handleRoot() {
digitalWrite(led, 1);
char temp[400];
int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
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);
}
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 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() {
@@ -87,39 +118,16 @@ void setup_webserver() {
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/inline", []() {
server.send(200, "text/plain", "this works as well");
});
server.on("/", handleRootGz);
server.on("/style.css", handleCssGz);
server.on("/favicon.png", handleFaviconGz);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
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
void setup_ota() {
ArduinoOTA.setPort(8266);
ArduinoOTA.setHostname("ESP_Treppenlicht");
ArduinoOTA.setPassword("admin");
@@ -159,48 +167,151 @@ void setup() {
}
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
setup_webserver();
}
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
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
Serial.println(pwmController.getChannelPWM(0)); // Should output 2048, which is 128 << 4
}
unsigned long i = 0;
void setup() {
Serial.begin(460800);
gdbstub_init();
Serial.println(F("Booting ...."));
pinMode(NODEMCU_LED, OUTPUT);
pinMode(ESP12_LED, OUTPUT);
Wire.begin(); // Wire must be started first
Wire.setClock(400000); // 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();
}
os_timer_setfn(&Timer1, timerCallback, &c);
os_timer_arm(&Timer1, 1, true);
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
setup_ota();
setup_webserver();
setup_pwm_pca9685();
}
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); }
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;
if(led != lastled){
pwmController.setChannelPWM(led, startval);
lastled = led;
current_pwm = startval;
return 1;
}
if(current_pwm == stopval){
return 0;
}
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;
}
}
}
}
}
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;
if(millis() - dimmtimer > 2){
//ledsequence(direction, onoff, 4);
dimmtimer = millis();
}
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);
}
+3 -3
View File
@@ -14,15 +14,15 @@ board = esp01_1m
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 = 192.168.178.75
upload_port = <!! IP ADDRESS !!>
upload_flags =
--port=8266
--auth=admin
lib_deps =
# The exact version
ottowinter/PCA9685 16-Channel PWM Driver Module Library @ 1.2.9
-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
View File
Whitespace-only changes.