How do I find the Yun IP address in a Python script


i'm working on wifi controlled robot using yun. have working proto-type using mega 2560 wifi shield, want port yun because compact mega wifi shield.

i have pc application sends data on wifi robot. robot needs read data , change servos or i/o pins based on values.

i've seen several python scripts open socket read data. in examples found, ip address hard coded in script. don't want have edit python script every time ip address changes. there pretty-wifi-status.lua script works example sketch, in lua, not python.

this script works on pc, errors on yun.
code: [select]

import socket
hostname = socket.gethostname()
address = socket.gethostbyname("%s.local" % hostname)
addr = address
print addr


the error is:

  file "getip.py", line 3, in <module>
    address = socket.gethostbyname("%s.local" % hostname)
socket.gaierror: [errno -2] name or service not known

can tell me doing wrong or way wifi ip address of yun within python?

code: [select]
nano getip.py

code: [select]
#!/usr/bin/python
import socket
s = socket.socket(socket.af_inet, socket.sock_dgram)
s.connect(('arduino.cc', 0))
address=s.getsockname()[0]
print address


code: [select]
chmod 755 getip.py

code: [select]
./getip.py


Arduino Forum > Products > Arduino Yún (Moderator: fabioc84) > How do I find the Yun IP address in a Python script


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support