Yaler Library for Arduino WiFi 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 YalerWiFiServer.zip or browse the source code at http://www.bitbucket.org/yaler/yalercontrib/src/tip/Arduino/YalerWiFiServer.
This version works with the WiFi shield. There is also a Yaler Arduino library for WiFi101, a Yaler Arduino library for Ethernet, 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.
YalerWiFiServer(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 <WiFi.h> #include <YalerWiFiServer.h> char ssid[] = "LOCAL_NETWORK_SSID"; char pass[] = "LOCAL_NETWORK_PASSWORD"; int status = WL_IDLE_STATUS; // Local WiFiServer at https://LOCAL_IP/ (e.g. http://192.168.0.7/) //WiFiServer server(80); // Get a relay domain at https://yaler.net/ to replace RELAY_DOMAIN below // The YalerWiFiServer is accessible at https://RELAY_DOMAIN.try.yaler.io/ YalerWiFiServer server("try.yaler.io", 80, "RELAY_DOMAIN"); void setup() { Serial.begin(9600); Serial.println("Aquiring IP address..."); if (WiFi.begin(ssid, pass) != WL_CONNECTED) { Serial.println("Connecting to WiFi failed."); } else { Serial.println(WiFi.localIP()); server.begin(); } } void sendResponse(WiFiClient 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() { WiFiClient client = server.available(); if (client && client.connected()) { client.find("\r\n\r\n"); // Consume incoming request sendResponse(client); delay(3000); // Give the Web browser time to receive the data client.stop(); } }
For more examples, see: http://www.bitbucket.org/yaler/yalercontrib/src/tip/Arduino