Go Down

Topic: Control Yun by browser (Read 1 time) previous topic - next topic

999danny

Hi,
I'm learning to use Arduino Mega + Yun shield .
I modified this example by adding the " prova " command, but it does not work.
Would someone know how to help me ?

ShapeShifter

Thank you for including a link to the original sketch, and for including your full source code. That's very helpful, and something that is often not done.

However, you don't really describe your problem, other than "it does not work." What doesn't work? What are you expecting to happen, and what actually happens? What is the exact URL you are using to test it?

999danny

Right, sorry!!!! :smiley-confuse:

If i use this string in a browser all work good:

http://myArduinoYun.local/arduino/digital/13 : calls digitalRead(13);
http://myArduinoYun.local/arduino/digital/13/1 : calls digitalWrite(13,1);
http://myArduinoYun.local/arduino/analog/9/123 : analogWrite(9,123);
http://myArduinoYun.local/arduino/analog/2 : analogRead(2);
http://myArduinoYun.local/arduino/mode/13/input : pinMode(13, INPUT);
http://myArduinoYun.local/arduino/mode/13/output : pinMode(13, OUTPUT);

if i use my string don't work (no error message) :

http://myArduinoYun.local/arduino/prova : call a response message "prova" in browser.

Thanks to all.

ShapeShifter

Try this command: http://myArduinoYun.local/arduino/prova/

Note the "/" slash on the end.

Here's what I suspect what's happening: the process() function starts by calling readStringUntil('/') to read in the token of the URL that appears after /arduino/ (for example "digital" or "mode"). That function will read in a string from the URL, until it reads the character in the argument (a slash character) or it gets a timeout. In all of the working examples, there is a slash after that token, so all you get from readStringUntil() is that token. However, in your "prova" example you have no slash character after the token, so it gets a timeout when it reaches the end of the URL. You will get the "prova" token, but you will also get the newline terminator that ended the URL. So, in reality, you don't get "prova" in the command string, you get "prova\n" instead. So, your test for the string "prova" fails because it does not match "prova\n".

Adding the slash to the end of the URL as shown above is one way to make this work, because readStringUntil() will find the slash and stop copying characters, so you won't get the trailing newline terminator character.

Another way to make it work is to just look for "prova\n" instead of "prova" but there is a better way. In process(), after the readStringUntil(), call but before any of the IF statements, add the line:
Code: [Select]
command.trim();
This removes any whitespace from the beginning and end of the command string. (Whitespace is non-printing characters like space, tab, newline, carriage return, etc.) With that, it should work whether or not there is a trailing slash.

999danny

Works, thanks.

With string :

http://myArduinoYun.local/arduino/prova/n -----> Work good !!!!

Now i try with a trim command.

Thaks to all.



Daniele

Go Up