I have a php file placed on the SD card of the Yun which echoes an integer when rendered. I then use HttpClient.get to get that integer. Everything works fine with the code below where I use the IP-address, but when I use myyun.local I get some weird number.
HttpClient webClient;
webClient.get("http://192.168.1.50/sd/myproject/testfile.php");
while (webClient.available()) {
int x = webClient.parseInt();
}
I read about Bonjour in another thread, but it is not a problem that I cannot access when not using the IP in my browser, but only that the Arduino can't either.
Angelo9999:
You can assign to your Yun a fixed address.
Or, you can leave the Yun using dynamic addresses (DHCP) and set up your DHCP server (usually in your router) to use Static DHCP to always hand out the same address to your Yun (based on the Yun's MAC address.) the advantage to this is that all of the network addressing details are all in one place (in the router) rather than scattered across multiple devices.
Maybe I did not explain myself well enough. My Yun always have the same IP on my wifi, so everything always works at home, but if I connect it to another network it of course gets a different IP, and that's where my problem is.
SomethingClever:
I have a php file placed on the SD card of the Yun which echoes an integer when rendered. I then use HttpClient.get to get that integer.
Is the PHP file, the SD card, and the sketch doing the get() call all on the same Yun? That's what it sounds like. If so:
try using the address 127.0.0.1, which is a local loopback address and will always reference the local machine, regardless of its current address
rather than incurring the web server and network overhead, try using the Bridge library's Process class to execute the PHP file directly
Yes, everything is on the same Yun. I will try the loopback address and hopefully that will work.
I should use the Process class to execute the PHP file, or maybe install the php client class (which I tried but I could not make it work), but right now it seems unmanageable as I don't understand it, or Linux, at all. When I bought the Yun I thought it was only a bit harder to get a grip of than the ordinary Arduinos as the Leonardo