summaryrefslogtreecommitdiffstats
path: root/f020_setup.ino
blob: 5c0c7e393c4af46ee41687e5d44153a7264db2f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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.println("");
  Serial.print("nastavljam dostopno tocko. SSID: " + String(dostopnatocka[0]) + " geslo: " + String(dostopnatocka[1]) + " ... ");
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(ipas, gatewayas, subnetas);
  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()));
  ftpSrv.begin(program_ime, readfile("/403/webgeslo.txt"));

  setSyncProvider(timeSyncProvider);
  setSyncInterval(30);



  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čen ukaz ali napač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("/api/fil", handleFile);
  server.on("/api/tud", handleForcedTimeUpdate);
  server.on("/test", handleTest);
  server.begin();
  if (razhroscevanje) Serial.println("(razhroscevanje): HTTP dela, vrata 80");
}