Hi Isaac,
we currently use about the following code to run a Web service on an Arduino / WIZnet Ethernet shield and make it accessible via Yaler:
#include <Ethernet.h>
#include <EthernetDHCP.h>
byte mac[] = ...
byte yalerIp[] = ...
const char yalerId[] = "my-arduino";
...
void setup() {
EthernetDHCP.begin(mac); // calls Ethernet.begin()
... sensor setup ...
}
void loop() {
Client client(yalerIp, 80);
client.connect();
if (client.connected()) {
sendYalerPostRequest(client, yalerId);
int status = receiveYalerResponse(client);
if (status == 101) {
receiveBrowserRequest(client, ...);
... read sensor ...
sendBrowserResponse(client, ...);
} else {} // 204
client.stop();
}
}
With our DHCP server / office LAN, calling EthernetDHCP.maintain(); seems not to be necessary, as long as the DHCP server keeps running.
Cheers,
tamberg
http://yaler.org/