Hardware Reference
In-Depth Information
Listing 10-1 continued
161 client.write("DATA\r\n");
162
163 // change to recipient address
164 client.write("To: You <you@yourdomain.com>\r\n");
165
166 // change to your address
167 client.write("From: Plant <plant@yourdomain.com>\r\n");
168
169 client.write("Subject: I need water!\r\n");
170
171 if (firstEmail == true) // First email
172 {
173 client.write("I'm thirsty!\r\n");
174 }
175 else
176 {
177 int i = random(4);
178 if (i == 0)
179 client.write("You don't love me any more, do you?\r\n");
180 if (i == 1)
181 client.write("All I know is pain...\r\n");
182 if (i == 2)
183 client.write("I would have watered you by now...\r\n");
184 if (i == 3)
185 client.write("My suffering will soon be over...\r\n");
186 }
187
188 client.write(".\r\n");
189
190 client.write("QUIT\r\n");
191 client.stop();
192
193 return true;
194 }
This sketch has four functions: the setup() and loop() that are present in
every sketch and two others, getDht11Humidity() and sendEmail() .
At the start, the sketch includes two libraries: WiFi.h and WiFiClient.h . On
lines 4 and 5, two pins are dei ned: the pin connected to the DHT11 data pin and
the pin connected to an LED. On line 7, another pin is dei ned: MINHUMIDITY . This
is the value that will be used as a warning level for the sensor; if the humidity
falls below this level (expressed as relative humidity), the user will be warned.
On lines 9, 10, and 11, three variables are dei ned as char arrays . These need
to be changed depending on your network setup; they are the SSID the Arduino
will connect to, the password to use, and the SMTP server that will be used to
send e-mails.
On line 13 is a variable: thirsty . This is a boolean: true if the plant needs
water, and false if the dirt has enough humidity. Finally, you have an int named
Search WWH ::




Custom Search