mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +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,12 +1,12 @@
|
||||
/*
|
||||
ESP8266 Blink by Simon Peter
|
||||
Blink the blue LED on the ESP-01 module
|
||||
This example code is in the public domain
|
||||
|
||||
The blue LED on the ESP-01 module is connected to GPIO1
|
||||
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
|
||||
|
||||
Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
|
||||
ESP8266 Blink by Simon Peter
|
||||
Blink the blue LED on the ESP-01 module
|
||||
This example code is in the public domain
|
||||
|
||||
The blue LED on the ESP-01 module is connected to GPIO1
|
||||
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
|
||||
|
||||
Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
@ -16,8 +16,8 @@ void setup() {
|
||||
// the loop function runs over and over again forever
|
||||
void loop() {
|
||||
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
|
||||
// but actually the LED is on; this is because
|
||||
// it is active low on the ESP-01)
|
||||
// but actually the LED is on; this is because
|
||||
// it is active low on the ESP-01)
|
||||
delay(1000); // Wait for a second
|
||||
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
|
||||
delay(2000); // Wait for two seconds (to demonstrate the active low LED)
|
||||
|
@ -1,16 +1,16 @@
|
||||
/*
|
||||
ESP8266 BlinkWithoutDelay by Simon Peter
|
||||
Blink the blue LED on the ESP-01 module
|
||||
Based on the Arduino Blink without Delay example
|
||||
This example code is in the public domain
|
||||
|
||||
The blue LED on the ESP-01 module is connected to GPIO1
|
||||
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
|
||||
|
||||
Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
|
||||
/*
|
||||
ESP8266 BlinkWithoutDelay by Simon Peter
|
||||
Blink the blue LED on the ESP-01 module
|
||||
Based on the Arduino Blink without Delay example
|
||||
This example code is in the public domain
|
||||
|
||||
The blue LED on the ESP-01 module is connected to GPIO1
|
||||
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
|
||||
|
||||
Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
|
||||
*/
|
||||
|
||||
int ledState = LOW;
|
||||
int ledState = LOW;
|
||||
|
||||
unsigned long previousMillis = 0;
|
||||
const long interval = 1000;
|
||||
@ -19,15 +19,15 @@ void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
void loop() {
|
||||
unsigned long currentMillis = millis();
|
||||
if(currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
if (ledState == LOW)
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
if (ledState == LOW) {
|
||||
ledState = HIGH; // Note that this switches the LED *off*
|
||||
else
|
||||
ledState = LOW; // Note that this switches the LED *on*
|
||||
} else {
|
||||
ledState = LOW; // Note that this switches the LED *on*
|
||||
}
|
||||
digitalWrite(LED_BUILTIN, ledState);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
|
||||
/*
|
||||
* NativeSdk by Simon Peter
|
||||
* Access functionality from the Espressif ESP8266 SDK
|
||||
* This example code is in the public domain
|
||||
*
|
||||
* This is for advanced users.
|
||||
* Note that this makes your code dependent on the ESP8266, which is generally
|
||||
* a bad idea. So you should try to use esp8266/Arduino functionality
|
||||
* where possible instead, in order to abstract away the hardware dependency.
|
||||
*/
|
||||
NativeSdk by Simon Peter
|
||||
Access functionality from the Espressif ESP8266 SDK
|
||||
This example code is in the public domain
|
||||
|
||||
This is for advanced users.
|
||||
Note that this makes your code dependent on the ESP8266, which is generally
|
||||
a bad idea. So you should try to use esp8266/Arduino functionality
|
||||
where possible instead, in order to abstract away the hardware dependency.
|
||||
*/
|
||||
|
||||
// Expose Espressif SDK functionality - wrapped in ifdef so that it still
|
||||
// compiles on other platforms
|
||||
@ -25,9 +25,9 @@ void setup() {
|
||||
void loop() {
|
||||
// Call Espressif SDK functionality - wrapped in ifdef so that it still
|
||||
// compiles on other platforms
|
||||
#ifdef ESP8266
|
||||
#ifdef ESP8266
|
||||
Serial.print("wifi_station_get_hostname: ");
|
||||
Serial.println(wifi_station_get_hostname());
|
||||
#endif
|
||||
#endif
|
||||
delay(1000);
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
/*
|
||||
ESP8266 CheckFlashConfig by Markus Sattler
|
||||
|
||||
This sketch tests if the EEPROM settings of the IDE match to the Hardware
|
||||
|
||||
*/
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
uint32_t realSize = ESP.getFlashChipRealSize();
|
||||
uint32_t ideSize = ESP.getFlashChipSize();
|
||||
FlashMode_t ideMode = ESP.getFlashChipMode();
|
||||
|
||||
Serial.printf("Flash real id: %08X\n", ESP.getFlashChipId());
|
||||
Serial.printf("Flash real size: %u\n\n", realSize);
|
||||
|
||||
Serial.printf("Flash ide size: %u\n", ideSize);
|
||||
Serial.printf("Flash ide speed: %u\n", ESP.getFlashChipSpeed());
|
||||
Serial.printf("Flash ide mode: %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));
|
||||
|
||||
if(ideSize != realSize) {
|
||||
Serial.println("Flash Chip configuration wrong!\n");
|
||||
} else {
|
||||
Serial.println("Flash Chip configuration ok.\n");
|
||||
}
|
||||
|
||||
delay(5000);
|
||||
}
|
||||
/*
|
||||
ESP8266 CheckFlashConfig by Markus Sattler
|
||||
|
||||
This sketch tests if the EEPROM settings of the IDE match to the Hardware
|
||||
|
||||
*/
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
uint32_t realSize = ESP.getFlashChipRealSize();
|
||||
uint32_t ideSize = ESP.getFlashChipSize();
|
||||
FlashMode_t ideMode = ESP.getFlashChipMode();
|
||||
|
||||
Serial.printf("Flash real id: %08X\n", ESP.getFlashChipId());
|
||||
Serial.printf("Flash real size: %u\n\n", realSize);
|
||||
|
||||
Serial.printf("Flash ide size: %u\n", ideSize);
|
||||
Serial.printf("Flash ide speed: %u\n", ESP.getFlashChipSpeed());
|
||||
Serial.printf("Flash ide mode: %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));
|
||||
|
||||
if (ideSize != realSize) {
|
||||
Serial.println("Flash Chip configuration wrong!\n");
|
||||
} else {
|
||||
Serial.println("Flash Chip configuration ok.\n");
|
||||
}
|
||||
|
||||
delay(5000);
|
||||
}
|
||||
|
@ -36,8 +36,7 @@
|
||||
timeval cbtime; // time set in callback
|
||||
bool cbtime_set = false;
|
||||
|
||||
void time_is_set (void)
|
||||
{
|
||||
void time_is_set(void) {
|
||||
gettimeofday(&cbtime, NULL);
|
||||
cbtime_set = true;
|
||||
Serial.println("------------------ settimeofday() was called ------------------");
|
||||
@ -47,7 +46,7 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
settimeofday_cb(time_is_set);
|
||||
|
||||
#if NTP0_OR_LOCAL1
|
||||
#if NTP0_OR_LOCAL1
|
||||
// local
|
||||
|
||||
ESP.eraseConfig();
|
||||
@ -56,14 +55,14 @@ void setup() {
|
||||
timezone tz = { TZ_MN + DST_MN, 0 };
|
||||
settimeofday(&tv, &tz);
|
||||
|
||||
#else // ntp
|
||||
#else // ntp
|
||||
|
||||
configTime(TZ_SEC, DST_SEC, "pool.ntp.org");
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(SSID, SSIDPWD);
|
||||
// don't wait, observe time changing when ntp timestamp is received
|
||||
|
||||
#endif // ntp
|
||||
#endif // ntp
|
||||
}
|
||||
|
||||
// for testing purpose:
|
||||
@ -73,7 +72,7 @@ extern "C" int clock_gettime(clockid_t unused, struct timespec *tp);
|
||||
Serial.print(":" #w "="); \
|
||||
Serial.print(tm->tm_##w);
|
||||
|
||||
void printTm (const char* what, const tm* tm) {
|
||||
void printTm(const char* what, const tm* tm) {
|
||||
Serial.print(what);
|
||||
PTM(isdst); PTM(yday); PTM(wday);
|
||||
PTM(year); PTM(mon); PTM(mday);
|
||||
|
@ -38,15 +38,14 @@ void setup() {
|
||||
Serial.println("Read: ");
|
||||
printMemory();
|
||||
Serial.println();
|
||||
uint32_t crcOfData = calculateCRC32( (uint8_t*) &rtcData.data[0], sizeof(rtcData.data) );
|
||||
uint32_t crcOfData = calculateCRC32((uint8_t*) &rtcData.data[0], sizeof(rtcData.data));
|
||||
Serial.print("CRC32 of data: ");
|
||||
Serial.println(crcOfData, HEX);
|
||||
Serial.print("CRC32 read from RTC: ");
|
||||
Serial.println(rtcData.crc32, HEX);
|
||||
if (crcOfData != rtcData.crc32) {
|
||||
Serial.println("CRC32 in RTC memory doesn't match CRC32 of data. Data is probably invalid!");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Serial.println("CRC32 check ok, data is probably valid.");
|
||||
}
|
||||
}
|
||||
@ -56,7 +55,7 @@ void setup() {
|
||||
rtcData.data[i] = random(0, 128);
|
||||
}
|
||||
// Update CRC32 of data
|
||||
rtcData.crc32 = calculateCRC32( (uint8_t*) &rtcData.data[0], sizeof(rtcData.data) );
|
||||
rtcData.crc32 = calculateCRC32((uint8_t*) &rtcData.data[0], sizeof(rtcData.data));
|
||||
// Write struct to RTC memory
|
||||
if (ESP.rtcUserMemoryWrite(0, (uint32_t*) &rtcData, sizeof(rtcData))) {
|
||||
Serial.println("Write: ");
|
||||
@ -71,8 +70,7 @@ void setup() {
|
||||
void loop() {
|
||||
}
|
||||
|
||||
uint32_t calculateCRC32(const uint8_t *data, size_t length)
|
||||
{
|
||||
uint32_t calculateCRC32(const uint8_t *data, size_t length) {
|
||||
uint32_t crc = 0xffffffff;
|
||||
while (length--) {
|
||||
uint8_t c = *data++;
|
||||
@ -99,8 +97,7 @@ void printMemory() {
|
||||
Serial.print(buf);
|
||||
if ((i + 1) % 32 == 0) {
|
||||
Serial.println();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Serial.print(" ");
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
/**
|
||||
* TestEspApi by Max Vilimpoc
|
||||
* This code is released to the public domain.
|
||||
*
|
||||
* Test out the Expressif ESP8266 Non-OS API, exhaustively trying out
|
||||
* as many of the built-in functions as possible.
|
||||
*
|
||||
* Some of the code is based on examples in:
|
||||
* "20A-ESP8266__RTOS_SDK__Programming Guide__EN_v1.3.0.pdf"
|
||||
*/
|
||||
TestEspApi by Max Vilimpoc
|
||||
This code is released to the public domain.
|
||||
|
||||
Test out the Expressif ESP8266 Non-OS API, exhaustively trying out
|
||||
as many of the built-in functions as possible.
|
||||
|
||||
Some of the code is based on examples in:
|
||||
"20A-ESP8266__RTOS_SDK__Programming Guide__EN_v1.3.0.pdf"
|
||||
*/
|
||||
|
||||
#ifdef ESP8266
|
||||
extern "C" {
|
||||
@ -23,291 +23,274 @@ Stream& ehConsolePort(Serial);
|
||||
// Wired to the blue LED on an ESP-01 board, active LOW.
|
||||
//
|
||||
// Cannot be used simultaneously with Serial.print/println()
|
||||
// calls, as TX is wired to the same pin.
|
||||
// calls, as TX is wired to the same pin.
|
||||
//
|
||||
// UNLESS: You swap the TX pin using the alternate pinout.
|
||||
const uint8_t LED_PIN = 1;
|
||||
|
||||
const char * const RST_REASONS[] =
|
||||
{
|
||||
"REASON_DEFAULT_RST",
|
||||
"REASON_WDT_RST",
|
||||
"REASON_EXCEPTION_RST",
|
||||
"REASON_SOFT_WDT_RST",
|
||||
"REASON_SOFT_RESTART",
|
||||
"REASON_DEEP_SLEEP_AWAKE",
|
||||
"REASON_EXT_SYS_RST"
|
||||
const char * const RST_REASONS[] = {
|
||||
"REASON_DEFAULT_RST",
|
||||
"REASON_WDT_RST",
|
||||
"REASON_EXCEPTION_RST",
|
||||
"REASON_SOFT_WDT_RST",
|
||||
"REASON_SOFT_RESTART",
|
||||
"REASON_DEEP_SLEEP_AWAKE",
|
||||
"REASON_EXT_SYS_RST"
|
||||
};
|
||||
|
||||
const char * const FLASH_SIZE_MAP_NAMES[] =
|
||||
{
|
||||
"FLASH_SIZE_4M_MAP_256_256",
|
||||
"FLASH_SIZE_2M",
|
||||
"FLASH_SIZE_8M_MAP_512_512",
|
||||
"FLASH_SIZE_16M_MAP_512_512",
|
||||
"FLASH_SIZE_32M_MAP_512_512",
|
||||
"FLASH_SIZE_16M_MAP_1024_1024",
|
||||
"FLASH_SIZE_32M_MAP_1024_1024"
|
||||
const char * const FLASH_SIZE_MAP_NAMES[] = {
|
||||
"FLASH_SIZE_4M_MAP_256_256",
|
||||
"FLASH_SIZE_2M",
|
||||
"FLASH_SIZE_8M_MAP_512_512",
|
||||
"FLASH_SIZE_16M_MAP_512_512",
|
||||
"FLASH_SIZE_32M_MAP_512_512",
|
||||
"FLASH_SIZE_16M_MAP_1024_1024",
|
||||
"FLASH_SIZE_32M_MAP_1024_1024"
|
||||
};
|
||||
|
||||
const char * const OP_MODE_NAMES[]
|
||||
{
|
||||
"NULL_MODE",
|
||||
"STATION_MODE",
|
||||
"SOFTAP_MODE",
|
||||
"STATIONAP_MODE"
|
||||
const char * const OP_MODE_NAMES[] {
|
||||
"NULL_MODE",
|
||||
"STATION_MODE",
|
||||
"SOFTAP_MODE",
|
||||
"STATIONAP_MODE"
|
||||
};
|
||||
|
||||
const char * const AUTH_MODE_NAMES[]
|
||||
{
|
||||
"AUTH_OPEN",
|
||||
"AUTH_WEP",
|
||||
"AUTH_WPA_PSK",
|
||||
"AUTH_WPA2_PSK",
|
||||
"AUTH_WPA_WPA2_PSK",
|
||||
"AUTH_MAX"
|
||||
const char * const AUTH_MODE_NAMES[] {
|
||||
"AUTH_OPEN",
|
||||
"AUTH_WEP",
|
||||
"AUTH_WPA_PSK",
|
||||
"AUTH_WPA2_PSK",
|
||||
"AUTH_WPA_WPA2_PSK",
|
||||
"AUTH_MAX"
|
||||
};
|
||||
|
||||
const char * const PHY_MODE_NAMES[]
|
||||
{
|
||||
"",
|
||||
"PHY_MODE_11B",
|
||||
"PHY_MODE_11G",
|
||||
"PHY_MODE_11N"
|
||||
const char * const PHY_MODE_NAMES[] {
|
||||
"",
|
||||
"PHY_MODE_11B",
|
||||
"PHY_MODE_11G",
|
||||
"PHY_MODE_11N"
|
||||
};
|
||||
|
||||
const char * const EVENT_NAMES[]
|
||||
{
|
||||
"EVENT_STAMODE_CONNECTED",
|
||||
"EVENT_STAMODE_DISCONNECTED",
|
||||
"EVENT_STAMODE_AUTHMODE_CHANGE",
|
||||
"EVENT_STAMODE_GOT_IP",
|
||||
"EVENT_SOFTAPMODE_STACONNECTED",
|
||||
"EVENT_SOFTAPMODE_STADISCONNECTED",
|
||||
"EVENT_MAX"
|
||||
const char * const EVENT_NAMES[] {
|
||||
"EVENT_STAMODE_CONNECTED",
|
||||
"EVENT_STAMODE_DISCONNECTED",
|
||||
"EVENT_STAMODE_AUTHMODE_CHANGE",
|
||||
"EVENT_STAMODE_GOT_IP",
|
||||
"EVENT_SOFTAPMODE_STACONNECTED",
|
||||
"EVENT_SOFTAPMODE_STADISCONNECTED",
|
||||
"EVENT_MAX"
|
||||
};
|
||||
|
||||
const char * const EVENT_REASONS[]
|
||||
{
|
||||
"",
|
||||
"REASON_UNSPECIFIED",
|
||||
"REASON_AUTH_EXPIRE",
|
||||
"REASON_AUTH_LEAVE",
|
||||
"REASON_ASSOC_EXPIRE",
|
||||
"REASON_ASSOC_TOOMANY",
|
||||
"REASON_NOT_AUTHED",
|
||||
"REASON_NOT_ASSOCED",
|
||||
"REASON_ASSOC_LEAVE",
|
||||
"REASON_ASSOC_NOT_AUTHED",
|
||||
"REASON_DISASSOC_PWRCAP_BAD",
|
||||
"REASON_DISASSOC_SUPCHAN_BAD",
|
||||
"REASON_IE_INVALID",
|
||||
"REASON_MIC_FAILURE",
|
||||
"REASON_4WAY_HANDSHAKE_TIMEOUT",
|
||||
"REASON_GROUP_KEY_UPDATE_TIMEOUT",
|
||||
"REASON_IE_IN_4WAY_DIFFERS",
|
||||
"REASON_GROUP_CIPHER_INVALID",
|
||||
"REASON_PAIRWISE_CIPHER_INVALID",
|
||||
"REASON_AKMP_INVALID",
|
||||
"REASON_UNSUPP_RSN_IE_VERSION",
|
||||
"REASON_INVALID_RSN_IE_CAP",
|
||||
"REASON_802_1X_AUTH_FAILED",
|
||||
"REASON_CIPHER_SUITE_REJECTED",
|
||||
const char * const EVENT_REASONS[] {
|
||||
"",
|
||||
"REASON_UNSPECIFIED",
|
||||
"REASON_AUTH_EXPIRE",
|
||||
"REASON_AUTH_LEAVE",
|
||||
"REASON_ASSOC_EXPIRE",
|
||||
"REASON_ASSOC_TOOMANY",
|
||||
"REASON_NOT_AUTHED",
|
||||
"REASON_NOT_ASSOCED",
|
||||
"REASON_ASSOC_LEAVE",
|
||||
"REASON_ASSOC_NOT_AUTHED",
|
||||
"REASON_DISASSOC_PWRCAP_BAD",
|
||||
"REASON_DISASSOC_SUPCHAN_BAD",
|
||||
"REASON_IE_INVALID",
|
||||
"REASON_MIC_FAILURE",
|
||||
"REASON_4WAY_HANDSHAKE_TIMEOUT",
|
||||
"REASON_GROUP_KEY_UPDATE_TIMEOUT",
|
||||
"REASON_IE_IN_4WAY_DIFFERS",
|
||||
"REASON_GROUP_CIPHER_INVALID",
|
||||
"REASON_PAIRWISE_CIPHER_INVALID",
|
||||
"REASON_AKMP_INVALID",
|
||||
"REASON_UNSUPP_RSN_IE_VERSION",
|
||||
"REASON_INVALID_RSN_IE_CAP",
|
||||
"REASON_802_1X_AUTH_FAILED",
|
||||
"REASON_CIPHER_SUITE_REJECTED",
|
||||
};
|
||||
|
||||
const char * const EVENT_REASONS_200[]
|
||||
{
|
||||
"REASON_BEACON_TIMEOUT",
|
||||
"REASON_NO_AP_FOUND"
|
||||
const char * const EVENT_REASONS_200[] {
|
||||
"REASON_BEACON_TIMEOUT",
|
||||
"REASON_NO_AP_FOUND"
|
||||
};
|
||||
|
||||
void wifi_event_handler_cb(System_Event_t * event)
|
||||
{
|
||||
ehConsolePort.print(EVENT_NAMES[event->event]);
|
||||
ehConsolePort.print(" (");
|
||||
|
||||
switch (event->event)
|
||||
{
|
||||
case EVENT_STAMODE_CONNECTED:
|
||||
break;
|
||||
case EVENT_STAMODE_DISCONNECTED:
|
||||
break;
|
||||
case EVENT_STAMODE_AUTHMODE_CHANGE:
|
||||
break;
|
||||
case EVENT_STAMODE_GOT_IP:
|
||||
break;
|
||||
case EVENT_SOFTAPMODE_STACONNECTED:
|
||||
case EVENT_SOFTAPMODE_STADISCONNECTED:
|
||||
{
|
||||
char mac[32] = {0};
|
||||
snprintf(mac, 32, MACSTR ", aid: %d" , MAC2STR(event->event_info.sta_connected.mac), event->event_info.sta_connected.aid);
|
||||
|
||||
ehConsolePort.print(mac);
|
||||
}
|
||||
break;
|
||||
}
|
||||
void wifi_event_handler_cb(System_Event_t * event) {
|
||||
ehConsolePort.print(EVENT_NAMES[event->event]);
|
||||
ehConsolePort.print(" (");
|
||||
|
||||
ehConsolePort.println(")");
|
||||
switch (event->event) {
|
||||
case EVENT_STAMODE_CONNECTED:
|
||||
break;
|
||||
case EVENT_STAMODE_DISCONNECTED:
|
||||
break;
|
||||
case EVENT_STAMODE_AUTHMODE_CHANGE:
|
||||
break;
|
||||
case EVENT_STAMODE_GOT_IP:
|
||||
break;
|
||||
case EVENT_SOFTAPMODE_STACONNECTED:
|
||||
case EVENT_SOFTAPMODE_STADISCONNECTED: {
|
||||
char mac[32] = {0};
|
||||
snprintf(mac, 32, MACSTR ", aid: %d", MAC2STR(event->event_info.sta_connected.mac), event->event_info.sta_connected.aid);
|
||||
|
||||
ehConsolePort.print(mac);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ehConsolePort.println(")");
|
||||
}
|
||||
|
||||
void print_softap_config(Stream & consolePort, softap_config const& config)
|
||||
{
|
||||
consolePort.println();
|
||||
consolePort.println(F("SoftAP Configuration"));
|
||||
consolePort.println(F("--------------------"));
|
||||
void print_softap_config(Stream & consolePort, softap_config const& config) {
|
||||
consolePort.println();
|
||||
consolePort.println(F("SoftAP Configuration"));
|
||||
consolePort.println(F("--------------------"));
|
||||
|
||||
consolePort.print(F("ssid: "));
|
||||
consolePort.println((char *) config.ssid);
|
||||
consolePort.print(F("ssid: "));
|
||||
consolePort.println((char *) config.ssid);
|
||||
|
||||
consolePort.print(F("password: "));
|
||||
consolePort.println((char *) config.password);
|
||||
consolePort.print(F("password: "));
|
||||
consolePort.println((char *) config.password);
|
||||
|
||||
consolePort.print(F("ssid_len: "));
|
||||
consolePort.println(config.ssid_len);
|
||||
consolePort.print(F("ssid_len: "));
|
||||
consolePort.println(config.ssid_len);
|
||||
|
||||
consolePort.print(F("channel: "));
|
||||
consolePort.println(config.channel);
|
||||
consolePort.print(F("channel: "));
|
||||
consolePort.println(config.channel);
|
||||
|
||||
consolePort.print(F("authmode: "));
|
||||
consolePort.println(AUTH_MODE_NAMES[config.authmode]);
|
||||
consolePort.print(F("authmode: "));
|
||||
consolePort.println(AUTH_MODE_NAMES[config.authmode]);
|
||||
|
||||
consolePort.print(F("ssid_hidden: "));
|
||||
consolePort.println(config.ssid_hidden);
|
||||
consolePort.print(F("ssid_hidden: "));
|
||||
consolePort.println(config.ssid_hidden);
|
||||
|
||||
consolePort.print(F("max_connection: "));
|
||||
consolePort.println(config.max_connection);
|
||||
consolePort.print(F("max_connection: "));
|
||||
consolePort.println(config.max_connection);
|
||||
|
||||
consolePort.print(F("beacon_interval: "));
|
||||
consolePort.print(config.beacon_interval);
|
||||
consolePort.println("ms");
|
||||
consolePort.print(F("beacon_interval: "));
|
||||
consolePort.print(config.beacon_interval);
|
||||
consolePort.println("ms");
|
||||
|
||||
consolePort.println(F("--------------------"));
|
||||
consolePort.println();
|
||||
consolePort.println(F("--------------------"));
|
||||
consolePort.println();
|
||||
}
|
||||
|
||||
void print_system_info(Stream & consolePort)
|
||||
{
|
||||
const rst_info * resetInfo = system_get_rst_info();
|
||||
consolePort.print(F("system_get_rst_info() reset reason: "));
|
||||
consolePort.println(RST_REASONS[resetInfo->reason]);
|
||||
void print_system_info(Stream & consolePort) {
|
||||
const rst_info * resetInfo = system_get_rst_info();
|
||||
consolePort.print(F("system_get_rst_info() reset reason: "));
|
||||
consolePort.println(RST_REASONS[resetInfo->reason]);
|
||||
|
||||
consolePort.print(F("system_get_free_heap_size(): "));
|
||||
consolePort.println(system_get_free_heap_size());
|
||||
consolePort.print(F("system_get_free_heap_size(): "));
|
||||
consolePort.println(system_get_free_heap_size());
|
||||
|
||||
consolePort.print(F("system_get_os_print(): "));
|
||||
consolePort.println(system_get_os_print());
|
||||
system_set_os_print(1);
|
||||
consolePort.print(F("system_get_os_print(): "));
|
||||
consolePort.println(system_get_os_print());
|
||||
consolePort.print(F("system_get_os_print(): "));
|
||||
consolePort.println(system_get_os_print());
|
||||
system_set_os_print(1);
|
||||
consolePort.print(F("system_get_os_print(): "));
|
||||
consolePort.println(system_get_os_print());
|
||||
|
||||
system_print_meminfo();
|
||||
system_print_meminfo();
|
||||
|
||||
consolePort.print(F("system_get_chip_id(): 0x"));
|
||||
consolePort.println(system_get_chip_id(), HEX);
|
||||
consolePort.print(F("system_get_chip_id(): 0x"));
|
||||
consolePort.println(system_get_chip_id(), HEX);
|
||||
|
||||
consolePort.print(F("system_get_sdk_version(): "));
|
||||
consolePort.println(system_get_sdk_version());
|
||||
consolePort.print(F("system_get_sdk_version(): "));
|
||||
consolePort.println(system_get_sdk_version());
|
||||
|
||||
consolePort.print(F("system_get_boot_version(): "));
|
||||
consolePort.println(system_get_boot_version());
|
||||
consolePort.print(F("system_get_boot_version(): "));
|
||||
consolePort.println(system_get_boot_version());
|
||||
|
||||
consolePort.print(F("system_get_userbin_addr(): 0x"));
|
||||
consolePort.println(system_get_userbin_addr(), HEX);
|
||||
consolePort.print(F("system_get_userbin_addr(): 0x"));
|
||||
consolePort.println(system_get_userbin_addr(), HEX);
|
||||
|
||||
consolePort.print(F("system_get_boot_mode(): "));
|
||||
consolePort.println(system_get_boot_mode() == 0 ? F("SYS_BOOT_ENHANCE_MODE") : F("SYS_BOOT_NORMAL_MODE"));
|
||||
consolePort.print(F("system_get_boot_mode(): "));
|
||||
consolePort.println(system_get_boot_mode() == 0 ? F("SYS_BOOT_ENHANCE_MODE") : F("SYS_BOOT_NORMAL_MODE"));
|
||||
|
||||
consolePort.print(F("system_get_cpu_freq(): "));
|
||||
consolePort.println(system_get_cpu_freq());
|
||||
consolePort.print(F("system_get_cpu_freq(): "));
|
||||
consolePort.println(system_get_cpu_freq());
|
||||
|
||||
consolePort.print(F("system_get_flash_size_map(): "));
|
||||
consolePort.println(FLASH_SIZE_MAP_NAMES[system_get_flash_size_map()]);
|
||||
consolePort.print(F("system_get_flash_size_map(): "));
|
||||
consolePort.println(FLASH_SIZE_MAP_NAMES[system_get_flash_size_map()]);
|
||||
}
|
||||
|
||||
void print_wifi_general(Stream & consolePort)
|
||||
{
|
||||
consolePort.print(F("wifi_get_channel(): "));
|
||||
consolePort.println(wifi_get_channel());
|
||||
|
||||
consolePort.print(F("wifi_get_phy_mode(): "));
|
||||
consolePort.println(PHY_MODE_NAMES[wifi_get_phy_mode()]);
|
||||
void print_wifi_general(Stream & consolePort) {
|
||||
consolePort.print(F("wifi_get_channel(): "));
|
||||
consolePort.println(wifi_get_channel());
|
||||
|
||||
consolePort.print(F("wifi_get_phy_mode(): "));
|
||||
consolePort.println(PHY_MODE_NAMES[wifi_get_phy_mode()]);
|
||||
}
|
||||
|
||||
void secure_softap_config(softap_config * config, const char * ssid, const char * password)
|
||||
{
|
||||
size_t ssidLen = strlen(ssid) < sizeof(config->ssid) ? strlen(ssid) : sizeof(config->ssid);
|
||||
size_t passwordLen = strlen(password) < sizeof(config->password) ? strlen(password) : sizeof(config->password);
|
||||
void secure_softap_config(softap_config * config, const char * ssid, const char * password) {
|
||||
size_t ssidLen = strlen(ssid) < sizeof(config->ssid) ? strlen(ssid) : sizeof(config->ssid);
|
||||
size_t passwordLen = strlen(password) < sizeof(config->password) ? strlen(password) : sizeof(config->password);
|
||||
|
||||
memset(config->ssid, 0, sizeof(config->ssid));
|
||||
memcpy(config->ssid, ssid, ssidLen);
|
||||
memset(config->ssid, 0, sizeof(config->ssid));
|
||||
memcpy(config->ssid, ssid, ssidLen);
|
||||
|
||||
memset(config->password, 0, sizeof(config->password));
|
||||
memcpy(config->password, password, passwordLen);
|
||||
memset(config->password, 0, sizeof(config->password));
|
||||
memcpy(config->password, password, passwordLen);
|
||||
|
||||
config->ssid_len = ssidLen;
|
||||
config->channel = 1;
|
||||
config->authmode = AUTH_WPA2_PSK;
|
||||
// config->ssid_hidden = 1;
|
||||
config->max_connection = 4;
|
||||
// config->beacon_interval = 1000;
|
||||
config->ssid_len = ssidLen;
|
||||
config->channel = 1;
|
||||
config->authmode = AUTH_WPA2_PSK;
|
||||
// config->ssid_hidden = 1;
|
||||
config->max_connection = 4;
|
||||
// config->beacon_interval = 1000;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Reuse default Serial port rate, so the bootloader
|
||||
// messages are also readable.
|
||||
|
||||
Serial.begin(74880);
|
||||
void setup() {
|
||||
// Reuse default Serial port rate, so the bootloader
|
||||
// messages are also readable.
|
||||
|
||||
// Try pushing frequency to 160MHz.
|
||||
system_update_cpu_freq(SYS_CPU_160MHZ);
|
||||
Serial.begin(74880);
|
||||
|
||||
Serial.println();
|
||||
Serial.println(F("ESP starting."));
|
||||
// Try pushing frequency to 160MHz.
|
||||
system_update_cpu_freq(SYS_CPU_160MHZ);
|
||||
|
||||
// System usually boots up in about 200ms.
|
||||
|
||||
Serial.print(F("system_get_time(): "));
|
||||
Serial.println(system_get_time());
|
||||
Serial.println();
|
||||
Serial.println(F("ESP starting."));
|
||||
|
||||
// set_event_handler_cb_stream(Serial);
|
||||
wifi_set_event_handler_cb(wifi_event_handler_cb);
|
||||
// System usually boots up in about 200ms.
|
||||
|
||||
print_system_info(Serial);
|
||||
Serial.print(F("system_get_time(): "));
|
||||
Serial.println(system_get_time());
|
||||
|
||||
Serial.print(F("wifi_get_opmode(): "));
|
||||
Serial.print(wifi_get_opmode());
|
||||
Serial.print(F(" - "));
|
||||
Serial.println(OP_MODE_NAMES[wifi_get_opmode()]);
|
||||
// set_event_handler_cb_stream(Serial);
|
||||
wifi_set_event_handler_cb(wifi_event_handler_cb);
|
||||
|
||||
Serial.print(F("wifi_get_opmode_default(): "));
|
||||
Serial.print(wifi_get_opmode_default());
|
||||
Serial.print(F(" - "));
|
||||
Serial.println(OP_MODE_NAMES[wifi_get_opmode_default()]);
|
||||
print_system_info(Serial);
|
||||
|
||||
Serial.print(F("wifi_get_broadcast_if(): "));
|
||||
Serial.println(wifi_get_broadcast_if());
|
||||
Serial.print(F("wifi_get_opmode(): "));
|
||||
Serial.print(wifi_get_opmode());
|
||||
Serial.print(F(" - "));
|
||||
Serial.println(OP_MODE_NAMES[wifi_get_opmode()]);
|
||||
|
||||
softap_config config;
|
||||
wifi_softap_get_config(&config);
|
||||
secure_softap_config(&config, "TestAP", "testtesttest");
|
||||
wifi_softap_set_config(&config);
|
||||
print_softap_config(Serial, config);
|
||||
Serial.print(F("wifi_get_opmode_default(): "));
|
||||
Serial.print(wifi_get_opmode_default());
|
||||
Serial.print(F(" - "));
|
||||
Serial.println(OP_MODE_NAMES[wifi_get_opmode_default()]);
|
||||
|
||||
print_wifi_general(Serial);
|
||||
Serial.print(F("wifi_get_broadcast_if(): "));
|
||||
Serial.println(wifi_get_broadcast_if());
|
||||
|
||||
// This doesn't work on an ESP-01.
|
||||
// wifi_set_sleep_type(LIGHT_SLEEP_T);
|
||||
softap_config config;
|
||||
wifi_softap_get_config(&config);
|
||||
secure_softap_config(&config, "TestAP", "testtesttest");
|
||||
wifi_softap_set_config(&config);
|
||||
print_softap_config(Serial, config);
|
||||
|
||||
// Try this dirty little thing.
|
||||
// Doesn't work because ESP-01 module doesn't link XPD_DCDC -> RST.
|
||||
// ESP.deepSleep(15000);
|
||||
print_wifi_general(Serial);
|
||||
|
||||
// This doesn't work on an ESP-01.
|
||||
// wifi_set_sleep_type(LIGHT_SLEEP_T);
|
||||
|
||||
// Try this dirty little thing.
|
||||
// Doesn't work because ESP-01 module doesn't link XPD_DCDC -> RST.
|
||||
// ESP.deepSleep(15000);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(F("system_get_time(): "));
|
||||
Serial.println(system_get_time());
|
||||
delay(1000);
|
||||
void loop() {
|
||||
Serial.print(F("system_get_time(): "));
|
||||
Serial.println(system_get_time());
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user