User manual

how the commands can be automatically operated via the controller. You will also
learn another command that you can use to test if a computer in the network or a
server online can be reached. In this example, the Google server will be pinged.
The example program P02_GooglePing mostly automates the processes that you
entered manually in the first example. The controller sends commands to the ESP
module in sequence, thus connecting to the WLAN, among others. The differently
long time-out times give the module enough time to answer.
Before the program can work properly, you need to enter your WLAN data after #de-
fine SSID and #define PASSWORD right at the beginning of the program source code.
The module needs access to the Internet to execute its last command. The command
AT+PING
pings other devices in the network. Pinging means a query whether a computer
can generally be reached. Here, the Google server is pinged with
AT+PING="www.google.de". When a response returns, a success message ap-
pears on the serial monitor and the LED labelled D3 that is connected to pin D13
at the board is activated. The first communication with the Internet is successful.
The program
We will analyse the program functions step by step below. First, we will cover com-
munication with the module.
1
Serial communication
This works via the serial software interface that is provided with the Software-
Serial-Library. When initialising, you also need to indicate the pins used: in this
case these are pins 11 and 12.
#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 12);
Just as for the normal serial interface, you can then transfer bytes or entire lines
with the commands esp8266.print or esp8266.println. The commands
esp8266.find and esp8266.findUntil, with which an incoming stream can be
checked for specific character strings, are particularly useful as well. This makes it
rather simple to catch the matching response from the module. However, if an
expected character string does not appear, it may take a while until the program
continues. The waiting time (time-out) is defined byesp8266.setTimeout. findUntil()
can also be used to define a second character spring in which the search function
stops and returns false as the return value. We will use this in the function send-
Com():