I’m working on a WiFi controlled robot using the Yun. I have a working proto-type using the Mega 2560 with a WiFi shield, but I want to port this to the Yun because its much compact than a Mega with a WiFi shield.
I have a PC application that sends data over Wifi to the robot. The robot needs to read the data and change servos or I/O pins based on the values.
I’ve seen several Python scripts that open a socket to read data. In all the examples I found, the IP address was hard coded in the script. I don’t want to have to edit the Python script every time my IP address changes. There is a pretty-wifi-status.lua script that works with an example sketch, but its in lua, not Python.
This script works on my PC, but errors on the Yun.
import socket hostname = socket.gethostname() address = socket.gethostbyname("%s.local" % hostname) addr = address print addr
The error I get is:
File “getIP.py”, line 3, in
address = socket.gethostbyname("%s.local" % hostname)
socket.gaierror: [Errno -2] Name or service not known
Can anyone tell me what I am doing wrong or another way to get the WiFi IP address of the Yun from within Python?