How do I Interconnect TWO Dragino Yun's??

Hi Everyone!

I am in the process of creating a wireless sensor network to help illustrate the concepts of networking among/between wired and wireless nodes.

To keep things simple for now, I have TWO Arduino Uno's, and TWO Dragino Yun's.

One "sensor" unit has an RFID reader attached to it, as well as the Yun (though conceptually this would also need to work with temperature sensors, gas sensors, motion sensors, etc.).

The "base" unit simply has an Uno and Yun. This unit would ideally communicate to the "sensor" unit via WiFi, as well as to a DHCP wired network.

What I would LOVE to see happen is for the "sensor" node to transmit its data over Yun WiFi to the "base" node, and then the "base" node upload the data to a web service through a Yun wired DHCP connection.

I have found bits and pieces of information on how to work with a single Yun, but what I have NOT found is how to interconnect two Yun's so that they can talk together via WiFi.

Can someone help me out with this? Clearly it would have to be a peer-to-peer setup, or Ad-Hoc in 802 lingo. Though I was also looking around at mesh networks to allow for expandability in the future (to add more "sensor" nodes). HOWEVER, at this point I would love for just these two Uno's to be able to talk to one another using their respective Yun's.

As a secondary question, also which I have not been able to definitively find an answer to, Can someone verify that the Yun can indeed communicate through both the WiFi as well as the Wired connection in the same sketch? I don't mean SIMULTANEOUS communication (i.e. - the "base" node receives some wireless data from the "sensor" node, process it and then transmit it to a web service via the wired connection). I just need to make sure that a single Yun doesn't have to be configured exclusively for WiFi or exclusively for wired in any given sketch.

And just to preemptively answer the question, I DO need to have both wired and wireless operating in the same project to achieve the goals of this project. I know it would be far easier to simply go wireless directly from the "sensor" node to a web service through the Internet, but to facilitate the key points of this project I would like the "sensor" node to make a wireless hop to the "base" node, and then from the "base" node through a wired connection to the Internet.

Thank you all in advance for your expertise and assistance!! Any sample code, redirection to sketches, etc. is MUCH appreciated.

-Dave

Hi Dave:

I think you need a M2M (machine to machine) communication that can connect all your Arduino boards together no mater it’s connected through DHCP or wireless network. So I recommend MQTT as your first priority choose.

MQTT topology has three important parts: Broker, Publish, Subscribe.

Broker is the server that implements the MQTT protocol and provides a lightweight method of carrying out messaging using a publish/subscribe model.

After you connect to a broker, you can either publish your sensor data to a specific address you created or subscribe the data form the address.

For YUN beginners, I recommend shiftr.io created by Joël Gähwiler. It has a visualized MQTT network graph that is easy to understand and design.

The MQTT library for Arduino yun is also ready for you. It’s worthy of giving it a try.

https://shiftr.io/
https://github.com/256dpi/arduino-mqtt

Also, it’s possible to build a website to receive and send response to Arduino boards.
https://docs.shiftr.io/

The Code below is a simple example that send “world” to /hello and receive “world” from /hello and print.

// This example uses an Arduino Yun and the
// YunMQTTClient to connect to shiftr.io.
//
// The YunMQTTClient uses a Linux side python
// script to manage the connection which results
// in less program space and memory used on the Arduino.
//
// You can check on your device after a successful
// connection here: https://shiftr.io/try.
//
// by Joël Gähwiler
// https://github.com/256dpi/arduino-mqtt

#include <Bridge.h>
#include <YunMQTTClient.h>

YunMQTTClient client;

unsigned long lastMillis = 0;

void setup() {
  Bridge.begin();
  Serial.begin(9600);
  client.begin("broker.shiftr.io");

  connect();
}

void connect() {
  Serial.print("connecting...");
  while (!client.connect("arduino", "try", "try")) {
    Serial.print(".");
    delay(1000);
  }

  Serial.println("\nconnected!");

  client.subscribe("/hello");
  // client.unsubscribe("/example");
}

void loop() {
  client.loop();

  if(!client.connected()) {
    connect();
  }

  // publish a message roughly every second.
  if(millis() - lastMillis > 1000) {
    lastMillis = millis();
    client.publish("/hello", "world");
  }
}

void messageReceived(String topic, String payload, char * bytes, unsigned int length) {
  Serial.print("incoming: ");
  Serial.print(topic);
  Serial.print(" - ");
  Serial.print(payload);
  Serial.println();
}

I am a newbie, too. There are still many interesting things for us to discover. It’s really exciting, isn’t it.

prosper50:
Clearly it would have to be a peer-to-peer setup, or Ad-Hoc in 802 lingo.

Not true. You can go that route, but the easiest solution is to set one up as a plain old access point, and the other as a regular client. Out-of-the-box, the Yun acts as an access point. This is perfect for your “base” Yun, the one that will have your wired connection. The default setup will do what you want, but you may want to change the network name (SSID) and add some security. Then, for your sensor nodes, just connect to the base node like you would to any WiFi network.

Though I was also looking around at mesh networks to allow for expandability in the future (to add more “sensor” nodes).

Setting up a mesh network is a great science project and learning explerience, but is not necessary if your only goal is to be able to connect more than one sensor. Where the benefit of mesh comes in is if they nodes are spread out where some are out of range of the base, but still within range of other sensor nodes. In such a case, sensor data can hop from one sensor to another, until it gets to the base. The trade off for the extra routing power is extra configuration work.

As a secondary question, also which I have not been able to definitively find an answer to, Can someone verify that the Yun can indeed communicate through both the WiFi as well as the Wired connection in the same sketch?

Absolutely! OpenWRT, the operating system running on the Linux side, is designed as a router. This is what makes the networking of the Yun so powerful. The out-of-the-box default setup s that the wired Ethernet port is considered the WAN port, with a connection to the main network and the Internet, while the WiFi is the LAN. Very much the same idea as any wireless router, except that it doesn’t have any wired Ethernet LAN ports.

know it would be far easier to simply go wireless directly from the “sensor” node to a web service through the Internet, but to facilitate the key points of this project I would like the “sensor” node to make a wireless hop to the “base” node, and then from the “base” node through a wired connection to the Internet.

There are many ways to do it, Tim gives one suggestion using MQTT. How I would do it depends on the data rates. For a low data rate, my first thought is to go with a simple REST API where the base unit is a server, and the sensor node(s) periopcally make a web request to send data. If higher data rates, the base unit listens for TCP connections, and the sensor unit(s) open a TCP a key and stream the data. Both schemes could be implemented in a sketch (simpler to do) or on the Linux side (more powerful and efficient.)

There are many other ways to do it. The easy part is to get them networked together. The fun part is to be the data moving between them. Good luck, it should be an interesting project.

Hi Tim and ShapeShifter!

I would like to take this opportunity to THANK YOU both for your informative replies, and for answering the few questions I had. I have experience with Arduino but have never before had a need to explore Yun, and from what both have mentioned, this is a very powerful tool in the Arduino toolbox!! I am eager to move forward with this using your recommendations.

THANK YOU AGAIN!

-Dave

prosper50:
I have experience with Arduino but have never before had a need to explore Yun, and from what both have mentioned, this is a very powerful tool in the Arduino toolbox!!

Yes, the addition of the Linux processor (and all of the possibilities that come with it) make it orders of magnitude more powerful than an Uno with a WiFi shield. It does so much more, but it does require a different way of thinking.