From b7045ba734ec8dbd699420beb4736ed6a097174b Mon Sep 17 00:00:00 2001 From: bay007 Date: Tue, 13 Dec 2016 00:35:30 -0600 Subject: [PATCH] Documentacion added, useful for beginners --- examples/esp8266/esp8266/esp8266.ino | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/esp8266/esp8266/esp8266.ino b/examples/esp8266/esp8266/esp8266.ino index b3e9ecd8..efbeecf4 100644 --- a/examples/esp8266/esp8266/esp8266.ino +++ b/examples/esp8266/esp8266/esp8266.ino @@ -1,21 +1,21 @@ -#include +#include //A simple ESP8266 Arduino library with built in re-connect functionality. (https://github.com/ekstrand/ESP8266wifi) const char* ssid = "your_wifi_network_name"; const char* password = "your_wifi_network_password"; const int ledPin = 2; -WiFiServer server(1337); +WiFiServer server(1337); //Creates a server that listens for incoming connections on the specified port. (https://www.arduino.cc/en/Reference/WiFiServer) -void printWiFiStatus(); +// the declaration is not useful. void setup(void) { - Serial.begin(115200); - WiFi.begin(ssid, password); + Serial.begin(115200); // opens serial port, sets data rate to 115200 bps (https://www.arduino.cc/en/Serial/Begin), (https://www.arduino.cc/en/Reference/Serial) + WiFi.begin(ssid, password); //Initializes the WiFi library's network settings and provides the current status. (https://www.arduino.cc/en/Reference/WiFiBegin) // Configure GPIO2 as OUTPUT. pinMode(ledPin, OUTPUT); // Start TCP server. - server.begin(); + server.begin(); //Tells the server to begin listening for incoming connections. //http://www.arduino.org/learning/reference/wifiserver-begin } void loop(void) { @@ -28,32 +28,32 @@ void loop(void) { printWiFiStatus(); } - WiFiClient client = server.available(); + WiFiClient client = server.available(); //Gets a client that is connected to the server and has data available for reading. (https://www.arduino.cc/en/Reference/WiFiServerAvailable) - if (client) { - Serial.println("Client connected."); + if (client) { //a Client object; if no Client has data available for reading, this object will evaluate to false in an if-statement + Serial.println("Client connected."); //Prints data to the serial port as human-readable ASCII text followed by a carriage return character.(https://www.arduino.cc/en/Serial/Println) while (client.connected()) { - if (client.available()) { - char command = client.read(); + if (client.available()) { //Returns the number of bytes available for reading (that is, the amount of data that has been written to the client by the server it is connected to). (https://www.arduino.cc/en/Reference/WiFiClientAvailable) + char command = client.read(); //This function reads the next byte received from the server the client is connected to (after the last call to read()). (http://www.arduino.org/learning/reference/wificlient-read) if (command == 'H') { - digitalWrite(ledPin, HIGH); - Serial.println("LED is now on."); + digitalWrite(ledPin, HIGH); //Write a HIGH or a LOW value to a digital pin. (https://www.arduino.cc/en/Reference/DigitalWrite) + Serial.println("LED is now off."); //the HIGH and LOW state is negative logical. } else if (command == 'L') { digitalWrite(ledPin, LOW); - Serial.println("LED is now off."); + Serial.println("LED is now on."); //the HIGH and LOW state is negative logical. } } } Serial.println("Client disconnected."); - client.stop(); + client.stop(); //This function disconnects from the server. (http://www.arduino.org/learning/reference/wificlient-stop) } } void printWiFiStatus() { Serial.println(""); - Serial.print("Connected to "); + Serial.print("Connected to "); //Prints data to the serial port as human-readable ASCII text. (https://www.arduino.cc/en/Serial/Print) Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP());