The concept is that the web service is a database of devices and their states. The main URL is a "human interface" that displays the entire database and lets you enter a device name and it's current state.
The "computer interface" is at http://phy-to-phy.appspot.com/update. You perform an HTTP GET, with a URL of the form:
http://phy-to-phy.appspot.com/update?q=[device to query]&d=[device to set state]&s=[state]
So for example, if I want to set the state of device "PIR" to "1" and at the same time query the state of "SolarCell", I'd send:
http://phy-to-phy.appspot.com/update?d=PIR&s=1&q=SolarCell
And the response would be something like:
SolarCell:1.8
Indicating that the device "SolarCell" has a state "1.8". When calling the service, you can leave out the "q=" query if you just want to set a device to a state, or leave out the "d=" and "s=" if you just want to query for a device state.
So for example, on an Arduino you would attach an Xport set to connect using TCP to IP address 74.125.91.141 (phy-to-phy.appspot.com), port 80, and using the NewSoftSerial library, your code snippet to set "PIR" to "1" would look like:
NewSoftSerial xport(3,2);
...
xport.print("GET /update?d=PIR&s=1 HTTP/1.1\r\nHost: phy-to-phy.appspot.com\r\n\r\n");
On a Make Controller, you would send the same string using SocketWrite.
In a few weeks, I will put up some code that also reads queries back from the phy2phy intermediation web service as well.
No comments:
Post a Comment