Moved platform-specific code related to WiFi and services to my_wifi.h. Also, made the HTTP server stuff compatible to ESP32.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Fabian Schlenz 2019-06-13 06:01:44 +02:00
parent ea4898daa6
commit 291a3be623
11 changed files with 41 additions and 34 deletions

View File

@ -2,9 +2,14 @@
#include "config.h"
#ifdef HTTP_SERVER_ENABLE
#include <ESP8266WebServer.h>
#include "my_wifi.h"
#if defined ( ESP8266 )
extern ESP8266WebServer http_server;
#elif defined ( ESP32 )
extern ESP32WebServer http_server;
#endif
void http_server_setup();
void http_server_loop();

19
include/my_wifi.h Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#include "config.h"
#if defined( ESP8266 )
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h>
#elif defined( ESP32 )
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <ESP32WebServer.h>
#endif
#include <WiFiUdp.h>
void wifi_setup();

View File

@ -1,7 +1,7 @@
#pragma once
#include <NTPClient.h>
#include <WiFiUdp.h>
#include "my_wifi.h"
#include "config.h"
extern NTPClient ntpClient;

View File

@ -1,9 +1,6 @@
#ifndef ota_H
#define ota_H
#pragma once
#include <ArduinoOTA.h>
void ota_setup();
void ota_loop();
#endif

View File

@ -1,6 +0,0 @@
#ifndef wifi_H
#define wifi_H
void wifi_setup();
#endif

View File

@ -19,6 +19,7 @@ lib_deps =
https://github.com/fabianonline/FastLED.git
https://github.com/fabianonline/simplelist.git
https://github.com/fabianonline/NTPClient.git
ESP8266WebServer
[env:ota]
upload_port = 10.10.2.78
@ -39,4 +40,7 @@ lib_deps = ${extra.lib_deps}
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = ${extra.lib_deps}
lib_deps =
${extra.lib_deps}
ESP32WebServer
WiFiClient

View File

@ -5,7 +5,11 @@
#include "http_server.h"
#include "effects.h"
#if defined( ESP8266 )
ESP8266WebServer http_server(HTTP_SERVER_PORT);
#elif defined( ESP32 )
ESP32WebServer http_server(HTTP_SERVER_PORT);
#endif
void http_server_400() {
http_server.send(400);

View File

@ -5,13 +5,7 @@
#pragma message "MQTT_ENABLE is false. Skipping MQTT."
#else
#if defined( ESP8266 )
#include <ESP8266WiFi.h>
#elif defined( ESP32 )
#include <WiFi.h>
#else
#error "Neither ESP32 nor ESP8266 set..."
#endif
#include "my_wifi.h"
#include <PubSubClient.h>
#include "EffectEntry.h"
#include "Effect.h"

View File

@ -1,12 +1,6 @@
#include <ArduinoOTA.h>
#if defined( ESP8266 )
#include <ESP8266mDNS.h>
#elif defined( ESP32 )
#include <ESPmDNS.h>
#else
#error Neither ESP32 nor ESP8266 set!
#endif
#include "my_wifi.h"
#include <ArduinoOTA.h>
#include "config.h"

View File

@ -4,7 +4,7 @@
#include "ntp.h"
#include "config.h"
#include "animations.h"
#include "wifi.h"
#include "my_wifi.h"
#include "ota.h"
#include "my_fastled.h"
#include "EffectEntry.h"

View File

@ -1,12 +1,8 @@
#include <Arduino.h>
#if defined( ESP8266 )
#include <ESP8266WiFi.h>
#elif defined( ESP32 )
#include <WiFi.h>
#endif
#include "wifi.h"
#include "my_wifi.h"
#include "config.h"
void wifi_setup() {
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);