Hardware Reference
In-Depth Information
unsigned long lastRefresh = 0;
byte stage = 0;
Finally, define an Ethernet client:
EthernetClient Client;
The rest of the sketch comes from the Teleduino example and won't be detailed here.
Note
The code for this section can be found in the GitHub repository for this chapter at ht-
tps://github.com/openhomeautomation/arduino-networking/tree/master/chapter4 .
It's now time to make a first test of this sketch. Upload the sketch to your Arduino board,
and then go to your web browser. You can now directly send commands to your board.
First, we are going to set the relay pin as an output as seen earlier. This is done using the
following command (where you have to insert your own key at the k parameter):
http://us01.proxy.teleduino.org/api/1.0/328.php?k=yourKey
&r=definePinMode&pin=7&mode=1
You will be greeted by a confirmation message inside your web browser. You can now
switch the relay pin to a HIGH state using the following command:
http://us01.proxy.teleduino.org/api/1.0/
328.php?k=yourKey&r=setDigitalOutput&pin=7&output=1
By doing so, you should hear the click of the relay, meaning the command was correctly
sent. You will also be greeted by a confirmation message inside your browser.
Now, we are going to modify the interface so you can command the relay from anywhere
using your web browser. Inside the JavaScript file, you will then need to define your Tele-
duino API key:
var key = "yourAPIkey";
Then, we have to change the command parameters to fit the Teleduino API and mention
the key as well, as shown in the following code:
Search WWH ::




Custom Search