This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:espressif_arduino [2023/11/14 16:46] – pczekalski | en:iot-open:espressif_arduino [2023/11/21 21:57] (current) – ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | === === | + | ====== Programming ESP8266 for the Network |
| - | <box # | + | |
| - | <box # | + | |
| - | === Programming ESP8266 for the Network === | + | |
| - | <box # | + | |
| - | <box # | + | |
| Programming networking services with Espressif SoCs requires the connection established on the networking layer between parties, mainly with TCP protocol.\\ | Programming networking services with Espressif SoCs requires the connection established on the networking layer between parties, mainly with TCP protocol.\\ | ||
| Below are two code examples for ESP8266 of how to implement access point and network station modes using libraries that came during installation of the development environment for Arduino framework.\\ | Below are two code examples for ESP8266 of how to implement access point and network station modes using libraries that came during installation of the development environment for Arduino framework.\\ | ||
| Line 32: | Line 28: | ||
| void setup() { | void setup() { | ||
| delay(1500); | delay(1500); | ||
| - | /* You can remove the password parameter if you want the AP to be open. */ | + | /* You can remove the password parameter |
| + | if you want the AP to be open. */ | ||
| WiFi.softAP(ssid, | WiFi.softAP(ssid, | ||
| Line 87: | Line 84: | ||
| // This will send the request to the server | // This will send the request to the server | ||
| - | // You can try send the GET request to possibly get the response (with error) | ||
| client.println(" | client.println(" | ||
| + | // Trying to send the GET request possibly responses (with error) | ||
| // client.println(" | // client.println(" | ||
| Line 114: | Line 111: | ||
| char pass[] = " | char pass[] = " | ||
| - | unsigned int localPort = 2390; // local port to listen for UDP packets | + | unsigned int localPort = 2390; |
| // NTP servers | // NTP servers | ||
| Line 133: | Line 130: | ||
| WiFiUDP udp; | WiFiUDP udp; | ||
| - | // Prototype of the function defined at the end of this file (required in Visual Studio Code) | + | // Prototype of the function defined at the end of this file |
| + | // (required in Visual Studio Code) | ||
| void sendNTPpacket(IPAddress& | void sendNTPpacket(IPAddress& | ||
| Line 182: | Line 180: | ||
| Serial.println(ntpServerIP); | Serial.println(ntpServerIP); | ||
| - | | + | // send an NTP packet to a time server |
| + | sendNTPpacket(ntpServerIP); | ||
| + | | ||
| // wait to see if a reply is available | // wait to see if a reply is available | ||
| delay(1000); | delay(1000); | ||
| Line 200: | Line 200: | ||
| Serial.println(cb); | Serial.println(cb); | ||
| // We've received a packet, read the data from it | // We've received a packet, read the data from it | ||
| - | udp.read(packetBuffer, | + | |
| + | | ||
| - | //the timestamp starts at byte 40 of the received packet and is four bytes, | + | // the timestamp starts at byte 40 |
| + | // of the received packet and is four bytes, | ||
| // or two words, long. First, extract the two words: | // or two words, long. First, extract the two words: | ||
| Line 215: | Line 217: | ||
| // now convert NTP time into everyday time: | // now convert NTP time into everyday time: | ||
| Serial.print(" | Serial.print(" | ||
| - | // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: | + | // Unix time starts on Jan 1 1970. |
| + | // In seconds, that's 2208988800: | ||
| const unsigned long seventyYears = 2208988800UL; | const unsigned long seventyYears = 2208988800UL; | ||
| // subtract seventy years: | // subtract seventy years: | ||