mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-01 03:47:23 +03:00
Migrate from astyle to clang-format (#8464)
This commit is contained in:
committed by
Max Prokhorov
parent
46190b61f1
commit
19b7a29720
@ -43,39 +43,38 @@
|
||||
Global defines and vars
|
||||
*/
|
||||
|
||||
#define TIMEZONE_OFFSET 1 // CET
|
||||
#define DST_OFFSET 1 // CEST
|
||||
#define UPDATE_CYCLE (1 * 1000) // every second
|
||||
#define TIMEZONE_OFFSET 1 // CET
|
||||
#define DST_OFFSET 1 // CEST
|
||||
#define UPDATE_CYCLE (1 * 1000) // every second
|
||||
|
||||
#define SERVICE_PORT 80 // HTTP port
|
||||
#define SERVICE_PORT 80 // HTTP port
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
|
||||
char* pcHostDomain = 0; // Negotiated host domain
|
||||
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain
|
||||
MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the clock service in the MDNS responder
|
||||
char* pcHostDomain = 0; // Negotiated host domain
|
||||
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain
|
||||
MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the clock service in the MDNS responder
|
||||
|
||||
// HTTP server at port 'SERVICE_PORT' will respond to HTTP requests
|
||||
ESP8266WebServer server(SERVICE_PORT);
|
||||
ESP8266WebServer server(SERVICE_PORT);
|
||||
|
||||
/*
|
||||
getTimeString
|
||||
*/
|
||||
const char* getTimeString(void) {
|
||||
|
||||
static char acTimeString[32];
|
||||
static char acTimeString[32];
|
||||
time_t now = time(nullptr);
|
||||
ctime_r(&now, acTimeString);
|
||||
size_t stLength;
|
||||
while (((stLength = strlen(acTimeString))) &&
|
||||
('\n' == acTimeString[stLength - 1])) {
|
||||
acTimeString[stLength - 1] = 0; // Remove trailing line break...
|
||||
size_t stLength;
|
||||
while (((stLength = strlen(acTimeString))) && ('\n' == acTimeString[stLength - 1])) {
|
||||
acTimeString[stLength - 1] = 0; // Remove trailing line break...
|
||||
}
|
||||
return acTimeString;
|
||||
}
|
||||
@ -186,7 +185,8 @@ void handleHTTPRequest() {
|
||||
Serial.println("HTTP Request");
|
||||
|
||||
// Get current time
|
||||
time_t now = time(nullptr);;
|
||||
time_t now = time(nullptr);
|
||||
;
|
||||
struct tm timeinfo;
|
||||
gmtime_r(&now, &timeinfo);
|
||||
|
||||
@ -231,10 +231,9 @@ void setup(void) {
|
||||
// Setup MDNS responder
|
||||
MDNS.setHostProbeResultCallback(hostProbeResult);
|
||||
// Init the (currently empty) host domain string with 'esp8266'
|
||||
if ((!MDNSResponder::indexDomain(pcHostDomain, 0, "esp8266")) ||
|
||||
(!MDNS.begin(pcHostDomain))) {
|
||||
if ((!MDNSResponder::indexDomain(pcHostDomain, 0, "esp8266")) || (!MDNS.begin(pcHostDomain))) {
|
||||
Serial.println("Error setting up MDNS responder!");
|
||||
while (1) { // STOP
|
||||
while (1) { // STOP
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
@ -39,26 +39,26 @@
|
||||
Global defines and vars
|
||||
*/
|
||||
|
||||
#define SERVICE_PORT 80 // HTTP port
|
||||
#define SERVICE_PORT 80 // HTTP port
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
|
||||
char* pcHostDomain = 0; // Negotiated host domain
|
||||
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain
|
||||
MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the http service in the MDNS responder
|
||||
MDNSResponder::hMDNSServiceQuery hMDNSServiceQuery = 0; // The handle of the 'http.tcp' service query in the MDNS responder
|
||||
char* pcHostDomain = 0; // Negotiated host domain
|
||||
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain
|
||||
MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the http service in the MDNS responder
|
||||
MDNSResponder::hMDNSServiceQuery hMDNSServiceQuery = 0; // The handle of the 'http.tcp' service query in the MDNS responder
|
||||
|
||||
const String cstrNoHTTPServices = "Currently no 'http.tcp' services in the local network!<br/>";
|
||||
String strHTTPServices = cstrNoHTTPServices;
|
||||
const String cstrNoHTTPServices = "Currently no 'http.tcp' services in the local network!<br/>";
|
||||
String strHTTPServices = cstrNoHTTPServices;
|
||||
|
||||
// HTTP server at port 'SERVICE_PORT' will respond to HTTP requests
|
||||
ESP8266WebServer server(SERVICE_PORT);
|
||||
ESP8266WebServer server(SERVICE_PORT);
|
||||
|
||||
|
||||
/*
|
||||
@ -80,26 +80,17 @@ bool setStationHostname(const char* p_pcHostname) {
|
||||
void MDNSServiceQueryCallback(MDNSResponder::MDNSServiceInfo serviceInfo, MDNSResponder::AnswerType answerType, bool p_bSetContent) {
|
||||
String answerInfo;
|
||||
switch (answerType) {
|
||||
case MDNSResponder::AnswerType::ServiceDomain :
|
||||
answerInfo = "ServiceDomain " + String(serviceInfo.serviceDomain());
|
||||
break;
|
||||
case MDNSResponder::AnswerType::HostDomainAndPort :
|
||||
answerInfo = "HostDomainAndPort " + String(serviceInfo.hostDomain()) + ":" + String(serviceInfo.hostPort());
|
||||
break;
|
||||
case MDNSResponder::AnswerType::IP4Address :
|
||||
case MDNSResponder::AnswerType::ServiceDomain: answerInfo = "ServiceDomain " + String(serviceInfo.serviceDomain()); break;
|
||||
case MDNSResponder::AnswerType::HostDomainAndPort: answerInfo = "HostDomainAndPort " + String(serviceInfo.hostDomain()) + ":" + String(serviceInfo.hostPort()); break;
|
||||
case MDNSResponder::AnswerType::IP4Address:
|
||||
answerInfo = "IP4Address ";
|
||||
for (IPAddress ip : serviceInfo.IP4Adresses()) {
|
||||
answerInfo += "- " + ip.toString();
|
||||
};
|
||||
for (IPAddress ip : serviceInfo.IP4Adresses()) { answerInfo += "- " + ip.toString(); };
|
||||
break;
|
||||
case MDNSResponder::AnswerType::Txt :
|
||||
case MDNSResponder::AnswerType::Txt:
|
||||
answerInfo = "TXT " + String(serviceInfo.strKeyValue());
|
||||
for (auto kv : serviceInfo.keyValues()) {
|
||||
answerInfo += "\nkv : " + String(kv.first) + " : " + String(kv.second);
|
||||
}
|
||||
for (auto kv : serviceInfo.keyValues()) { answerInfo += "\nkv : " + String(kv.first) + " : " + String(kv.second); }
|
||||
break;
|
||||
default :
|
||||
answerInfo = "Unknown Answertype";
|
||||
default: answerInfo = "Unknown Answertype";
|
||||
}
|
||||
Serial.printf("Answer %s %s\n", answerInfo.c_str(), p_bSetContent ? "Modified" : "Deleted");
|
||||
}
|
||||
@ -109,10 +100,8 @@ void MDNSServiceQueryCallback(MDNSResponder::MDNSServiceInfo serviceInfo, MDNSRe
|
||||
Probe result callback for Services
|
||||
*/
|
||||
|
||||
void serviceProbeResult(String p_pcServiceName,
|
||||
const MDNSResponder::hMDNSService p_hMDNSService,
|
||||
bool p_bProbeResult) {
|
||||
(void) p_hMDNSService;
|
||||
void serviceProbeResult(String p_pcServiceName, const MDNSResponder::hMDNSService p_hMDNSService, bool p_bProbeResult) {
|
||||
(void)p_hMDNSService;
|
||||
Serial.printf("MDNSServiceProbeResultCallback: Service %s probe %s\n", p_pcServiceName.c_str(), (p_bProbeResult ? "succeeded." : "failed!"));
|
||||
}
|
||||
|
||||
@ -186,7 +175,7 @@ void handleHTTPRequest() {
|
||||
s += WiFi.hostname() + ".local at " + WiFi.localIP().toString() + "</h3></head>";
|
||||
s += "<br/><h4>Local HTTP services are :</h4>";
|
||||
s += "<ol>";
|
||||
for (auto info : MDNS.answerInfo(hMDNSServiceQuery)) {
|
||||
for (auto info : MDNS.answerInfo(hMDNSServiceQuery)) {
|
||||
s += "<li>";
|
||||
s += info.serviceDomain();
|
||||
if (info.hostDomainAvailable()) {
|
||||
@ -196,15 +185,11 @@ void handleHTTPRequest() {
|
||||
}
|
||||
if (info.IP4AddressAvailable()) {
|
||||
s += "<br/>IP4:";
|
||||
for (auto ip : info.IP4Adresses()) {
|
||||
s += " " + ip.toString();
|
||||
}
|
||||
for (auto ip : info.IP4Adresses()) { s += " " + ip.toString(); }
|
||||
}
|
||||
if (info.txtAvailable()) {
|
||||
s += "<br/>TXT:<br/>";
|
||||
for (auto kv : info.keyValues()) {
|
||||
s += "\t" + String(kv.first) + " : " + String(kv.second) + "<br/>";
|
||||
}
|
||||
for (auto kv : info.keyValues()) { s += "\t" + String(kv.first) + " : " + String(kv.second) + "<br/>"; }
|
||||
}
|
||||
s += "</li>";
|
||||
}
|
||||
@ -245,10 +230,9 @@ void setup(void) {
|
||||
MDNS.setHostProbeResultCallback(hostProbeResult);
|
||||
|
||||
// Init the (currently empty) host domain string with 'esp8266'
|
||||
if ((!MDNSResponder::indexDomain(pcHostDomain, 0, "esp8266")) ||
|
||||
(!MDNS.begin(pcHostDomain))) {
|
||||
if ((!MDNSResponder::indexDomain(pcHostDomain, 0, "esp8266")) || (!MDNS.begin(pcHostDomain))) {
|
||||
Serial.println(" Error setting up MDNS responder!");
|
||||
while (1) { // STOP
|
||||
while (1) { // STOP
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
@ -265,6 +249,3 @@ void loop(void) {
|
||||
// Allow MDNS processing
|
||||
MDNS.update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -14,12 +14,12 @@
|
||||
|
||||
#ifndef APSSID
|
||||
#define APSSID "your-apssid"
|
||||
#define APPSK "your-password"
|
||||
#define APPSK "your-password"
|
||||
#endif
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-sta"
|
||||
#define STAPSK "your-password"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
// includes
|
||||
@ -35,15 +35,15 @@
|
||||
@brief mDNS and OTA Constants
|
||||
@{
|
||||
*/
|
||||
#define HOSTNAME "ESP8266-OTA-" ///< Hostname. The setup function adds the Chip ID at the end.
|
||||
#define HOSTNAME "ESP8266-OTA-" ///< Hostname. The setup function adds the Chip ID at the end.
|
||||
/// @}
|
||||
|
||||
/**
|
||||
@brief Default WiFi connection information.
|
||||
@{
|
||||
*/
|
||||
const char* ap_default_ssid = APSSID; ///< Default SSID.
|
||||
const char* ap_default_psk = APPSK; ///< Default PSK.
|
||||
const char *ap_default_ssid = APSSID; ///< Default SSID.
|
||||
const char *ap_default_psk = APPSK; ///< Default PSK.
|
||||
/// @}
|
||||
|
||||
/// Uncomment the next line for verbose output over UART.
|
||||
@ -81,9 +81,7 @@ bool loadConfig(String *ssid, String *pass) {
|
||||
if (pos == -1) {
|
||||
le = 1;
|
||||
pos = content.indexOf("\n");
|
||||
if (pos == -1) {
|
||||
pos = content.indexOf("\r");
|
||||
}
|
||||
if (pos == -1) { pos = content.indexOf("\r"); }
|
||||
}
|
||||
|
||||
// If there is no second line: Some information is missing.
|
||||
@ -110,7 +108,7 @@ bool loadConfig(String *ssid, String *pass) {
|
||||
#endif
|
||||
|
||||
return true;
|
||||
} // loadConfig
|
||||
} // loadConfig
|
||||
|
||||
|
||||
/**
|
||||
@ -135,7 +133,7 @@ bool saveConfig(String *ssid, String *pass) {
|
||||
configFile.close();
|
||||
|
||||
return true;
|
||||
} // saveConfig
|
||||
} // saveConfig
|
||||
|
||||
|
||||
/**
|
||||
@ -160,7 +158,7 @@ void setup() {
|
||||
|
||||
// Print hostname.
|
||||
Serial.println("Hostname: " + hostname);
|
||||
//Serial.println(WiFi.hostname());
|
||||
// Serial.println(WiFi.hostname());
|
||||
|
||||
|
||||
// Initialize file system.
|
||||
@ -170,7 +168,7 @@ void setup() {
|
||||
}
|
||||
|
||||
// Load wifi connection information.
|
||||
if (! loadConfig(&station_ssid, &station_psk)) {
|
||||
if (!loadConfig(&station_ssid, &station_psk)) {
|
||||
station_ssid = STASSID;
|
||||
station_psk = STAPSK;
|
||||
|
||||
@ -196,7 +194,7 @@ void setup() {
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// ... Uncomment this for debugging output.
|
||||
//WiFi.printDiag(Serial);
|
||||
// WiFi.printDiag(Serial);
|
||||
} else {
|
||||
// ... Begin with sdk config.
|
||||
WiFi.begin();
|
||||
@ -208,7 +206,7 @@ void setup() {
|
||||
unsigned long startTime = millis();
|
||||
while (WiFi.status() != WL_CONNECTED && millis() - startTime < 10000) {
|
||||
Serial.write('.');
|
||||
//Serial.print(WiFi.status());
|
||||
// Serial.print(WiFi.status());
|
||||
delay(500);
|
||||
}
|
||||
Serial.println();
|
||||
@ -245,4 +243,3 @@ void loop() {
|
||||
// Handle OTA server.
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
|
||||
|
@ -14,12 +14,12 @@
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
const char* ssid = STASSID;
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
char hostString[16] = {0};
|
||||
char hostString[16] = { 0 };
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
@ -43,14 +43,12 @@ void setup() {
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
if (!MDNS.begin(hostString)) {
|
||||
Serial.println("Error setting up MDNS responder!");
|
||||
}
|
||||
if (!MDNS.begin(hostString)) { Serial.println("Error setting up MDNS responder!"); }
|
||||
Serial.println("mDNS responder started");
|
||||
MDNS.addService("esp", "tcp", 8080); // Announce esp tcp service on port 8080
|
||||
MDNS.addService("esp", "tcp", 8080); // Announce esp tcp service on port 8080
|
||||
|
||||
Serial.println("Sending mDNS query");
|
||||
int n = MDNS.queryService("esp", "tcp"); // Send out query for esp tcp services
|
||||
int n = MDNS.queryService("esp", "tcp"); // Send out query for esp tcp services
|
||||
Serial.println("mDNS query done");
|
||||
if (n == 0) {
|
||||
Serial.println("no services found");
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
const char* ssid = STASSID;
|
||||
@ -57,9 +57,7 @@ void setup(void) {
|
||||
// we send our IP address on the WiFi network
|
||||
if (!MDNS.begin("esp8266")) {
|
||||
Serial.println("Error setting up MDNS responder!");
|
||||
while (1) {
|
||||
delay(1000);
|
||||
}
|
||||
while (1) { delay(1000); }
|
||||
}
|
||||
Serial.println("mDNS responder started");
|
||||
|
||||
@ -77,16 +75,12 @@ void loop(void) {
|
||||
|
||||
// Check if a client has connected
|
||||
WiFiClient client = server.accept();
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
if (!client) { return; }
|
||||
Serial.println("");
|
||||
Serial.println("New client");
|
||||
|
||||
// Wait for data from client to become available
|
||||
while (client.connected() && !client.available()) {
|
||||
delay(1);
|
||||
}
|
||||
while (client.connected() && !client.available()) { delay(1); }
|
||||
|
||||
// Read the first line of HTTP request
|
||||
String req = client.readStringUntil('\r');
|
||||
@ -121,4 +115,3 @@ void loop(void) {
|
||||
|
||||
Serial.println("Done with client");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user