PHP and Arduino

I am doing a project which consists in controlling Arduino through a website. I am fairly new to this and the deadline approaches for project delivery. For communicating with the Arduino I am using a COM port. Anyway, my question is, is there anyway to auto select the arduino port in PHP? It feels so bad when I have to run all the code and change all COM’s to the one I want.

All help is appreciated.

(See some of my actual code bellow)

misolans:
For communicating with the Arduino I am using a COM port.

That is not going to work for communicating with a website.

Have a look at this Python GUI demo. It has a system for selecting the port and you may be able to use the same technique with PHP.

...R

ieee488:
That is not going to work for communicating with a website.

So far it is working... At least it works to change RGB Led to HIGH.

ieee488:
That is not going to work for communicating with a website.

My guess is that the flow of data is
Arduino ----> PC (PHP) ----> website

...R

Robin2:
My guess is that the flow of data is
Arduino ----> PC (PHP) ----> website

...R

PHP can't run as standalone as Python does. It is a website programming language.

Arduino ---> PC (PHP + website) [cannot work]

misolans:
So far it is working... At least it works to change RGB Led to HIGH.

Good for you! I have no idea what RGB Led to HIGH really means. LOL.

ieee488:
PHP can't run as standalone as Python does. It is a website programming language.

Forgive my ignorance. I abandoned PHP years ago.

However I believe it can access the serial ports on the server so my sense of the role of the Arduino is probably correct.

...R

ieee488:
PHP can't run as standalone as Python does. It is a website programming language.

Arduino ---> PC (PHP + website) [cannot work]

Actually PHP can work standalone, used in command-line mode or as interactive shell .

Ciao, Ale.

ilguargua:
Actually PHP can work standalone, used in command-line mode or as interactive shell .

Ciao, Ale.

I don’t think that is what the OP has been mind, but if you know how to do what the OP wants, have at it! No one is stopping you.

It sounds like an interesting architecture.
The more usual way of getting an Arduino to interface with a web site is that the Arduino is directly integrated into the local network with WiFi or Ethernet. The Arduino issues HTTP Post/Get commands to the Webserver and on the web server there is PHP/HTML code which interprets those commands, writing to or reading from a database. To illuminate a LED on the Arduino, as in this instance, a user would use a web page which set a status row in a database to indicate that the LED should be on, and the Arduino would poll regularly to see what the current LED status should be and set it accordingly.

6v6gt:
The more usual way of getting an Arduino to interface with a web site is that the Arduino is directly integrated into the local network with WiFi or Ethernet. The Arduino issues HTTP Post/Get commands to the Webserver and on the web server there is PHP/HTML code which interprets those commands, writing to or reading from a database.

I have built a couple of small Python web-servers to provide a GUI for {a} model train control and {b} control of a small CNC lathe. In both cases the server is connected to the Arduino by the USB cable. The purpose of the web-server is to act as an interface to the Arduino.

I have the impression from the mention of a COM port in the Original Post that this is what the OP has in mind.

...R

I've created a Python HTTP to Serial gateway to handle this kind of thing in the past. With python twisted you can make it nicely asynchronous. The PHP script (or rather the ajax/javascript in my case) talks to the python webserver and issues commands that are relayed to the Arduno. I must put it up on Github some time (it requires some cleanup first).

I encountered this post on Reddit recently:

A simple websocket to serial bridge for your connected projects (JAVA)

That could be a nice way to do it too.
The Java process creates a websocket process that connects to the Arduino.

Hi, can I suggest a simpler solution?

A Wemos D1 mini and an RGB led mini shield.

The Wemos connects to WiFi and acts as a server, hosting a simple web page. Users can connect to this page and set the desired colour and brightness. No PC, no PHP, no Arduino!

The Wemos can be programmed using the Arduino IDE.

D1-mini-Mini-NodeMcu-4M-bytes-Lu.jpg
WS2812B-RGB-SHIELD-for-WeMos-D1-.jpg