I need to send data from a web page to an arduino, but without knowing the ip address. My idea is to make the arduino listening on a specific port and the web page would send data to this port.
Can my idea work ? If yes how to do the php part ?
Otherwise what can i do ?
Sorry for my english, i'm not really good.
If you want to send data to somebody on the Internet you have to find out their IP address. There is no other way. If the recipient has a dynamic IP address they need to tell the sender about it somehow. A dynamic DNS service is one example of this.
However if this is all in a local network and you make sure everything is set up correctly, you can also send to a broadcast address. Broadcast packets will be received by any host in the local network.
I don't know anything about PHP, but if you want to do this over a LAN you need to know the hostname. In laymans terms, the hostname acts as the IP address over the LAN.
Related
I want to send a value from my website to my arduino using httprequest.
as the image explain, i want to enter my site from a device (let's say mobile phone) and send a request to my arduino from my website (webserver)
so i'm having this problems:
1- how to address the arduino without dns, should i have a fixed ip address for my arduino, is there any way else ?
2- what is the PHP code that i need to let the website send the request ??
i know i can connect arduino to web using httpclient, but i want the reverse process, that is connect the website to arduino ( the website as client and a arduino as a server)
is there anyway to do that ?
thank you and sorry for my bad english
I've recently made a similar project with a Raspberry Pi. But this doesn't make a difference.
First be careful with my solution. Anybody can join on your device, if they have your IP and Port. It might be not the best solution, but it works pretty good.
So what I did is, I've set a DynDNS to my router, so that I doesn't have to change the IP in my script every time. You can get a DynDNS from your provider or you can use the free service No-IP. Next I set a static local IP adress to my arduino/pi via the settings on my router. Then I also set port-forwarding to the arduino/pi.
Then you should be able to access your arduino/pi via the internet. And if you have this, you can also control it via any website you want.
To accomplish an HTTP request in PHP, there will be a lot of possible solutions. But I prefer this:
$response = file_get_contents(YOUR_DYNDNSIP_AND_PORT)
https://www.w3schools.com/php/func_filesystem_file_get_contents.asp
You also can additionally can get a response via this function.
To protect your own network, you can use HTTP Basic Authentication, which you have to add a username and a password to the request. This make it difficulter to access your arduino.
I hope this might help you.
I know that's a confusing title but let me explain. I'm working on a website and I want it to look differently depending on if they used the ip or example.com in the address bar. Is it possible to get what address they used in PHP? I know you can change it with header('Location:example.com'); but I need to know how to get it.
Print out
$_SERVER['HTTP_HOST']
will resolve your problem.
Servers are always accessed by their IP addresses. If someone types in the hostname 'example.org' the device will resolve it using a DNS server (large list of hostnames and their respective ip addresses), the DNS server will give the device the IP address and the device will connect to that IP.
TCP/IPv4 packets can only be sent to 32-bit ipv4 addresses.
TCP/IPv6 packets can only be sent to 128-bit ipv6 addresses.
On the page you want to know from what location a visitor came in from, do this:
var_dump($_SERVER);
You will see all the $_SERVER values you'll use to get different values you require.
Can some one help me to read out the IPv6?
I tried this Working with IPv6 Addresses in PHP but it does not work for me..
There is no problem to get the IPv4 over
echo $_SERVER['REMOTE_ADDR'];
but can someone tell me how i get the IPv6?
This Site can read both (IPv4 and IPv6): http://ipv6-test.com/api/. But I try it without any api, is that possible?
Thanks
You have the right idea, but the request has to be made with IPv6 if you want an IPv6 address.
The site you link to probably works by having a page that loads resource from a server only accessible via IPv6. If it works, then you know the address.
I would just build a site that fires off AJAX requests to the same server, one via IPv4 and one via IPv6. Use its IP addresses to rule out any local DNS issues where IPv6 may not be supported.
I just downloaded PhProxy from here. When I went to some IP locator site my IP was a Dallas/Texas IP. Is there any way to change the IP PhProxy uses? I couldn't find a way to do it.
PHProxy - like all proxies - accepts requests from any of a number of IPs and acts on their behalf to fulfill that request. The IP you're seeing is almost certainly the IP address of your webserver, and no you can't edit some setting to change it. Your server makes a request to some address and includes its own address - this is how the remote end knows how to answer back. You couldn't change this with a PHProxy setting even if you wanted to - if you could, your packets wouldn't get back to you.
You could get a different webhost, if a Dallas-located IP is a real problem, but it would be locked to the new webhost just the same. Webservers can't exactly IP-hop...
If I'm on a local network is there a URL that I can type that will allow all users on the local network to view a local hosted website?
There is one feature called put online but I would need to be connected to the internet. Can it be done another way?
I know this question is off subject but I get fast responses here. and its somehow related :)
You can use either your local IP or your hostname on the network.
For the hostname to work, your network needs a DNS server that updates itself from DHCP, or has a static entry for your computer, or all the systems need to have NetBEUI running. If you can type "ping " in a command prompt/console window, and it shows it pinging your network IP, then it works.
they have to enter your ip
You could use your local network IP address to address your machine. But you have to configure your webserver to deliver the right content without a specific host name.