Arduinio Yun troubles with Bridge

Hi,

I have some troubles with Arduino Yun.

  1. Bridge
    When I test the sketch “Exemples → Bridge → Bridge”,
    I type on internet explorer “http://yun.local/arduino/digital/13/0”, the led switches off but, I haven’t the Yun response but Message “HTTP 500 Internal server error”.
    I haven’t the message like “Pin D 13 set to 0”

  2. HTTP Client
    When I test the sketch "Exemples → Bridge →
    In console I read :

301 Moved Permanently

301 Moved Permanently


nginx/1.4.2 and not the Arduinio text.

Could you help me please ?

Hi,

does this occure with 1.6.3 or 1.6.2? Have you tried 1.6.1?

See: http://forum.arduino.cc/index.php?topic=317016.0

Good luck, Christof

That occurs with Arduino version 1.6.3

OpenWRT version is 1.5.3

Bonjour service is installed

flidilic:
::::SNIP::::
2) HTTP Client
When I test the sketch "Exemples → Bridge →
In console I read :

301 Moved Permanently

301 Moved Permanently


nginx/1.4.2 and not the Arduinio text.

Could you help me please ?

@flidilic,
your are NOT connected to the YUN, You are connected to the Internet and some other server.

In the output you posted it says:

nginx/1.4.2

nginx is an Internet server. It is not on the YUN. It appears the problem is with your Internet router.

Can you give us some more details on #1 (“Exemples → Bridge → Bridge”)
Can you tell us the IP of the YUN?
Have you upgradeded?
Have you set the Server name?
Can you get to webpages on the Yun?

TIA
Jesse

jessemonroy650:
@flidilic,
your are NOT connected to the YUN, You are connected to the Internet and some other server.

In the output you posted it says:

nginx/1.4.2

nginx is an Internet server. It is not on the YUN.

Correct, he is not trying to talk to the Yun. The HttpClient Example has the sketch go out to a remote server and retrieve a web page (similar idea to curl.) In this case, the sketch is trying to fetch http://arduino.cc/asciilogo.txt.

I'm not at my computer or Yun at the moment, and can't currently test it with my tablet. I can load that URL and see the text file, but it can't tell whether the request was redirected as indicated in the OP's listed response.

flidilic:
2) HTTP Client
When I test the sketch "Exemples → Bridge →
In console I read :

301 Moved Permanently

301 Moved Permanently


nginx/1.4.2 and not the Arduinio text.

This appears to be working correctly, as this is what I am seeing as well.

If I try the http://arduino.cc/asciilogo.txt URL in a browser, and look at the network diagnostics, it shows that the redirection is to http://www.arduino.cc/asciilogo.txt (note the “www.” added to the front of the URL.

This is easily fixed by changing line 40 of the sketch to:

 client.get("http://www.arduino.cc/asciilogo.txt");

It would appear that there has been some arduino.cc server configuration changes since the sketch was published.

Hi,
ShapeShifter thank you for your message, your solution is OK :smiley: :

In the sketch "Exemples -> Bridge -> HttpClient"

I change

p.addParameter("http://arduino.cc/asciilogo.txt"); // Add the URL parameter to "curl"

into

p.addParameter("http://www.arduino.cc/asciilogo.txt"); // Add the URL parameter to "curl"

