I have two Yuns that need to communicate via wifi, but they won't always have the same IP-address.
What is the easiest way to accomplish this? I am thinking about having them write to a database and periodically check if the other one has written anything. They just need to send a single integer to the other when a sensor is activated.
Only change ethernet dhcp client get ip from router ip pool to static ip.
uci set network.wan.proto=static
uci set network.wan.ipaddr=192.168.241.1
uci set network.wan.netmask=255.255.255.0
uci commit network
/etc/init.d/network restart
Thanks! But I think I didn't explain it enough. The Yuns will be moved around and be connected to different networks by people who don't know how to reprogram them. So the problem is not that the IP is not static, it is that the Yuns will never know the other ones IP.
Maybe I could upload the IP once the Yun is connected and let the other one read it?
sonnyyu:
It is ideal application for Bonjour service.
However Yun supports Bonjour service only, no Bonjour client support at Yun.
@SomethingClever,
to be clear on what SonnyYu is saying. Bonjour service is on the default Yun - the factory setting. So you can setup one of the Yun with a unique name. However, the other Yun does not have the software to be a client to the Bonjour service.
However, if both Yuns can access the Internet, you could setup a registry to hold the IP of each and perhaps connect that way. Is that what you were thinking?
Yes, I was thinking something like that. Either that or just make them read the integer from the database. The last solution is probably the easiest with my limited coding experience
It's surprising to me that you can't just use the "arduino.local" style name to access one Yun from another Yun.
I set up statistics monitoring according to THIS THREAD including setting up a network plugins to collect data on one Yun and send to another. On the one Yun, I set up a server interface to send data to Yun2.local, and on the other I set up a listener interface to receive data from Yun1.local. I did not enter IP addresses, and yet the data was properly sent from one to the other. (See attached image.)
Yet, if I SSH into one of them, and try to ping the other, it says it's a bad address.
Why would collectd be able to resolve the address, yet ping can't?
[b]Sophisticated network code[/b]
collectd utilizes a data push model, i.e. the data is collected and sent (pushed) to a multicast group or server. Thus there is no central instance which queries any values.
Multicast is the key.
To be clear on this, Multicast does NOT resolve any addresses.
Multicast puts out a packet on special IP address and other computers are supposed to listen.
If you look at the dump from ifconfig, it looks like the section below. In the middle of that you'll see MULTICAST. It's enabled and compiled into the kernel. You can catch the packets with any program, if you know the IP. The wikipedia article should have the address.
jessemonroy650:
To be clear on this, Multicast does NOT resolve any addresses.
Multicast puts out a packet on special IP address and other computers are supposed to listen.
I guess that makes sense on the surface. I will have to think about it, because I'm not sure why the sender and the receiver would need to know each other's name or address. If in were designing something like that, I would add a "connection ID" value that is passed in the packets, and which is set to the same value on the sender and receiver sides. If it doesn't resolve to an address, then why would the sender need to know the receiver's name/address, and why would the receiver need to know the sender's name address? I'll have to think this through (although it's not a high priority for me now.)
Still, this might be an idea for the OP: set up a multicast group, have each Yun join it, and talk to each other that way. The multicasts could be used for the actual communications, or just used as a setup phase to exchange their actual addresses, allowing direct communications after that. (Hmmm... maybe that's what collectd does and why it needs those names?)
ShapeShifter:
I guess that makes sense on the surface. I will have to think about it, because I'm not sure why the sender and the receiver would need to know each other's name or address. If in were designing something like that, I would add a "connection ID" value that is passed in the packets, and which is set to the same value on the sender and receiver sides. If it doesn't resolve to an address, then why would the sender need to know the receiver's name/address, and why would the receiver need to know the sender's name address? I'll have to think this through (although it's not a high priority for me now.)
::::SNIP::::
@All,
Last night after I went to bed I recalled that I implemented this over a year ago for a hackathon. My boilerplater code is available on github. It is written in Python. Notes are included in the repo.
#!/usr/bin/python
import socket, struct
MCAST_GRP = '224.1.1.1'
MCAST_PORT = 5007
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', MCAST_PORT)) # use MCAST_GRP instead of '' to listen only
# to MCAST_GRP, not all groups on MCAST_PORT
mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
while True:
print sock.recv(1024)