summaryrefslogtreecommitdiffstats
path: root/f020_setup.ino
diff options
context:
space:
mode:
authorAnton Šijanec <sijanecantonluka@gmail.com>2019-12-14 20:55:18 +0100
committerAnton Šijanec <sijanecantonluka@gmail.com>2019-12-14 20:55:18 +0100
commit7eaa0674d83351828a2e235752d21f160b5fe9af (patch)
tree2c2412b3f5a67410fe2c878f2f7cbf19232f0f76 /f020_setup.ino
parentfirst commit (diff)
downloadsijaneciot-7eaa0674d83351828a2e235752d21f160b5fe9af.tar
sijaneciot-7eaa0674d83351828a2e235752d21f160b5fe9af.tar.gz
sijaneciot-7eaa0674d83351828a2e235752d21f160b5fe9af.tar.bz2
sijaneciot-7eaa0674d83351828a2e235752d21f160b5fe9af.tar.lz
sijaneciot-7eaa0674d83351828a2e235752d21f160b5fe9af.tar.xz
sijaneciot-7eaa0674d83351828a2e235752d21f160b5fe9af.tar.zst
sijaneciot-7eaa0674d83351828a2e235752d21f160b5fe9af.zip
Diffstat (limited to 'f020_setup.ino')
-rw-r--r--f020_setup.ino71
1 files changed, 71 insertions, 0 deletions
diff --git a/f020_setup.ino b/f020_setup.ino
new file mode 100644
index 0000000..28de3b5
--- /dev/null
+++ b/f020_setup.ino
@@ -0,0 +1,71 @@
+void setup() {
+ SPIFFS.begin();
+ if (SPIFFS.exists("/403/pwmfreq.txt")) {
+ if (readfile("/403/pwmfreq.txt").toInt() > 0) {
+ analogWriteFreq(readfile("/403/pwmfreq.txt").toInt());
+ } else {
+ writefile("/403/pwmfreq.txt", "20000");
+ analogWriteFreq(20000);
+ }
+ }
+ if (!SPIFFS.exists("/403/webgeslo.txt")) {
+ writefile("/403/webgeslo.txt", "sijaneciot");
+ }
+ if (!SPIFFS.exists("/403/hostname.txt")) {
+ writefile("/403/hostname.txt", String(program_ime) + "" + String(ESP.getChipId()));
+ }
+ if (razhroscevanje) Serial.setDebugOutput(true);
+ Serial.begin(9600);
+ Serial.println();
+ String dostopnatocka[4];
+ if (SPIFFS.exists("/403/wifi-ap.txt")) {
+ explode(readfile("/403/wifi-ap.txt"), ",", dostopnatocka, 4);
+ } else {
+ if (razhroscevanje) Serial.println("(razhroscevanje): /403/wifi-ap.txt ne obstaja, privzeta wifi konfiguracija");
+ dostopnatocka[0] = String(program_ime) + "-" + String(ESP.getChipId());
+ dostopnatocka[1] = "";
+ dostopnatocka[2] = "1"; // kanal
+ dostopnatocka[3] = "0"; // skrito omrežje?
+ }
+ Serial.print("nastavljam dostopno tocko. SSID: " + String(dostopnatocka[0]) + " geslo: " + String(dostopnatocka[1]) + " ... ");
+ WiFi.mode(WIFI_AP);
+ WiFi.softAP(dostopnatocka[0].c_str(), dostopnatocka[1].c_str(), dostopnatocka[2].toInt(), dostopnatocka[3].toInt());
+ if (razhroscevanje) Serial.println("(razhroscevanje): wifi.softap --> IPv4 " + String(WiFi.softAPIP().toString()));
+ if (MDNS.begin(readfile("/403/hostname.txt"))) { // Start the mDNS responder for esp8266.local
+ if (razhroscevanje) Serial.println("(razhroscevanje): mDNS dela, " + readfile("/403/hostname.txt"));
+ } else {
+ if (razhroscevanje) Serial.println("(razhroscevanje): mDNS fejl");
+ }
+ ftpSrv.begin(program_ime, readfile("/403/webgeslo.txt"));
+
+ setSyncProvider(getNtpTime);
+ setSyncInterval(300);
+
+
+
+ server.on("/", handleRoot);
+ server.onNotFound([]() { // If the client requests any URI
+ if (!handleFileRead(server.uri())) // send it if it exists
+ server.send(404, "text/html", fihr(404, "Napa&ccaron;en ukaz ali napa&ccaron;no ime datoteke.")); // otherwise, respond with a 404 (Not Found) error
+ });
+ server.on("/api/upload", HTTP_POST, // if the client posts to the upload page
+ [](){ server.send(200); }, // Send status 200 (OK) to tell the client we are ready to receive
+ handleFileUpload // Receive and save the file
+ );
+ server.on("/api/pin", handlePin);
+ server.on("/api/res", handleRes);
+ server.on("/api/sap", handleSetAP);
+ server.on("/api/sta", handleSetSTA);
+ server.on("/api/gid", handleGetID);
+ server.on("/api/pwm", handlePWM);
+ server.on("/api/rst", handleRestart);
+ server.on("/api/slp", handleDeepSleep);
+ server.on("/api/now", handleUnixTimestamp);
+ server.on("/api/pwd", handleNewPassword);
+ server.on("/api/tms", handleTms);
+ server.on("/api/ren", handleRename); // \ prvi primer
+ server.on("/api/mov", handleRename); // / uporabe aliasa
+ server.on("/test", handleTest);
+ server.begin();
+ if (razhroscevanje) Serial.println("(razhroscevanje): HTTP dela, vrata 80");
+}