0

I want to send a value from my website to my arduino using httprequest.

EXPLANATION

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.