Yaler Library for Arduino Author: Thomas Amberg Contact: tamberg@yaler.net
Description | Download | Methods | Examples
This library enables an Arduino board connected to a local network to become accessible from the Web, via the Yaler.net relay service.
Download YalerEthernetServer.zip or browse the source code at http://www.bitbucket.org/yaler/yalercontrib/src/tip/Arduino/YalerEthernetServer.
This version works with the Ethernet shield. There is also a Yaler Arduino library for WiFi, a Yaler Arduino library for WiFi101, a Yaler Arduino library for CC3000 and a Yaler tutorial for the Arduino Yún.
Create a server that listens for incoming connections on the specified relay domain.
YalerEthernetServer(const char *host, uint16_t port, const char *id);
Gets a client that is connected to the server via the relay and has data available for reading.
server.available()
None
a Client object
A minimal Web service accessible via the Yaler relay.
// Copyright (c) 2014, Yaler GmbH, Switzerland // All rights reserved #include <SPI.h> #include <Ethernet.h> #include <YalerEthernetServer.h> // Enter a MAC address for your controller below. // Some Ethernet shields have a MAC address printed on a sticker byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Local EthernetServer at https://LOCAL_IP/ (e.g. http://192.168.0.7/) //EthernetServer server(80); // Get a relay domain at https://yaler.net/ to replace RELAY_DOMAIN below // YalerEthernetServer is accessible at https://RELAY_DOMAIN.try.yaler.io/ YalerEthernetServer server("try.yaler.io", 80, "RELAY_DOMAIN"); void setup() { Serial.begin(9600); Serial.println("Acquiring IP address..."); if (Ethernet.begin(mac) == 0) { Serial.println("DHCP failed."); } else { Serial.println(Ethernet.localIP()); server.begin(); } } void sendResponse(EthernetClient client) { client.print("HTTP/1.1 200 OK\r\n"); client.print("Connection: close\r\n"); client.print("Content-Length: 5\r\n"); client.print("\r\n"); client.print("Hello"); } void loop() { EthernetClient client = server.available(); if (client && client.connected()) { client.find("\r\n\r\n"); // Consume incoming request sendResponse(client); delay(1); // Give the Web browser time to receive the data client.stop(); } }
For more examples, see: http://www.bitbucket.org/yaler/yalercontrib/src/tip/Arduino