Bridge Arduino
Bridge Arduino
http://myArduinoYun.local/arduino/digital/13 :
calls digitalRead(13);
http://myArduinoYun.local/arduino/digital/13/1 :
calls digitalWrite(13,1);
http://myArduinoYun.local/arduino/analog/9/123 : analo
gWrite(9,123);
http://myArduinoYun.local/arduino/analog/2 : analogRead
(2);
http://myArduinoYun.local/arduino/mode/13/input : pinM
ode(13, INPUT);
http://myArduinoYun.local/arduino/mode/13/output : pi
nMode(13, OUTPUT);
You can use the CURL command from the command line
instead of a browser if you prefer.
Hardware Required
Yn board or shield
computer and Yn device on the same wireless or wired
network
Software Required
web browser
Circuit
There is no circuit for this example.
image developed using Fritzing. For more circuit examples, see the Fritzing
project page
Code
The example code shows how it is possible to make REST
requests to the Yn device to read from and write information
to the board's pins.
You need to include the Bridge, YunServer,
and YunClient libraries :
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
[Get Code]
YunServer server;
[Get Code]
[Get Code]
process(client);
client.stop();
}
delay(50);
}
[Get Code]
[Get Code]
[Get Code]
[Get Code]
Print the value to the client and update the datastore key with
the current pin value.
By wrapping the value to the client in F(), you'll be printing
form the flash memory. This helps conserve space in SRAM,
which is useful when dealing with long strings like URLs.
The key will be the pin, and type. For example D2 will be
saved for for digital pin 2. The value will be whatever value
the pin is currently set to, or was read from the pin.
client.print(F("Pin D"));
client.print(pin);
client.print(F(" set to "));
client.println(value);
String key = "D";
key += pin;
Bridge.put(key, String(value));
}
[Get Code]
[Get Code]
[Get Code]
if (client.read() != '/') {
client.println(F("error"));
return;
}
[Get Code]
[Get Code]
"/arduino/digital/13"
"/arduino/digital/13/1"
"/arduino/analog/2/123"
"/arduino/analog/2"
"/arduino/mode/13/input"
"/arduino/mode/13/output"
->
->
->
->
->
->
digitalRead(13)
digitalWrite(13, HIGH)
analogWrite(2, 123)
analogRead(2)
pinMode(13, INPUT)
pinMode(13, OUTPUT)
[Get Code]
See Also
Time check - Gets the time from Linux via Bridge then
parses out hours, minutes and seconds.