1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-21 22:50:55 +00:00

ESP8266 Compatibility, finally

This commit is contained in:
Lukas Bachschwell 2017-12-01 17:11:16 +01:00
parent 489ba045fb
commit 479792e335
3 changed files with 36 additions and 14 deletions

View File

@ -1,7 +1,12 @@
#include <ESPUI.h> #include <ESPUI.h>
#include <WiFi.h>
const char *ssid = "ESP32"; #if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
const char *ssid = "ESPUI";
const char *password = ""; const char *password = "";
long oldTime = 0; long oldTime = 0;
@ -10,7 +15,13 @@ bool switchi = false;
void setup(void) { void setup(void) {
Serial.begin(115200); Serial.begin(115200);
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
WiFi.setHostname(ssid);
#if defined(ESP32)
WiFi.setHostname(ssid);
#else
WiFi.hostname(ssid);
#endif
WiFi.softAP(ssid); WiFi.softAP(ssid);
// WiFi.softAP(ssid, password); // WiFi.softAP(ssid, password);
Serial.println(""); Serial.println("");

View File

@ -29,7 +29,7 @@ void deleteFile(fs::FS &fs, const char * path){
} }
} }
void writeFile(fs::FS &fs, const char * path, const char * message){ void writeFile(fs::FS &fs, const char * path, const char * data){
Serial.printf("Writing file: %s\n", path); Serial.printf("Writing file: %s\n", path);
File file = fs.open(path, FILE_WRITE); File file = fs.open(path, FILE_WRITE);
@ -37,7 +37,7 @@ void writeFile(fs::FS &fs, const char * path, const char * message){
Serial.println("Failed to open file for writing"); Serial.println("Failed to open file for writing");
return; return;
} }
if(file.print(message)){ if(file.print(FPSTR(data))){
Serial.println("File written"); Serial.println("File written");
} else { } else {
Serial.println("Write failed"); Serial.println("Write failed");
@ -67,14 +67,13 @@ deleteFile(SPIFFS, "/js/slider.js");
Serial.println('Cleanup done'); Serial.println('Cleanup done');
// Now write // Now write
writeFile(SPIFFS, "/index.htm", HTML_INDEX); writeFile(SPIFFS, "/index.htm", HTML_INDEX);
writeFile(SPIFFS, "/css/style.css", CSS_STYLE); writeFile(SPIFFS, "/css/style.css", CSS_STYLE);
writeFile(SPIFFS, "/css/normalize.css", CSS_NORMALIZE); writeFile(SPIFFS, "/css/normalize.css", CSS_NORMALIZE);
writeFile(SPIFFS, "/js/controls.js", JS_CONTROLS);
writeFile(SPIFFS, "/js/zepto.js", JS_ZEPTO); writeFile(SPIFFS, "/js/zepto.js", JS_ZEPTO);
writeFile(SPIFFS, "/js/controls.js", JS_CONTROLS);
writeFile(SPIFFS, "/js/slider.js", JS_SLIDER); writeFile(SPIFFS, "/js/slider.js", JS_SLIDER);
Serial.println("Done Initializing filesystem :-)"); Serial.println("Done Initializing filesystem :-)");

View File

@ -1,23 +1,35 @@
#ifndef ESPUI_h #ifndef ESPUI_h
#define ESPUI_h #define ESPUI_h
#define HARDWARE "esp32"
#define debug true #define debug true
// ifdef 8266
//#include "Hash.h"
#include "Arduino.h" #include "Arduino.h"
#include "ArduinoJson.h" #include "ArduinoJson.h"
#include "FS.h" #include "FS.h"
#include "SPIFFS.h"
#include "WiFi.h"
#include "stdlib_noniso.h" #include "stdlib_noniso.h"
#if defined(ESP32)
#include "SPIFFS.h"
#include "WiFi.h"
#include <AsyncTCP.h> #include <AsyncTCP.h>
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
#else
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#include <FS.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <SPIFFSEditor.h>
#define FILE_WRITE "w"
#endif
typedef struct Control { typedef struct Control {
unsigned int type; unsigned int type;
unsigned int id; // just mirroring the id here for practical reasons unsigned int id; // just mirroring the id here for practical reasons