Editing
esp
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==ESP.reset== esp8266 arduino core has soft reset: ESP.reset(). Calling this function you get a valid reset. Note to software reset. esp8266 has a bug. If software reset (or exception) is executed in program started right after the flashing, the board goes back to flashing mode because the flashing flag is still active. {{template:toponly}} ===ESP.wdtDisable();=== Disable the software watchdog<br> Although this disables the software watchdog, the hardware watchdog will still remain active, causing a reset after some time. As indicated in the comments of the wdtDisable method, if we stop the software watchdog by more than 6 seconds, the hardware watchdog will trigger.<br> ===ESP.wdtEnable(1000);=== Re-enable the software watchdog<br> It’s important to note that an integer value needs to be passed as input argument of this method, which would correspond to the number of milliseconds for the watchdog to trigger. Nevertheless, this value makes no effect and it is not used in the internal call of the SDK ESP8266 functions<br> Additionally, in the header file, it’s clearly stated that, at the time, setting the timeout is not implemented. Unfortunately, it’s not clear what is the default value of the watchdog timer when we call this function, and neither it is documented in the SDK of the ESP8266.<br> ===ESP.wdtFeed();=== In order to explicitly restart the watchdog, we can call the wdtFeed method. Fortunately, the ESP libraries implicitly reset the watchdog in many of the functions, so most of the time we don’t need to worry about feeding the watchdog. Nevertheless, it’s important to know that it exists, in order to troubleshoot spontaneous reboots of our programs.<br> {{template:top}} ===ESP.WiFi=== [https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html#table-of-contents ESP8266WiFi Documentation]<br> ESP8266 WiFi stack will save WiFi configuration to flash memory, and automatically reconnect to the same network on restart. This happens even if you aren't using WiFi functions. You can disable persistence by adding '''WiFi.persistent(false);''' in the beginning of your WiFi initialization code. To disable WiFi in a sketch where you don't need it you can use '''WiFi.mode(WIFI_OFF);'''.<br> ====Functions==== =====hostname===== ;Get the DHCP hostname assigned to ESP station. WiFi.hostname() Function returns String type. Default hostname is in format ESP_24xMAC where 24xMAC are the last 24 bits of module’s MAC address. The hostname may be changed using the following function: WiFi.hostname(aHostname) Input parameter aHostname may be a type of char*, const char* or String. Maximum length of assigned hostname is 32 characters. Function returns either true or false depending on result. For instance, if the limit of 32 characters is exceeded, function will return false without assigning the new hostname. Example code: <nowiki>Serial.printf("Default hostname: %s\n", WiFi.hostname().c_str()); WiFi.hostname("Station_Tester_02"); Serial.printf("New hostname: %s\n", WiFi.hostname().c_str());</nowiki> ====WiFi.scanNetworks(true)==== The optional parameter, true, is an instruction to scan in asynchronous mode, i.e. trigger scanning process, do not wait for result (processing will be done in background) and move to the next line of code.<br> [https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-examples.html Example Code]<br> ====WiFi.disconnect()==== WiFi.disconnect() shuts down a connection to an access point that module may have automatically made using previously saved credentials.<br> ===mDNS=== DNS works great for normal sites on the Internet, but most local networks don't have their own DNS server. This means that you can't reach local devices using a domain name, and you're stuck using IP addresses.<br> <br> Fortunately, there's another way: multicast DNS, or mDNS.<br> '''mDNS''' uses domain names with the .local suffix, for example ''http://esp8266.local''. If your computer needs to send a request to a domain name that ends in .local, it will send a multicast query to all other devices on the LAN that support mDNS, asking the device with that specific domain name to identify itself. The device with the right name will then respond with another multicast and send its IP address. Now that your computer knows the IP address of the device, it can send normal requests.<br> <br> Luckily for us, the ESP8266 Arduino Core supports mDNS:<br> <nowiki>#include <ESP8266WiFi.h> // Include the Wi-Fi library #include <ESP8266WiFiMulti.h> // Include the Wi-Fi-Multi library #include <ESP8266mDNS.h> // Include the mDNS library ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti' void setup() { Serial.begin(115200); // Start the Serial communication to send messages to the computer delay(10); Serial.println('\n'); wifiMulti.addAP("ssid_from_AP_1", "your_password_for_AP_1"); // add Wi-Fi networks you want to connect to wifiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2"); wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3"); Serial.println("Connecting ..."); int i = 0; while (wifiMulti.run() != WL_CONNECTED) { // Wait for the Wi-Fi to connect: scan for Wi-Fi networks, and connect to the strongest of the networks above delay(1000); Serial.print(++i); Serial.print(' '); } Serial.println('\n'); Serial.print("Connected to "); Serial.println(WiFi.SSID()); // Tell us what network we're connected to Serial.print("IP address:\t"); Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer if (!MDNS.begin("esp8266")) { // Start the mDNS responder for esp8266.local Serial.println("Error setting up MDNS responder!"); } Serial.println("mDNS responder started"); } void loop() { }</nowiki> <br> Upload it and ping to esp8266.local<br> {{template:top}} ===ping.h=== '''''Needs more info here'''''<br> After Ping.ping() has been called, the average response time (in milliseconds) can be retrieved with<br> int avg_time_ms = Ping.averageTime(); {{template:top}} ===WDT- Watchdog Timer=== [https://arduino-esp8266.readthedocs.io/en/latest/boards.html#boot-messages-and-modes Boot messages and Modes]<br> Here is a very [https://www.sigmdel.ca/michel/program/esp8266/arduino/watchdogs_en.html detailed explanation] of the Watchdog timers in the ESP8266.<br> The ESP8266 is a little different than the standard Arduino boards in that it has the watchdog(WDT) turned on by default. If the watchdog timer isn't periodically reset then it will automatically reset your ESP8266. The watchdog is reset every time '''loop()''' runs or you call '''delay()''' or '''yield()''' but if you have blocking code like a while or for loop, then the watchdog may time out, resulting in your reset.<br> The '''delay()''' function is blocking so this prevents other code from running while it's sitting there waiting out the delay. '''delay()''' doesn't cause WDT reset though because it automatically calls '''yield()''' to prevent that.<br> When the ESP reboots, you get the reboot cause: ets Jan 8 2013,rst cause:2, boot mode:(3,7) *Soft WDT: Cause 2 *Hardware WDT: Cause 4 ;Cause for reset: {| class="wikitable" |- ! Number ! Description |- | 0 | unknown |- | 1 | normal boot |- | 2 | reset pin |- | 3 | software reset |- | 4 | watchdog reset |} <br> ;Boot Mode {| class="wikitable" |- ! Number ! GPIO15 ! GPIO0 ! GPIO2 ! Mode |- | 0 | 0V | 0V | 0V | Not valid |- | 1 | 0V | 0V | 3.3V | Uart |- | 2 | 0V | 3.3V | 0V | Not valid |- | 3 | 0V | 3.3V | 3.3V | Flash |- | 4 | 3.3V | 0V | 0V | SDIO |- | 5 | 3.3V | 0V | 3.3V | SDIO |- | 6 | 3.3V | 3.3V | 0V | SDIO |- | 7 | 3.3V | 3.3V | 3.3V | SDIO |} <br> The timeout for the hardware watchdog is 8.2 seconds, and 3.2 seconds for the software watchdog timeout<br> Don't block software watchdog too long with blocking code, otherwise it will trigger hardware watchdog reset.<br> You can reset the WDT inside your blocking code with: ESP.wdt_reset() or yield(); {{template:top}}
Summary:
Please note that all contributions to Notebook may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Notebook:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Home Page
C++ Reference
ESP Hardware
ESPHome
Home Assistant
Network Stuff
Tools
What links here
Related changes
Special pages
Page information