LEDs have two legs, an anode (longer leg, positive) and a cathode (shorter leg, negative). Connect the anode to a current-limiting resistor and the other end of the resistor to the microcontroller’s output pin. Connect the cathode directly to the microcontroller’s ground (GND) pin. Interfacing an LED with an ESP8266 using the Arduino core is quite similar to the basic Arduino example. The ESP8266 Arduino core provides a convenient platform for programming ESP8266 modules with the Arduino IDE. Here’s a simple example of “interfacing an LED with an ESP8266 using an Arduino-core”ESP8266 Arduino-Core Interface – LED”:
Category Archives: ESP8266 Arduino Core
ESP8266 Arduino-core Tutorial – HTTP Post Data to Web Page
These various applications for sending data, especially in IoT projects. Below are some scenarios and use cases where sending data using an HTTP POST request can be beneficial. In this article will discuss about “ESP8266 Arduino-core Tutorial – HTTP Post Data to Web Page”.
Required
- ESP8266 Any Module (Used NodeMCU Dev Kit Version 1.0)
- Arduino IDE with ESP8266 Platform
- Web Sever (Shared, Linux, Windows or Own Server like with any hosting providers: Amazon, GoDaddy, GlobeHost, BlueHost, HostingRaja and etc)
- Cpanel Login Access and update index file contend
Cpanel index.php code for web Server
Note I tested its code is working well.
<?php $age= $name = $TimeStamp = ""; $Hum= $Temp = ""; $timezone = new DateTimeZone("Asia/Kolkata" ); $date = new DateTime(); $date->setTimezone($timezone ); echo $date->format('Ymd-H:i:s'); $TimeStamp = $date; if( $_REQUEST["Hum"] || $_REQUEST["Temp"] ) { echo " The Humidity is: ". $_REQUEST['Hum']. "%<br />"; echo " The Temperature is: ". $_REQUEST['Temp']. " Celcius<br />"; $Hum= $_REQUEST["Hum"]; $Temp = $_REQUEST["Temp"]; $myfile = fopen("arun.txt", "a") or die("Unable to open file!"); fwrite($myfile, "TimeStamp : ".$date->format('Ymd-H:i:s')."\t | Hum : ".$Hum."\t | Temp : ".$Temp. " |\n"); fclose($myfile); } if( $_GET["name"] || $_GET["age"] ) { echo "Welcome ". $_GET['name']. "<br />"; echo "You are ". $_GET['age']. " years old.". "<br />"; $age= $_GET["age"]; $name = $_GET["name"]; $myfile = fopen("arun.txt", "a") or die("Unable to open file!"); fwrite($myfile, "TimeStamp : ".$date->format('Ymd-H:i:s')."\t | Name : ".$name."\t | Age : ".$age. " |\n"); fclose($myfile); exit(); } $myfile = fopen("arun.txt", "r") or die("Unable to open file!"); echo "<table border='1' align ='center' >"; while(!feof($myfile)) { echo "<tr><td border='1' align ='center' >"; echo fgets($myfile) . "<br>"; echo "</td></tr>"; } echo "</table>"; fclose($myfile); ?>
ESP8266 Arduino-Core Code for HTTP Post Data
//www.Aruneworld.com/embedded/esp8266/esp8266-arduino-core/ const char* hostGet = "iot.aruneworld.com/ESP8266/NodeMCU/HTTP-Post/"; #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> const char* ssid="ArunEworld"; const char*password="8300026060INDIA"; WiFiClient client; void postData() { WiFiClient clientGet; const int httpGetPort = 80; //the path and file to send the data to: String urlGet = "/index.php"; // We now create and add parameters: String src = "12345"; String typ = "6789"; String nam = "temp"; String vint = "92"; urlGet += "?Hum=" + src + "&Temp=" + typ ; Serial.print(">>> Connecting to host: "); Serial.println(hostGet); if (!clientGet.connect(hostGet, httpGetPort)) { Serial.print("Connection failed: "); Serial.print(hostGet); } else { clientGet.println("GET " + urlGet + " HTTP/1.1"); clientGet.print("Host: "); clientGet.println(hostGet); clientGet.println("User-Agent: ESP8266/1.0"); clientGet.println("Connection: close\r\n\r\n"); unsigned long timeoutP = millis(); while (clientGet.available() == 0) { if (millis() - timeoutP > 10000) { Serial.print(">>> Client Timeout: "); Serial.println(hostGet); clientGet.stop(); return; } } //just checks the 1st line of the server response. Could be expanded if needed. while(clientGet.available()){ String retLine = clientGet.readStringUntil('\r'); Serial.println(retLine); break; } } //end client connection if else Serial.print(">>> Closing host: "); Serial.println(hostGet); clientGet.stop(); } void setup() { Serial.begin(115200); // Starts the serial communication WiFi.begin(ssid, password); //begin WiFi connection Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println("ArunEworld"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); } void loop() { postData(); delay(30000); }
Make sure to replace the placeholders:
your-ssid
andyour-password
with your WiFi credentials.your-server-address
with the address of your server./your-api-endpoint
with the specific endpoint on your server that handles the incoming POST requests.
Applications and Uses
Purpose | Example and use Case |
---|---|
Data Logging | Use Case: Collecting sensor data from IoT devices and sending it to a web server for logging. |
Example: Temperature and humidity readings from a sensor sent periodically to a server for historical tracking. | |
Remote Control | Use Case: Controlling devices remotely through a web interface. |
Example: Sending commands to turn on/off lights, appliances, or actuators. | |
Sensor Data Transmission | Use Case: Transmitting real-time sensor data to a central server. |
Example: Accelerometer data from a wearable device sent to a cloud server for analysis. | |
Form Submissions | Use Case: Submitting form data from a device to a web server. |
Example: User input from a device form (e.g., a weather station) sent to a server for processing. | |
User Authentication | Use Case: Authenticating users and transmitting login credentials securely. |
Example: Transmitting username and password securely to a server for authentication. | |
Integration with APIs | Use Case: Interacting with third-party APIs or services. |
Example: Sending data to a cloud service API for weather information or other integrations. | |
Alerts and Notifications | Use Case: Sending alerts or notifications from a device to a central server. |
Example: Sending an alert when a predefined threshold is exceeded (e.g., temperature too high). | |
Configuration Updates | Use Case: Updating device configurations remotely. |
Example: Sending configuration parameters to a device, allowing dynamic adjustments. | |
Data Synchronization | Use Case: Synchronizing data between devices and servers. |
Example: Uploading data collected offline on a device to a central server when connectivity is restored. | |
Command and Control Systems | Use Case: Building command and control systems for industrial or automation applications. |
Example: Controlling and monitoring devices in a manufacturing plant through a central server. |
Security aspects & Encryption
When implementing HTTP POST requests in your application, consider security aspects such as using HTTPS for encrypted communication and implementing proper authentication mechanisms to protect sensitive data. Always follow best practices for secure communication, especially when transmitting data over the internet.
FAQ
if you have the following Questions and most of the repeated and same-meaning questions, then the Above article should help you
- How send data to web page using ESP8266?
- How to HTTP Post Data to Web Page using ESP8266 via Arduino-core Tutorial –
- ESP8266 send data to website?
- Send ESP8266 Data to Your Webpage – no AT Commands
- Arduino-Esp8266-Post-Data-to-Website
- ESP8266: HTTP POST Requests
- Posting and getting data from ESP on Apache WebServer
- How to Send Data from Arduino to Webpage using WiFi?
- How to send data to a server using ESP8266 with Arduino?
NEXT
Arduino-Core IDE Setup |
|
ESP8266 Interface LED |
ESP8266 Interface Button |
ESP8266 Interface ADC |
|
ESP8266 Project WebServer |
HTTP Post Data to Web Page |
Cayenne MyDevice Get Start |
ESP8266 Arduino-Core Sitemap |
ESP8266 Arduino-Core All Post |
ESP8266 Arduino-Core Tutorial – Web Server
TCP Server Listener
The below Arduino code will also create a server and Access Point in ESP8266 which will continuously listen for a connection.
Code
//www.ArunEworld.com #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> const char *ssid = "ArunEworld"; const char *password = "Arun"; ESP8266WebServer server(80); void handleRoot() { server.send(200, "text/html", "<t1>ArunEworld</t1>"); server.send(200, "text/html", "<h1>ArunEworld : TCP WebServer Listener</h1>"); server.send(200, "text/html", "<h2>You are connected</h2>"); } void setup() { delay(1000); Serial.begin(115200); Serial.println(); Serial.print("Configuring access point..."); WiFi.softAP(ssid, password); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); server.on("/", handleRoot); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); }
After uploading this sketch, you can find a new Access Point named “test” from your Laptop or PC.
Result
ESP8266 Arduino-Core – Basics
The ESP8266 Arduino Core is a software framework that enables developers to program ESP8266 microcontrollers using the Arduino programming language and environment. This core provides a set of libraries and tools that simplify the development process for projects involving the ESP8266 chip. Here will discuss ESP8266 Arduino-Core Basics.
ESP8266 Arduino Core serves as a powerful tool for developing IoT (Internet of Things) applications, home automation systems, sensor networks, and more, using the ESP8266 microcontroller platform with the simplicity and flexibility of the Arduino ecosystem.
Read more: ESP8266 Arduino-Core – BasicsCall SDK Functions
- Required Hardware ESP8266 with Programmer (or) NodeMCU Dev Kit
- Required Software Tools Arduino IDE with ESP8266 Core
Code
/* https://www.aruneworld.com/embedded/espressif/esp8266/esp8266_arduino-core/ Tested By : Arun(20170219) Example Name : AEW_CallSDKFunctions.ino */ /** * 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" { #include "user_interface.h" } #endif // Set up output serial port (could be a SoftwareSerial // if really wanted). 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. // // 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 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 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 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_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; } ehConsolePort.println(")"); } 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("password: ")); consolePort.println((char *) config.password); consolePort.print(F("ssid_len: ")); consolePort.println(config.ssid_len); consolePort.print(F("channel: ")); consolePort.println(config.channel); consolePort.print(F("authmode: ")); consolePort.println(AUTH_MODE_NAMES[config.authmode]); consolePort.print(F("ssid_hidden: ")); consolePort.println(config.ssid_hidden); consolePort.print(F("max_connection: ")); consolePort.println(config.max_connection); consolePort.print(F("beacon_interval: ")); consolePort.print(config.beacon_interval); consolePort.println("ms"); 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]); 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()); system_print_meminfo(); 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_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_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_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 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->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; } void setup() { // Reuse default Serial port rate, so the bootloader // messages are also readable. Serial.begin(74880); // Try pushing frequency to 160MHz. system_update_cpu_freq(SYS_CPU_160MHZ); Serial.println(); Serial.println(F("ESP starting.")); // System usually boots up in about 200ms. Serial.print(F("system_get_time(): ")); Serial.println(system_get_time()); // set_event_handler_cb_stream(Serial); wifi_set_event_handler_cb(wifi_event_handler_cb); print_system_info(Serial); Serial.print(F("wifi_get_opmode(): ")); Serial.print(wifi_get_opmode()); Serial.print(F(" - ")); Serial.println(OP_MODE_NAMES[wifi_get_opmode()]); 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()]); Serial.print(F("wifi_get_broadcast_if(): ")); Serial.println(wifi_get_broadcast_if()); softap_config config; wifi_softap_get_config(&config); secure_softap_config(&config, "TestAP", "testtesttest"); wifi_softap_set_config(&config); print_softap_config(Serial, config); 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); }
Result
wifi_station_get_hostname: wifi_station_get_hostname: wifi_station_get_hostname: wifi_station_get_hostname: wifi_station_get_hostname: wifi_station_get_hostname: wifi_station_get_hostname: wifi_station_get_hostname: wifi_station_get_hostname: wifi_station_get_hostname:
Test ESP8266 API
ESP8266 Arduino-Core Basics
Code
/* https://www.aruneworld.com/embedded/espressif/esp8266/esp8266_arduino-core/esp8266_arduino-core-basics/ Tested By : Arun(20170219) Example Name : AEW_TestEspAPI.ino */ /** * 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" { #include "user_interface.h" } #endif // Set up output serial port (could be a SoftwareSerial // if really wanted). 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. // // 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 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 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 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_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; } ehConsolePort.println(")"); } 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("password: ")); consolePort.println((char *) config.password); consolePort.print(F("ssid_len: ")); consolePort.println(config.ssid_len); consolePort.print(F("channel: ")); consolePort.println(config.channel); consolePort.print(F("authmode: ")); consolePort.println(AUTH_MODE_NAMES[config.authmode]); consolePort.print(F("ssid_hidden: ")); consolePort.println(config.ssid_hidden); consolePort.print(F("max_connection: ")); consolePort.println(config.max_connection); consolePort.print(F("beacon_interval: ")); consolePort.print(config.beacon_interval); consolePort.println("ms"); 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]); 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()); system_print_meminfo(); 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_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_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_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 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->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; } void setup() { // Reuse default Serial port rate, so the bootloader // messages are also readable. Serial.begin(74880); // Try pushing frequency to 160MHz. system_update_cpu_freq(SYS_CPU_160MHZ); Serial.println(); Serial.println(F("ESP starting.")); // System usually boots up in about 200ms. Serial.print(F("system_get_time(): ")); Serial.println(system_get_time()); // set_event_handler_cb_stream(Serial); wifi_set_event_handler_cb(wifi_event_handler_cb); print_system_info(Serial); Serial.print(F("wifi_get_opmode(): ")); Serial.print(wifi_get_opmode()); Serial.print(F(" - ")); Serial.println(OP_MODE_NAMES[wifi_get_opmode()]); 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()]); Serial.print(F("wifi_get_broadcast_if(): ")); Serial.println(wifi_get_broadcast_if()); softap_config config; wifi_softap_get_config(&config); secure_softap_config(&config, "TestAP", "testtesttest"); wifi_softap_set_config(&config); print_softap_config(Serial, config); 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);
Result
ets Jan 8 2013,rst cause:2, boot mode:(3,6) load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v09f0c112 ~ld ¡H¨MA�starting. system_get_time(): 282250 system_get_rst_info() reset reason: REASON_EXT_SYS_RST system_get_free_heap_size(): 49016 system_get_os_print(): 0 system_get_os_print(): 1 system_get_chip_id(): 0xD98DD7 system_get_sdk_version(): 1.5.3(aec24ac9) system_get_boot_version(): 5 system_get_userbin_addr(): 0x1000 system_get_boot_mode(): SYS_BOOT_NORMAL_MODE system_get_cpu_freq(): 160 system_get_flash_size_map(): FLASH_SIZE_4M_MAP_256_256 wifi_get_opmode(): 2 - SOFTAP_MODE wifi_get_opmode_default(): 2 - SOFTAP_MODE wifi_get_broadcast_if(): 2 SoftAP Configuration -------------------- ssid: TestAP password: testtesttest ssid_len: 6 channel: 1 authmode: AUTH_WPA2_PSK ssid_hidden: 0 max_connection: 4 beacon_interval: 11298ms -------------------- wifi_get_channel(): 1 wifi_get_phy_mode(): PHY_MODE_11N system_get_time(): 386190 system_get_time(): 1387316 system_get_time(): 2387360 system_get_time(): 3387405 system_get_time(): 4387450 system_get_time(): 5387495 system_get_time(): 6387539
RTC User Memory
Code
/* https://www.aruneworld.com/embedded/espressif/esp8266/esp8266_arduino-core/esp8266_arduino-core-basics/ Tested By : Arun(20170219) Example Name : AEW_RTCUserMemory.ino */ // Example: Storing struct data in RTC user rtcDataory // // Struct data with the maximum size of 512 bytes can be stored // in the RTC user rtcDataory using the ESP-specifc APIs. // The stored data can be retained between deep sleep cycles. // However, the data might be lost after power cycling the ESP8266. // // This example uses deep sleep mode, so connect GPIO16 and RST // pins before running it. // // Created Mar 30, 2016 by Macro Yau. // // This example code is in the public domain. // CRC function used to ensure data validity uint32_t calculateCRC32(const uint8_t *data, size_t length); // helper function to dump memory contents as hex void printMemory(); // Structure which will be stored in RTC memory. // First field is CRC32, which is calculated based on the // rest of structure contents. // Any fields can go after CRC32. // We use byte array as an example. struct { uint32_t crc32; byte data[508]; } rtcData; void setup() { Serial.begin(115200); Serial.println(); delay(1000); // Read struct from RTC memory if (ESP.rtcUserMemoryRead(0, (uint32_t*) &rtcData, sizeof(rtcData))) { Serial.println("Read: "); printMemory(); Serial.println(); uint32_t crcOfData = calculateCRC32(((uint8_t*) &rtcData) + 4, sizeof(rtcData) - 4); 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 { Serial.println("CRC32 check ok, data is probably valid."); } } // Generate new data set for the struct for (int i = 0; i < sizeof(rtcData); i++) { rtcData.data[i] = random(0, 128); } // Update CRC32 of data rtcData.crc32 = calculateCRC32(((uint8_t*) &rtcData) + 4, sizeof(rtcData) - 4); // Write struct to RTC memory if (ESP.rtcUserMemoryWrite(0, (uint32_t*) &rtcData, sizeof(rtcData))) { Serial.println("Write: "); printMemory(); Serial.println(); } Serial.println("Going into deep sleep for 5 seconds"); ESP.deepSleep(5e6); } void loop() { } uint32_t calculateCRC32(const uint8_t *data, size_t length) { uint32_t crc = 0xffffffff; while (length--) { uint8_t c = *data++; for (uint32_t i = 0x80; i > 0; i >>= 1) { bool bit = crc & 0x80000000; if (c & i) { bit = !bit; } crc <<= 1; if (bit) { crc ^= 0x04c11db7; } } } return crc; } void printMemory() { char buf[3]; for (int i = 0; i < sizeof(rtcData); i++) { sprintf(buf, "%02X", rtcData.data[i]); Serial.print(buf); if ((i + 1) % 32 == 0) { Serial.println(); } else { Serial.print(" "); } } Serial.println(); }
Result
3F 34 14 6D 36 50 4F 51 7B 57 20 64 6A 4E 20 12 3C 2E 37 1E 23 1E 4F 28 23 16 1D 3F 4E 6F 36 3D 7E 5E 60 05 7D 37 3E 4B 53 40 74 64 09 0A 40 13 3E 05 09 5D 49 63 1C 15 37 50 76 02 5D 75 10 07 4C 2A 73 65 49 78 6E 3C 02 50 1D 6D 0D 16 77 15 10 48 31 02 57 1A 60 3B 41 16 6A 78 3F 0B 1D 2D 39 58 3D 58 5E 72 06 7A 79 52 24 6A 77 68 38 4D 5A 02 43 09 4A 75 4B 04 78 3B 52 7C 20 34 60 1F 51 5F 44 08 26 04 3B 1E 77 73 13 49 4B 11 3A 06 42 1E 59 6D 63 4D 1F 2D 2E 3D 51 00 77 50 28 46 44 78 7A 07 42 21 73 75 44 60 7C 68 23 5B 44 31 47 5E 73 67 69 47 2A 0A 34 05 14 62 61 13 07 02 77 3B 3F 1F 3B 75 77 23 64 34 7D 38 41 00 4E 73 07 5E 7B 02 69 37 65 52 3D 3B 09 10 3B 21 44 36 55 4E 45 20 19 25 0D 38 37 37 66 4A 7B 48 64 45 04 4E 3E 28 55 6F 6E 3F 6F 62 0D 58 71 04 49 53 3F 60 37 22 06 52 4B 5A 56 20 07 22 21 0C 17 32 33 5B 5F 37 06 26 2C 19 6C 25 4E 24 0F 45 0B 3E 5A 4A 03 36 2A 3F 34 78 44 12 42 07 3D 3F 7D 42 1C 73 1F 3D 76 1B 5B 0C 3A 07 1E 64 36 73 6E 77 1A 21 40 76 03 01 16 1F 3E 31 0D 6C 2B 72 7A 24 49 15 50 7C 6A 08 16 72 3F 36 5C 7D 29 15 1B 31 06 31 7A 07 1E 46 28 51 68 4F 5C 1F 1C 33 55 2E 54 0D 24 3F 01 47 32 2B 6B 22 1D 44 2E 2C 65 10 44 37 4A 52 3F 11 7B 3D 68 7B 23 17 42 1B 43 23 57 31 7F 31 7D 21 15 0A 2C 2D 16 21 5C 14 17 16 6E 5E 7D 70 2E 67 79 75 30 34 40 2A 61 3A 74 43 0A 7A 12 7F 7D 48 51 52 22 43 4D 6F 08 4C 65 46 7E 07 76 29 29 59 64 3D 6E 64 5B 61 61 34 7B 0B 02 0D 1B 05 66 49 1D 4A 26 29 1B 4D 7C 03 64 34 0F 2F 73 0D 18 20 74 30 02 00 30 4C 34 62 36 25 42 25 65 52 3E 73 0B 3B 15 31 33 29 00 00 00 00 CRC32 of data: 7927D498 CRC32 read from RTC: 7927D498 CRC32 check ok, data is probably valid. Write: 4A 64 61 6D 6E 6C 29 0D 59 02 2A 59 0F 3F 76 5E 0F 3E 21 6C 0B 3F 6A 2E 67 4E 6D 05 3F 51 18 50 61 4C 4C 18 0D 0C 0A 07 2D 7E 6D 7F 4E 15 0A 61 15 6D 4F 0E 2B 35 70 45 61 2D 32 48 58 56 60 64 01 7B 3B 45 32 5F 64 7F 71 4C 61 43 00 48 0C 1E 42 76 51 5B 2C 3B 0C 39 68 5F 75 21 25 6C 76 5D 6E 4C 45 3A 12 44 23 25 4E 32 37 4C 44 01 51 62 71 34 53 5F 0C 39 49 67 03 57 13 0F 42 23 45 5C 7B 7F 47 76 73 26 45 65 3E 0C 02 10 20 28 53 68 1B 02 63 3F 26 3D 39 6E 70 09 1C 48 2F 0E 4F 49 1A 04 6F 15 3B 34 5C 76 20 54 02 20 5E 1A 47 38 14 31 69 07 02 60 7E 2F 79 34 43 4B 75 3D 55 3C 41 76 7C 69 3A 74 48 69 75 7B 04 29 71 27 08 04 6D 13 08 70 34 4E 26 43 10 02 1C 0B 57 22 2F 74 0F 0B 59 46 47 35 1B 45 0B 14 32 24 11 29 2E 29 6F 50 4D 75 31 68 4E 3B 00 1D 10 41 0C 2C 55 23 5C 7C 59 25 09 1F 37 56 21 1A 0D 12 56 6B 63 28 2B 75 06 5B 72 56 61 04 68 64 5F 2E 12 13 78 04 3C 43 10 18 63 37 63 74 37 6D 44 22 3D 67 75 68 53 24 03 7F 20 08 7A 59 5B 04 5F 35 4F 42 1E 64 6F 3F 70 54 06 3B 17 4B 1A 70 36 38 38 5D 01 7A 3B 60 02 7D 14 3C 4D 16 3F 30 3A 73 28 1F 3C 0A 0F 00 56 27 73 55 2C 77 21 59 68 0A 68 72 75 76 32 01 2E 0D 04 3E 37 67 75 04 5E 33 13 17 1A 24 1B 59 18 0E 50 41 79 4D 06 7E 4C 70 48 46 37 3D 45 01 6B 0D 3E 64 2E 40 3C 26 7F 04 15 7F 0D 26 66 27 66 53 15 0D 16 6B 02 3E 67 17 60 42 6A 20 78 16 21 75 61 60 50 05 02 6D 4D 1B 1E 50 7B 33 7F 0E 30 0A 6F 16 6E 49 28 53 19 14 11 11 30 56 44 21 3A 55 74 21 47 17 63 1B 28 44 0A 60 53 57 3B 4E 5F 5E 3B 50 04 42 24 4F 31 72 71 35 24 15 2A 4B 18 16 0F 5D 43 5B 60 4F 57 6D 02 69 5D 6C Going into deep sleep for 5 seconds
Result
Flash real id: 001640E0 Flash real size: 4194304 Flash ide size: 524288 Flash ide speed: 40000000 Flash ide mode: DIO Flash Chip configuration wrong!
Check Flash Configuration
This Arduino sketch tests whether the ESP8266 microcontroller’s hardware configuration matches the EEPROM settings of the Integrated Development Environment (IDE).
Here’s a breakdown of what the code does:
- Setup Function: The
setup
function is executed once when the microcontroller starts up. In this sketch, it initializes serial communication with a baud rate of 115200. - Loop Function: The
loop
function is executed repeatedly as long as the microcontroller is powered on. Inside the loop, it performs the following actions:ESP.getFlashChipRealSize()
: Retrieves the actual size of the flash memory chip.ESP.getFlashChipSize()
: Retrieves the size of the flash memory chip as defined in the IDE settings.ESP.getFlashChipMode()
: Retrieves the flash mode of the chip as defined in the IDE settings.
- If the actual size of the flash memory chip (
realSize
) differs from the size defined in the IDE settings (ideSize
), it indicates a configuration mismatch, and a corresponding error message is printed. - If the sizes match, the sketch prints a message indicating that the flash chip configuration is correct.
- Delay: After printing the flash chip configuration, the loop waits for 5 seconds before repeating the process.
This sketch is useful for verifying that the EEPROM settings in the IDE match the actual hardware configuration of the ESP8266 chip. It can help troubleshoot issues related to flash memory configuration mismatches.
Code
/* https://www.aruneworld.com/embedded/espressif/esp8266/esp8266_arduino-core/esp8266_arduino-core-basics/ Tested By : Arun(20170219) Example Name : AEW_CheckFlashConfiguration.ino 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 Arduino-Core Interface – ADC
ADC
Required
- Required Hardware – ESP8266 with Programmer (or) NodeMCU Dev Kit
- Required Software Tools – Arduino IDE with ESP8266 Core
Circuit
Code
/* http://www.ArunEworld.com/Embedded/ESPressif/ESP8266/ESP8266_Arduino-Core/ Tested By : Arun(20170219) Example Name : AEW_ADC-Interface.ino */ /* AnalogReadSerial Reads an analog input on pin 0, prints the result to the serial monitor. Graphical representation is available using serial plotter (Tools > Serial Plotter menu) Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); delay(1); // delay in between reads for stability }
Result
3 2 3 4 3 3 4 3 2 3 4 2 2
Next :
Previous :
ESP8266 Arduino-Core Interface – Button
Button – Digital Read Serial
-
Required Hardware ESP8266 with Programmer (or) NodeMCU Dev Kit
-
Required Software Tools Arduino IDE with ESP8266 Core
Code
/* http://www.ArunEworld.com/Embedded/ESPressif/ESP8266/ESP8266_Arduino-core/ESP8266-Arduino-Core-Interface-Button Tested By : Arun(20170219) Example Name : AEW_ADC-Interface.ino */ /* AnalogReadSerial Reads an analog input on pin 0, prints the result to the serial monitor. Graphical representation is available using serial plotter (Tools > Serial Plotter menu) Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); delay(1); // delay in between reads for stability }
Output
0 1 1 1 0 0
Next :
Previous :
ESP8266 Arduino-Core Cayenne – Get Start with Cayenne MyDevice
What is Cayenne MyDevice?
myDevices Cayenne allows you to quickly design, prototype, and visualize IoT solutions. You can use Cayenne as a tool to visualize real-time and historical data, sent over to The Things Network. Let’s discuss “ESP8266 Arduino-Core Cayenne – Get Start with Cayenne MyDevice“
Cayenne is a platform for building IoT (Internet of Things) projects that provides tools for creating dashboards, monitoring devices, and controlling connected devices remotely. The Cayenne platform supports various microcontrollers and single-board computers, including the ESP8266, through the use of Cayenne MQTT or Cayenne MQTT API.
You must be logged in to post a comment.