The result is :

           `:;;;,`                      .:;;:.           
        .;;;;;;;;;;;`                :;;;;;;;;;;:     TM 
      `;;;;;;;;;;;;;;;`            :;;;;;;;;;;;;;;;      
     :;;;;;;;;;;;;;;;;;;         `;;;;;;;;;;;;;;;;;;     
    ;;;;;;;;;;;;;;;;;;;;;       .;;;;;;;;;;;;;;;;;;;;    
   ;;;;;;;;:`   `;;;;;;;;;     ,;;;;;;;;.`   .;;;;;;;;   
  .;;;;;;,         :;;;;;;;   .;;;;;;;          ;;;;;;;  
  ;;;;;;             ;;;;;;;  ;;;;;;,            ;;;;;;. 
 ,;;;;;               ;;;;;;.;;;;;;`              ;;;;;; 
 ;;;;;.                ;;;;;;;;;;;`      ```       ;;;;;`
 ;;;;;                  ;;;;;;;;;,       ;;;       .;;;;;
`;;;;:                  `;;;;;;;;        ;;;        ;;;;;
,;;;;`    `,,,,,,,,      ;;;;;;;      .,,;;;,,,     ;;;;;
:;;;;`    .;;;;;;;;       ;;;;;,      :;;;;;;;;     ;;;;;
:;;;;`    .;;;;;;;;      `;;;;;;      :;;;;;;;;     ;;;;;
.;;;;.                   ;;;;;;;.        ;;;        ;;;;;
 ;;;;;                  ;;;;;;;;;        ;;;        ;;;;;
 ;;;;;                 .;;;;;;;;;;       ;;;       ;;;;;,
 ;;;;;;               `;;;;;;;;;;;;                ;;;;; 
 `;;;;;,             .;;;;;; ;;;;;;;              ;;;;;; 
  ;;;;;;:           :;;;;;;.  ;;;;;;;            ;;;;;;  
   ;;;;;;;`       .;;;;;;;,    ;;;;;;;;        ;;;;;;;:  
    ;;;;;;;;;:,:;;;;;;;;;:      ;;;;;;;;;;:,;;;;;;;;;;   
    `;;;;;;;;;;;;;;;;;;;.        ;;;;;;;;;;;;;;;;;;;;    
      ;;;;;;;;;;;;;;;;;           :;;;;;;;;;;;;;;;;:     
       ,;;;;;;;;;;;;;,              ;;;;;;;;;;;;;;       
         .;;;;;;;;;`                  ,;;;;;;;;:         
                                                         
                                                         
                                                         
                                                         
    ;;;   ;;;;;`  ;;;;:  .;;  ;; ,;;;;;, ;;. `;,  ;;;;   
    ;;;   ;;:;;;  ;;;;;; .;;  ;; ,;;;;;: ;;; `;, ;;;:;;  
   ,;:;   ;;  ;;  ;;  ;; .;;  ;;   ,;,   ;;;,`;, ;;  ;;  
   ;; ;:  ;;  ;;  ;;  ;; .;;  ;;   ,;,   ;;;;`;, ;;  ;;. 
   ;: ;;  ;;;;;:  ;;  ;; .;;  ;;   ,;,   ;;`;;;, ;;  ;;` 
  ,;;;;;  ;;`;;   ;;  ;; .;;  ;;   ,;,   ;; ;;;, ;;  ;;  
  ;;  ,;, ;; .;;  ;;;;;:  ;;;;;: ,;;;;;: ;;  ;;, ;;;;;;  
  ;;   ;; ;;  ;;` ;;;;.   `;;;:  ,;;;;;, ;;  ;;,  ;;;;

@flidilic,

Could you answer these questions? If you don't know how, we can help with question #1.

Can you give us some more details on #1 ("Exemples -> Bridge -> Bridge")
Can you tell us the IP of the YUN?
Have you upgradeded?
Have you set the Server name?
Can you get to webpages on the Yun?

Jesse

  1. Code of “Exemples → Bridge → Bridge” :
/*
  Arduino Yún Bridge example

 This example for the Arduino Yún shows how to use the
 Bridge library to access the digital and analog pins
 on the board through REST calls. It demonstrates how
 you can create your own API when using REST style
 calls through the browser.

 Possible commands created in this shetch:

 * "/arduino/digital/13"     -> digitalRead(13)
 * "/arduino/digital/13/1"   -> digitalWrite(13, HIGH)
 * "/arduino/analog/2/123"   -> analogWrite(2, 123)
 * "/arduino/analog/2"       -> analogRead(2)
 * "/arduino/mode/13/input"  -> pinMode(13, INPUT)
 * "/arduino/mode/13/output" -> pinMode(13, OUTPUT)

 This example code is part of the public domain

 http://arduino.cc/en/Tutorial/Bridge

 */

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

// Listen to the default port 5555, the Yún webserver
// will forward there all the HTTP requests you send
YunServer server;

void setup() {
  // Bridge startup
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);

  // Listen for incoming connection only from localhost
  // (no one from the external network could connect)
  server.listenOnLocalhost();
  server.begin();
}

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

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

    // Close connection and free resources.
    client.stop();
  }

  delay(50); // Poll every 50ms
}

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

  // is "digital" command?
  if (command == "digital") {
    digitalCommand(client);
  }

  // is "analog" command?
  if (command == "analog") {
    analogCommand(client);
  }

  // is "mode" command?
  if (command == "mode") {
    modeCommand(client);
  }
}

void digitalCommand(YunClient client) {
  int pin, value;

  // Read pin number
  pin = client.parseInt();

  // If the next character is a '/' it means we have an URL
  // with a value like: "/digital/13/1"
  if (client.read() == '/') {
    value = client.parseInt();
    digitalWrite(pin, value);
  }
  else {
    value = digitalRead(pin);
  }

  // Send feedback to client
  client.print(F("Pin D"));
  client.print(pin);
  client.print(F(" set to "));
  client.println(value);

  // Update datastore key with the current pin value
  String key = "D";
  key += pin;
  Bridge.put(key, String(value));
}

void analogCommand(YunClient client) {
  int pin, value;

  // Read pin number
  pin = client.parseInt();

  // If the next character is a '/' it means we have an URL
  // with a value like: "/analog/5/120"
  if (client.read() == '/') {
    // Read value and execute command
    value = client.parseInt();
    analogWrite(pin, value);

    // Send feedback to client
    client.print(F("Pin D"));
    client.print(pin);
    client.print(F(" set to analog "));
    client.println(value);

    // Update datastore key with the current pin value
    String key = "D";
    key += pin;
    Bridge.put(key, String(value));
  }
  else {
    // Read analog pin
    value = analogRead(pin);

    // Send feedback to client
    client.print(F("Pin A"));
    client.print(pin);
    client.print(F(" reads analog "));
    client.println(value);

    // Update datastore key with the current pin value
    String key = "A";
    key += pin;
    Bridge.put(key, String(value));
  }
}

void modeCommand(YunClient client) {
  int pin;

  // Read pin number
  pin = client.parseInt();

  // If the next character is not a '/' we have a malformed URL
  if (client.read() != '/') {
    client.println(F("error"));
    return;
  }

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

  if (mode == "input") {
    pinMode(pin, INPUT);
    // Send feedback to client
    client.print(F("Pin D"));
    client.print(pin);
    client.print(F(" configured as INPUT!"));
    return;
  }

  if (mode == "output") {
    pinMode(pin, OUTPUT);
    // Send feedback to client
    client.print(F("Pin D"));
    client.print(pin);
    client.print(F(" configured as OUTPUT!"));
    return;
  }

  client.print(F("error: invalid mode "));
  client.print(mode);
}
  1. IP of Yun is 192.168.0.39

  2. That occurs with Arduino version 1.6.3

  3. Yun has been upgradeded
    Last YunImage_v1.5.3.zip (http://www.arduino.cc/en/Main/Donate) contents :

  • openwrt-ar71xx-generic-yun-16M-kernel.bin
  • openwrt-ar71xx-generic-yun-16M-rootfs-squashfs.bin
  • openwrt-ar71xx-generic-linino-u-boot.bin

Arduino version 1.6.3
OpenWRT version is 1.5.3

  1. Have you set the Server name? No : how to check ? to do ?

  2. Can you get to webpages on the Yun? Yes

About the problem #1:

The Bridge library of the IDE 1.6.3 needs to be updated. There is a missing patch in the library shipped with the IDE.

Open the IDE and click on Sketch->Include library->Manage Libraries
Search for the Bridge library and click on Update.

Thank you Angelo9999

After updating Bridge library (Open the IDE and click on Sketch->Include library->Manage Libraries
Search for the Bridge library and click on Update)

The problem is resolved :wink:

I have Arduino IDE 1.6.6, Yun, and my Bridge library version 1.1.0 installed.

When I run the Bridge > Process example, it still shows:

301 Moved Permanently

301 Moved Permanently


nginx/1.4.2

I read the post above, and I changed the following line from:

p.addParameter(“http://www.arduino.cc/asciilogo.txt”); // Add the URL parameter to “curl”

changed to (remove the www.):

p.addParameter(“http://arduino.cc/asciilogo.txt”); // Add the URL parameter to “curl”

Then the logo appears on serial monitor.

Notice:

http://arduino.cc/asciilogo.txt displays the ascii logo
http://www.arduino.cc/asciilogo.txt auto transfers to secure https, ie.
https://www.arduino.cc/asciilogo.txt

It sounds like the powers that be may have realized that they broke the example code, so the fixed the server configuration so the example works. However, in doing so, it looks like they may have broken the “fixed” example code that has www. added to it?