1
votes

I am trying to connect two Arduino Yun boards to each other via WIFI (make one board control a pin on the other board an vice versa) and I am having trouble making it work the way I want to.

This is where I've gotten so far: I have two Arduino Yun boards with a simple sketch installed on each, which works fine as long as I keep the "connecting-each-other"-part out of it. It uses a potentiometer on the analog port, reads its value, maps it to the range of 0-255 an fades a LED up or down on one of the digital pins (brighter / darker) depending on the given value. Now I want to use the potentionmeter of one board to control the LED on the OTHER board.

To do that, I tried to use the REST API. I combined my sketch with the code from the "Bridge" Example Sketch, which sets up a http-client/server on the Arduino Yun (on the Linux part) allowing it to receive requests to control and read patricular pins via http.

When using the specific URL for the REST API in a browser, it works fine. For example: when I type "http://myarduino.local/arduino/digital/3/1" it sets the value of digital pin 3 to 1 (i.e. LED is switched on) --> so that's all fine

I am not sure how to continue at this point, since I dont want to control the board from a browser or app but make one Arduino Yun control another Arduino Yun directly. If I put a http request in my sketch like mentioned above via client.get and client.read (as in the example sketch) it does not work. See example code below. It doesnt have any effect nor does anything appear in the serial monitor (with the original URL "http://arduino.cc/asciilogo.txt" like in the example, the ascii code appears in the serial monitor)

 HttpClient webclient;
  webclient.get("http://ardu1.local/digital/3/1");

  while (webclient.available()) {
    char c = webclient.read();
    Serial.print(c);
  }
  Serial.flush();

I am a beginner with Arduino Yun boards and maybe I am missing something?

Thanks for any help or pointing me in the right direction. Or if you need more information to help me with this problem, please let me know.

2

2 Answers

2
votes

I found another way to connect two Arduino Yun boards directly, or as close to "directly" as it probably gets. The REST API was not the right way to go. So this is for anyone who might encounter the same "problem":

After some research I came across "Spacebrew". It's based on "websockets" and requires a server to connect the boards to each other, but it is very flexible. It's also fairly easy to setup a spacebrew server locally. It allows every client (like a Arduino Yun board) connected to the server to publish different types of data (boolean, range, value) and/or to subscribe to the published data from other devices using a simple webinterface. The good thing is, that the connection is fast and there's no waiting for the connection to be reestablished when there is data to be sent.

I used the Arduino Example Sketch "spacebrewRange" and it worked fine for me. It also requires a few other things before it can work, but its explained on the website and in a tutorial:

http://docs.spacebrew.cc/gettingstarted/

http://de.slideshare.net/julioterra/spacebrew-server-workshop-itp

0
votes

Trying to do the same, it seems, and for me it works (this bit at least :-|

I let one arduino request the URL "http://router.domain:port/arduino/key/value", using a Process which runs cURL. The receiving arduino interprets this request to set the key to the value, using a YunClient.

From the URLs in your question, it seems that you are missing the mandatory "/arduino/" component in the path name. As far as I know, this is needed to direct any requests directed at the OpenWRT stack to the arduino/Leonardo part.