mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
examples: format all .ino files
This formats all the example source files using Arduino style rules.
This commit is contained in:
committed by
Ivan Grokhotkov
parent
e226251b27
commit
61cd8d8385
@ -1,16 +1,16 @@
|
||||
/**
|
||||
* @file OTA-mDNS-SPIFFS.ino
|
||||
*
|
||||
* @author Pascal Gollor (http://www.pgollor.de/cms/)
|
||||
* @date 2015-09-18
|
||||
*
|
||||
* changelog:
|
||||
* 2015-10-22:
|
||||
* - Use new ArduinoOTA library.
|
||||
* - loadConfig function can handle different line endings
|
||||
* - remove mDNS studd. ArduinoOTA handle it.
|
||||
*
|
||||
*/
|
||||
@file OTA-mDNS-SPIFFS.ino
|
||||
|
||||
@author Pascal Gollor (http://www.pgollor.de/cms/)
|
||||
@date 2015-09-18
|
||||
|
||||
changelog:
|
||||
2015-10-22:
|
||||
- Use new ArduinoOTA library.
|
||||
- loadConfig function can handle different line endings
|
||||
- remove mDNS studd. ArduinoOTA handle it.
|
||||
|
||||
*/
|
||||
|
||||
// includes
|
||||
#include <ESP8266WiFi.h>
|
||||
@ -21,16 +21,16 @@
|
||||
|
||||
|
||||
/**
|
||||
* @brief mDNS and OTA Constants
|
||||
* @{
|
||||
*/
|
||||
@brief mDNS and OTA Constants
|
||||
@{
|
||||
*/
|
||||
#define HOSTNAME "ESP8266-OTA-" ///< Hostename. The setup function adds the Chip ID at the end.
|
||||
/// @}
|
||||
|
||||
/**
|
||||
* @brief Default WiFi connection information.
|
||||
* @{
|
||||
*/
|
||||
@brief Default WiFi connection information.
|
||||
@{
|
||||
*/
|
||||
const char* ap_default_ssid = "esp8266"; ///< Default SSID.
|
||||
const char* ap_default_psk = "esp8266esp8266"; ///< Default PSK.
|
||||
/// @}
|
||||
@ -39,21 +39,19 @@ const char* ap_default_psk = "esp8266esp8266"; ///< Default PSK.
|
||||
//#define SERIAL_VERBOSE
|
||||
|
||||
/**
|
||||
* @brief Read WiFi connection information from file system.
|
||||
* @param ssid String pointer for storing SSID.
|
||||
* @param pass String pointer for storing PSK.
|
||||
* @return True or False.
|
||||
*
|
||||
* The config file have to containt the WiFi SSID in the first line
|
||||
* and the WiFi PSK in the second line.
|
||||
* Line seperator can be \r\n (CR LF) \r or \n.
|
||||
*/
|
||||
bool loadConfig(String *ssid, String *pass)
|
||||
{
|
||||
@brief Read WiFi connection information from file system.
|
||||
@param ssid String pointer for storing SSID.
|
||||
@param pass String pointer for storing PSK.
|
||||
@return True or False.
|
||||
|
||||
The config file have to containt the WiFi SSID in the first line
|
||||
and the WiFi PSK in the second line.
|
||||
Line seperator can be \r\n (CR LF) \r or \n.
|
||||
*/
|
||||
bool loadConfig(String *ssid, String *pass) {
|
||||
// open file for reading.
|
||||
File configFile = SPIFFS.open("/cl_conf.txt", "r");
|
||||
if (!configFile)
|
||||
{
|
||||
if (!configFile) {
|
||||
Serial.println("Failed to open cl_conf.txt.");
|
||||
|
||||
return false;
|
||||
@ -62,26 +60,23 @@ bool loadConfig(String *ssid, String *pass)
|
||||
// Read content from config file.
|
||||
String content = configFile.readString();
|
||||
configFile.close();
|
||||
|
||||
|
||||
content.trim();
|
||||
|
||||
// Check if ther is a second line available.
|
||||
int8_t pos = content.indexOf("\r\n");
|
||||
uint8_t le = 2;
|
||||
// check for linux and mac line ending.
|
||||
if (pos == -1)
|
||||
{
|
||||
if (pos == -1) {
|
||||
le = 1;
|
||||
pos = content.indexOf("\n");
|
||||
if (pos == -1)
|
||||
{
|
||||
if (pos == -1) {
|
||||
pos = content.indexOf("\r");
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no second line: Some information is missing.
|
||||
if (pos == -1)
|
||||
{
|
||||
if (pos == -1) {
|
||||
Serial.println("Infvalid content.");
|
||||
Serial.println(content);
|
||||
|
||||
@ -95,30 +90,28 @@ bool loadConfig(String *ssid, String *pass)
|
||||
ssid->trim();
|
||||
pass->trim();
|
||||
|
||||
#ifdef SERIAL_VERBOSE
|
||||
#ifdef SERIAL_VERBOSE
|
||||
Serial.println("----- file content -----");
|
||||
Serial.println(content);
|
||||
Serial.println("----- file content -----");
|
||||
Serial.println("ssid: " + *ssid);
|
||||
Serial.println("psk: " + *pass);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return true;
|
||||
} // loadConfig
|
||||
|
||||
|
||||
/**
|
||||
* @brief Save WiFi SSID and PSK to configuration file.
|
||||
* @param ssid SSID as string pointer.
|
||||
* @param pass PSK as string pointer,
|
||||
* @return True or False.
|
||||
*/
|
||||
bool saveConfig(String *ssid, String *pass)
|
||||
{
|
||||
@brief Save WiFi SSID and PSK to configuration file.
|
||||
@param ssid SSID as string pointer.
|
||||
@param pass PSK as string pointer,
|
||||
@return True or False.
|
||||
*/
|
||||
bool saveConfig(String *ssid, String *pass) {
|
||||
// Open config file for writing.
|
||||
File configFile = SPIFFS.open("/cl_conf.txt", "w");
|
||||
if (!configFile)
|
||||
{
|
||||
if (!configFile) {
|
||||
Serial.println("Failed to open cl_conf.txt for writing");
|
||||
|
||||
return false;
|
||||
@ -129,21 +122,20 @@ bool saveConfig(String *ssid, String *pass)
|
||||
configFile.println(*pass);
|
||||
|
||||
configFile.close();
|
||||
|
||||
|
||||
return true;
|
||||
} // saveConfig
|
||||
|
||||
|
||||
/**
|
||||
* @brief Arduino setup function.
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
@brief Arduino setup function.
|
||||
*/
|
||||
void setup() {
|
||||
String station_ssid = "";
|
||||
String station_psk = "";
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
|
||||
delay(100);
|
||||
|
||||
Serial.println("\r\n");
|
||||
@ -161,15 +153,13 @@ void setup()
|
||||
|
||||
|
||||
// Initialize file system.
|
||||
if (!SPIFFS.begin())
|
||||
{
|
||||
if (!SPIFFS.begin()) {
|
||||
Serial.println("Failed to mount file system");
|
||||
return;
|
||||
}
|
||||
|
||||
// Load wifi connection information.
|
||||
if (! loadConfig(&station_ssid, &station_psk))
|
||||
{
|
||||
if (! loadConfig(&station_ssid, &station_psk)) {
|
||||
station_ssid = "";
|
||||
station_psk = "";
|
||||
|
||||
@ -178,15 +168,13 @@ void setup()
|
||||
|
||||
// Check WiFi connection
|
||||
// ... check mode
|
||||
if (WiFi.getMode() != WIFI_STA)
|
||||
{
|
||||
if (WiFi.getMode() != WIFI_STA) {
|
||||
WiFi.mode(WIFI_STA);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
// ... Compare file config with sdk config.
|
||||
if (WiFi.SSID() != station_ssid || WiFi.psk() != station_psk)
|
||||
{
|
||||
if (WiFi.SSID() != station_ssid || WiFi.psk() != station_psk) {
|
||||
Serial.println("WiFi config changed.");
|
||||
|
||||
// ... Try to connect to WiFi station.
|
||||
@ -198,9 +186,7 @@ void setup()
|
||||
|
||||
// ... Uncomment this for debugging output.
|
||||
//WiFi.printDiag(Serial);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// ... Begin with sdk config.
|
||||
WiFi.begin();
|
||||
}
|
||||
@ -209,8 +195,7 @@ void setup()
|
||||
|
||||
// ... Give ESP 10 seconds to connect to station.
|
||||
unsigned long startTime = millis();
|
||||
while (WiFi.status() != WL_CONNECTED && millis() - startTime < 10000)
|
||||
{
|
||||
while (WiFi.status() != WL_CONNECTED && millis() - startTime < 10000) {
|
||||
Serial.write('.');
|
||||
//Serial.print(WiFi.status());
|
||||
delay(500);
|
||||
@ -218,16 +203,13 @@ void setup()
|
||||
Serial.println();
|
||||
|
||||
// Check connection
|
||||
if(WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
// ... print IP Address
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Serial.println("Can not connect to WiFi station. Go into AP mode.");
|
||||
|
||||
|
||||
// Go into software AP mode.
|
||||
WiFi.mode(WIFI_AP);
|
||||
|
||||
@ -246,10 +228,9 @@ void setup()
|
||||
|
||||
|
||||
/**
|
||||
* @brief Arduino loop function.
|
||||
*/
|
||||
void loop()
|
||||
{
|
||||
@brief Arduino loop function.
|
||||
*/
|
||||
void loop() {
|
||||
// Handle OTA server.
|
||||
ArduinoOTA.handle();
|
||||
yield();
|
||||
|
Reference in New Issue
Block a user