Dominik Bartsch 2 years ago
parent
commit
055a6193df
6 changed files with 64 additions and 41 deletions
  1. 0
    4
      .gitignore
  2. 11
    1
      .vscode/settings.json
  3. 1
    2
      README.md
  4. 1
    1
      include/http/index.html
  5. 2
    0
      include/webtest.cmd
  6. 49
    33
      src/main.cpp

+ 0
- 4
.gitignore View File

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

+ 11
- 1
.vscode/settings.json View File

@@ -1,5 +1,15 @@
{
"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"
}
}

+ 1
- 2
README.md View File

@@ -17,8 +17,7 @@ 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>]

+ 1
- 1
include/http/index.html View File

@@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>My test page</title>
<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>
<body>
<h1>Mozilla is cool</h1>

+ 2
- 0
include/webtest.cmd View File

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

+ 49
- 33
src/main.cpp View File

@@ -1,17 +1,17 @@
#include <Arduino.h>
#include <Wire.h>

#include "wifi_credentials.h"
#include "PCA9685.h"

// Änderung
// OTA & WEB
#include "wifi_credentials.h"
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

#include <ESP8266WebServer.h>
#include <WiFiClient.h> // evtl weghauen ?
#include <WiFiClient.h>

#include "index.html.gz.h"
#include "style.css.gz.h"
@@ -21,8 +21,16 @@
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 handleRootGz() {
const char* dataType = "text/html";
@@ -36,7 +44,6 @@ void handleCssGz() {
server.send(200, dataType, (const char*)style_css_gz, style_css_gz_len);
}


void handleNotFound() {
digitalWrite(led, 1);
String message = "File Not Found\n\n";
@@ -74,35 +81,15 @@ void setup_webserver() {
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

//server.on("/", handleRoot);
server.on("/", handleRootGz);
server.on("/styles/style.css", handleCssGz);
server.on("/style.css", handleCssGz);
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");
@@ -142,21 +129,44 @@ 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
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
}



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;
@@ -237,6 +247,7 @@ void ledsequence(uint8_t direction, uint8_t onoff, uint8_t factor){


void loop() {
<<<<<<< HEAD
static uint32_t dimmtimer = 0;
/* static uint8_t led = 0;
static uint16_t brightness = 127;
@@ -273,4 +284,9 @@ void loop() {
if(millis() > 25000) onoff = 0;
TIMEIF_US("OTA", ArduinoOTA.handle(), 20000);
TIMEIF_US("HTTP", server.handleClient(), 20000);
=======
TIMEIF_US("OTA", ArduinoOTA.handle(), 1000);
TIMEIF_US("HTTP", server.handleClient(), 1000);
>>>>>>> d0b824963bd79fc436b4b312e49b48081860d8d4
}

Loading…
Cancel
Save