|
| 1 | + |
| 2 | +void configModeCallback (WiFiManager *myWiFiManager) { |
| 3 | + ticker.attach(0.2, tick); |
| 4 | +} |
| 5 | + |
| 6 | +void saveConfigCallback () { |
| 7 | + DEBUG_PRINTLN("Should save config"); |
| 8 | + shouldSaveConfig = true; |
| 9 | +} |
| 10 | + |
| 11 | +void setupWifiManager () { |
| 12 | + WiFiManagerParameter custom_device_id("device_id", "DeviceID", device_id, 40); |
| 13 | + WiFiManagerParameter custom_device_token("device_token", "DeviceToken", device_token, 70); |
| 14 | + WiFiManagerParameter custom_client_id("client_id", "ClientID", client_id, 40); |
| 15 | + |
| 16 | + WiFiManager wifiManager; |
| 17 | + |
| 18 | + wifiManager.setSaveConfigCallback(saveConfigCallback); |
| 19 | + wifiManager.setAPCallback(configModeCallback); |
| 20 | + |
| 21 | + wifiManager.addParameter(&custom_device_id); |
| 22 | + wifiManager.addParameter(&custom_device_token); |
| 23 | + wifiManager.addParameter(&custom_client_id); |
| 24 | + |
| 25 | + if (!wifiManager.autoConnect("ESP-32")) { |
| 26 | + DEBUG_PRINTLN("failed to connect and hit timeout"); |
| 27 | + delay(3000); |
| 28 | + |
| 29 | + ESP.restart(); |
| 30 | + delay(5000); |
| 31 | + } |
| 32 | + |
| 33 | + DEBUG_PRINTLN("[WIFI] Connected"); |
| 34 | + |
| 35 | + strcpy(device_id, custom_device_id.getValue()); |
| 36 | + strcpy(device_token, custom_device_token.getValue()); |
| 37 | + strcpy(client_id, custom_client_id.getValue()); |
| 38 | + |
| 39 | + if (shouldSaveConfig) { |
| 40 | + DEBUG_PRINTLN("saving config"); |
| 41 | + |
| 42 | + DEBUG_PRINTLN("DeviceID" + String(device_id)); |
| 43 | + DEBUG_PRINTLN("DeviceToken" + String(device_token)); |
| 44 | + DEBUG_PRINTLN("ClientID" + String(client_id)); |
| 45 | + |
| 46 | + setDeviceID(device_id); |
| 47 | + setDeviceToken(device_token); |
| 48 | + setClientID(client_id); |
| 49 | + } |
| 50 | + |
| 51 | + DEBUG_PRINT("[WIFI] IP: "); |
| 52 | + DEBUG_PRINTLN(WiFi.localIP()); |
| 53 | +} |
| 54 | + |
0 commit comments