I’m currently working on interfacing a Raspberry Pi with an Arduino. The Pi needs to tell the Arduino it’s IP address on the LAN in order for it to be displayed on an LCD screen.
My code running on the Pi is PHP. It’s usually pretty straightforward to get your local IP address from within PHP.
I just make use of the handy $_SERVER array like so:
failed. SERVER_ADDR wasn’t set. Using my initiative, I threw together the following function, which works a treat:
It basically calls the linux command ‘ifconfig’. The IP address is then extracted from the results.
This should work for any occasion where $_SERVER['SERVER_ADDR'] isn’t available, as a fallback.
Feel free to use this in your own projects!
If you have a folder full of files in windows and you’d like a list of filenames, you may have wondered how the hell you can do it. Well, it’s easy. Here’s how it’s done.
1. Open up the directory in Windows Explorer and hold shift whilst right clicking somewhere within it (not on a file). From the context menu, select ‘Open command window here’.
2. You should see a console window open. Type the following line and hit ‘enter’:
dir *.* /b > files.txt
3. You should see a new file appear within your folder called ‘files.txt’. Open it up in notepad and there’s your list of files! (It also contains ‘files.txt’ listed within it, you might want to delete that line)
You can choose to show only certain filetype by changing the ‘*.*’ wildcard. The line below will show all JPG images:
dir *.jpg /b > files.txt
That’s it. It’s easy when you know how!
I use this trick all the time. I hope you find it as useful as I do.