Hardware Reference
In-Depth Information
// Initialize the client library
WiFiClient client;
This library is almost identical to the Ethernet library, though certain techni-
cal aspects are different to handle wireless connectivity. To create a socket to a
server, you must use connect() , just like with the Ethernet library:
result = client.connect(server, port);
The function takes two parameters: port is an int and indicates the port to
which you want to connect. The server parameter is either an IPAddress (or
an array of 4 bytes), or a String containing the server name. It returns a bool-
ean : true if the connection was accepted, and false if the connection failed.
Wireless Server
Wireless devices can also be servers, waiting for clients to connect before answer-
ing to requests. Again, the WiFi library has its own specialized object: WiFiServer :
WiFiServer server(port);
The port parameter is the port that you want to open, expressed as an int .
When the port is opened, the server waits for incoming connections with begin() :
server.begin(); // Wait for clients to connect
Example Application
I'm terrible with plants. Taking care of most kinds isn't that complicated; I just
need to keep the dirt moist, keep them out of direct sunlight (but still enough
sunlight) and change the dirt from time to time. Just keeping the dirt moist
seems to be too much for me, and this is where technology can help.
The DHT11 is a popular temperature and humidity sensor; it is inexpensive,
reliable, and fairly easy to use. It comes with a plastic cover offering protection
from most environments, and as long as you don't put water directly onto it, it
can live happily with your houseplants. It is illustrated in Figure 10-1.
The DHT11 does have something unique. Previous chapters talked about serial
communications, some of them requiring more wires than others, but some (I 2 C
especially) requiring only two wires to function. This component is different; it
requires only one. There is one wire used to send and to receive data, in addition
to a power and ground. Although it might sound complicated to use a single
wire for both data reception and emission, it is actually fairly straightforward.
The downside to this component is that you can make only one reading every
2 seconds, but that is more than enough for a houseplant, even mine.
 
Search WWH ::




Custom Search