This commit is contained in:
Dominik Bartsch 2021-06-21 10:53:49 +02:00
commit 055a6193df
6 changed files with 64 additions and 41 deletions

4
.gitignore vendored
View File

@ -1,9 +1,5 @@
.pio .pio
.vscode .vscode
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
platformio.ini platformio.ini
include/wifi_credentials.h include/wifi_credentials.h
include/*.gz.h include/*.gz.h

12
.vscode/settings.json vendored
View File

@ -1,5 +1,15 @@
{ {
"files.associations": { "files.associations": {
"random": "cpp" "random": "cpp",
"array": "cpp",
"*.tcc": "cpp",
"deque": "cpp",
"list": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"string_view": "cpp",
"memory": "cpp",
"ranges": "cpp"
} }
} }

View File

@ -17,8 +17,7 @@ https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html
``` ```
##### platformio.ini ##### platformio.ini
change IP of esp8266 accordingly see templ_platformio_ini
IP gets printed on Serial Monitor after first Upload
```ini ```ini
[env:<BOARD>] [env:<BOARD>]

View File

@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>My test page</title> <title>My test page</title>
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css"> <link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<link href="styles/style.css" rel="stylesheet" type="text/css"> <link href="style.css" rel="stylesheet" type="text/css">
</head> </head>
<body> <body>
<h1>Mozilla is cool</h1> <h1>Mozilla is cool</h1>

2
include/webtest.cmd Normal file
View File

@ -0,0 +1,2 @@
CD .\include\http
py.exe -m http.server

View File

@ -1,17 +1,17 @@
#include <Arduino.h> #include <Arduino.h>
#include <Wire.h> #include <Wire.h>
#include "wifi_credentials.h"
#include "PCA9685.h" #include "PCA9685.h"
// Änderung // Änderung
// OTA & WEB // OTA & WEB
#include "wifi_credentials.h"
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include <WiFiClient.h> // evtl weghauen ? #include <WiFiClient.h>
#include "index.html.gz.h" #include "index.html.gz.h"
#include "style.css.gz.h" #include "style.css.gz.h"
@ -21,8 +21,16 @@
const char* ssid = STASSID; const char* ssid = STASSID;
const char* password = STAPSK; const char* password = STAPSK;
void setup_webserver();
void setup_ota();
void setup_pwm_pca9685();
void handleRootGz();
void handleCssGz();
void handleNotFound();
const int led = 13; const int led = 13;
ESP8266WebServer server(80); ESP8266WebServer server(80);
PCA9685 pwmController;
void handleRootGz() { void handleRootGz() {
const char* dataType = "text/html"; const char* dataType = "text/html";
@ -36,7 +44,6 @@ void handleCssGz() {
server.send(200, dataType, (const char*)style_css_gz, style_css_gz_len); server.send(200, dataType, (const char*)style_css_gz, style_css_gz_len);
} }
void handleNotFound() { void handleNotFound() {
digitalWrite(led, 1); digitalWrite(led, 1);
String message = "File Not Found\n\n"; String message = "File Not Found\n\n";
@ -74,35 +81,15 @@ void setup_webserver() {
Serial.print("IP address: "); Serial.print("IP address: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
//server.on("/", handleRoot);
server.on("/", handleRootGz); server.on("/", handleRootGz);
server.on("/styles/style.css", handleCssGz); server.on("/style.css", handleCssGz);
server.onNotFound(handleNotFound); server.onNotFound(handleNotFound);
server.begin(); server.begin();
Serial.println("HTTP server started"); Serial.println("HTTP server started");
} }
void setup_ota() {
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.setPort(8266);
ArduinoOTA.setHostname("ESP_Treppenlicht"); ArduinoOTA.setHostname("ESP_Treppenlicht");
ArduinoOTA.setPassword("admin"); ArduinoOTA.setPassword("admin");
@ -142,21 +129,44 @@ void setup() {
} }
}); });
ArduinoOTA.begin(); 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.resetDevices(); // Software resets all PCA9685 devices on Wire line
pwmController.init(B000000); // Address pins A5-A0 set to B000000 pwmController.init(B000000); // Address pins A5-A0 set to B000000
pwmController.setPWMFrequency(200); // Default is 200Hz, supports 24Hz to 1526Hz pwmController.setPWMFrequency(200); // Default is 200Hz, supports 24Hz to 1526Hz
pwmController.setChannelPWM(0, 128 << 4); // Set PWM to 128/255, but in 4096 land 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
}
void setup() {
Serial.begin(115200);
Serial.println(F("Booting ...."));
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();
}
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
setup_ota();
setup_webserver();
setup_pwm_pca9685();
} }
uint32_t t; uint32_t t;
@ -237,6 +247,7 @@ void ledsequence(uint8_t direction, uint8_t onoff, uint8_t factor){
void loop() { void loop() {
<<<<<<< HEAD
static uint32_t dimmtimer = 0; static uint32_t dimmtimer = 0;
/* static uint8_t led = 0; /* static uint8_t led = 0;
static uint16_t brightness = 127; static uint16_t brightness = 127;
@ -273,4 +284,9 @@ void loop() {
if(millis() > 25000) onoff = 0; if(millis() > 25000) onoff = 0;
TIMEIF_US("OTA", ArduinoOTA.handle(), 20000); TIMEIF_US("OTA", ArduinoOTA.handle(), 20000);
TIMEIF_US("HTTP", server.handleClient(), 20000); TIMEIF_US("HTTP", server.handleClient(), 20000);
=======
TIMEIF_US("OTA", ArduinoOTA.handle(), 1000);
TIMEIF_US("HTTP", server.handleClient(), 1000);
>>>>>>> d0b824963bd79fc436b4b312e49b48081860d8d4
} }