Hardware Reference
In-Depth Information
// Give name and ID to device
rest.set_id(xbee_id);
Note that if you are configuring more than one sensor, you need to change the ID of each
sensor you are configuring. Now, thanks to the aREST library, the loop() part of the
sketch is pretty simple. We simply have to handle the incoming requests from the com-
puter that will come via the XBee serial interface:
void loop() {
// Handle REST calls
rest.handle(Serial);
}
Now, the sketch is ready to be used.
Note
All the code is available on the GitHub repository of the project:
https://github.com/openhomeautomation/arduino-home-automation/tree/master/chapter1
You can upload the sketch to your Arduino board by making sure that the switch is still
set on DLINE. Once this is done, you can test the code locally via the serial monitor of the
Arduino IDE. Open the serial monitor, make sure that the serial speed is set to 9600, and
type the following:
/digital/8/r
This is the REST command to read a digital value from pin number 8 and return the value,
which is exactly what we want to achieve. You should see the following data being re-
turned, depending on the current state of the sensor:
{"return_value": 0, "id": "2", "name": "", "connected":
true}
What we are interested in is the return_value field, which contains the result of the
digitalRead() function. Try to wave your hand in front of the sensor to see if the re-
Search WWH ::




Custom Search