Eric Eric -4 years ago 215
reST (reStructuredText) Question

Arduino Yún Bridge: simple command failing

I created the following sketch, based almost entirely on the Bridge tutorial provided on

I can't figure out why the example Bridge script has worked for me (toggling the LED on pin 13 by curling URIs like

), but this much simpler sketch responds with my failure string, "Unrecognized command: hello" when I curl

What am I missing?

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

YunServer server;

void setup() {

// Bridge startup
digitalWrite(13, HIGH);
digitalWrite(13, LOW);

void loop() {
// Get clients coming from server
YunClient client = server.accept();

// There is a new client?
if (client) {
// Process request

// Close connection and free resources.

delay(50); // Poll every 50ms

void process(YunClient client) {
// read the command
String command = client.readStringUntil('/');

if (command == "hello") {
client.println(F("I will do your bidding"));

client.print(F("Unrecognized command: "));

Ultimately, I'd like to use a longer, random string as a key--in place of "hello"--allowing me to activate a connected component from a device that has stored the secret (e.g. an smart phone with the URI stored as a button on the home screen).

Answer Source

What I missed in the example was the exact behavior of these Stream functions:

String command = client.readStringUntil('/');
if (command == "hello") { ... }

That condition will only be true if "hello" is not the final segment of the URI. What tipped me off was the mode command in the Bridge example code. It parsed the final segment (expecting "input" or "output") like this:

String mode = client.readStringUntil('\r');

This was perplexing because I hadn't assumed the Yun server would strip the final '/' when I curled:

$ curl "arduino.local/arduino/digital/hello/" -v


Use readStringUntil('\r') for parsing the final segment of a URI.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download