@@ -37,7 +37,6 @@ static WebServer webServer(80);
37
37
static HTTPUpdateServer httpUpdater;
38
38
static Mycila::ESPConnect espConnect;
39
39
static Mycila::ESPConnect::Config espConnectConfig;
40
- static String hostname;
41
40
42
41
static String getChipIDStr () {
43
42
uint32_t chipId = 0 ;
@@ -64,17 +63,15 @@ void setup() {
64
63
logger.setLevel (ARDUHAL_LOG_LEVEL_DEBUG);
65
64
#endif
66
65
67
- // Init hostname
68
- hostname = " SafeBoot-" + getChipIDStr ();
69
66
LOGI (TAG, " SafeBoot Version: %s" , __COMPILED_APP_VERSION__);
70
67
LOGI (TAG, " Chip ID: %s" , getChipIDStr ().c_str ());
71
- LOGI (TAG, " Hostname: %s" , hostname.c_str ());
72
68
73
69
// Set next boot partition
74
70
const esp_partition_t * partition = esp_partition_find_first (esp_partition_type_t ::ESP_PARTITION_TYPE_APP, esp_partition_subtype_t ::ESP_PARTITION_SUBTYPE_APP_OTA_0, nullptr );
75
71
if (partition) {
76
72
esp_ota_set_boot_partition (partition);
77
73
}
74
+
78
75
// setup routes
79
76
HTTPUpdateServer::setVersion (__COMPILED_APP_VERSION__);
80
77
httpUpdater.setup (&webServer, " /" );
@@ -88,6 +85,11 @@ void setup() {
88
85
espConnect.setBlocking (true );
89
86
espConnect.setAutoRestart (false );
90
87
88
+ // reuse a potentially set hostname from main app, or set a default one
89
+ if (!espConnectConfig.hostname .length ()) {
90
+ espConnectConfig.hostname = " SafeBoot-" + getChipIDStr ();
91
+ }
92
+
91
93
// If the passed config is to be in AP mode, or has a SSID that's fine.
92
94
// If the passed config is empty, we need to check if the board supports ETH.
93
95
// - For boards relying only on Wifi, if a SSID is not set and AP is not set (config empty), then we need to go to AP mode.
@@ -111,28 +113,31 @@ void setup() {
111
113
});
112
114
113
115
// connect...
114
- espConnect.begin (hostname. c_str (), hostname.c_str (), " " , espConnectConfig);
116
+ espConnect.begin (espConnectConfig. hostname .c_str (), " " , espConnectConfig);
115
117
116
118
LOGI (TAG, " Connected to network!" );
117
119
LOGI (TAG, " IP Address: %s" , espConnect.getIPAddress ().toString ().c_str ());
118
120
LOGI (TAG, " Hostname: %s" , espConnect.getHostname ().c_str ());
119
121
if (espConnect.getWiFiSSID ().length ()) {
120
122
LOGI (TAG, " WiFi SSID: %s" , espConnect.getWiFiSSID ().c_str ());
121
123
}
124
+ if (espConnectConfig.apMode ) {
125
+ LOGI (TAG, " Access Point: %s" , espConnect.getAccessPointSSID ().c_str ());
126
+ }
122
127
123
128
// starte http
124
129
LOGI (TAG, " Starting HTTP server..." );
125
130
webServer.begin ();
126
131
127
132
#ifndef MYCILA_SAFEBOOT_NO_MDNS
128
133
// Start mDNS
129
- MDNS.begin (hostname.c_str ());
134
+ MDNS.begin (espConnectConfig. hostname .c_str ());
130
135
MDNS.addService (" http" , " tcp" , 80 );
131
136
#endif
132
137
133
138
// Start OTA
134
139
LOGI (TAG, " Starting OTA server..." );
135
- ArduinoOTA.setHostname (hostname.c_str ());
140
+ ArduinoOTA.setHostname (espConnectConfig. hostname .c_str ());
136
141
ArduinoOTA.setRebootOnSuccess (true );
137
142
ArduinoOTA.setMdnsEnabled (true );
138
143
ArduinoOTA.begin ();
0 commit comments