StoopKid
Posts: 41
Joined: Thu Jul 19, 2012 5:41 am

Easiest way to communicate with arduino through PHP

Sun Nov 02, 2014 2:06 am

I would like to be able to communicate with an Arduino with a website I am hosting on my Raspi.I have had trouble in the past trying to do GPIO stuff with php, I would end up having to edit a file then have a c++ program read the file to know what to do. And that c++ program wouldn't run as root automatically so I would have to run it in a tmux window so that wiringPi would work. I tried a bunch of tutorials to make wiringPi not require sudo but nothing worked. It was a real mess....

So what is the easiest way to do this? I just want to send a tiny amount of info to an arduino(an atmega328p, to be more particular, I'd like to avoid having to use the entire arduino) from a php script.

riklaunim
Posts: 265
Joined: Tue Apr 22, 2014 7:34 pm

Re: Easiest way to communicate with arduino through PHP

Sun Nov 02, 2014 2:30 am

Serial connection maybe?

StoopKid
Posts: 41
Joined: Thu Jul 19, 2012 5:41 am

Re: Easiest way to communicate with arduino through PHP

Sun Nov 02, 2014 4:14 am

That's what I was thinking but I was hoping someone had some experience with it so I don't jump into another thing that just gives me headaches.

StoopKid
Posts: 41
Joined: Thu Jul 19, 2012 5:41 am

Re: Easiest way to communicate with arduino through PHP

Sun Nov 02, 2014 8:18 am

So yeah, trying to do serial with php and c++ are both giving me tons of problems. While I work on it, are there any suggestions for efficient alternatives?

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Easiest way to communicate with arduino through PHP

Sun Nov 02, 2014 8:37 am

I haven't tried it, so I don't know if it is either possible or efficient, but how about a framework like firmata? There is a standard firmata sketch supplied with the arduino ide. There are php implementations/interfaces for firmata.

https://github.com/ThomasWeinert/carica-firmata

https://github.com/oasynnoum/phpmake_firmata

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Easiest way to communicate with arduino through PHP

Sun Nov 02, 2014 12:20 pm

You can use MQTT (to publish messages) from php without requiring root.

A subscribing program can run as root and control GPIO.

Google MQTT Mosquitto

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13100
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Easiest way to communicate with arduino through PHP

Sun Nov 02, 2014 1:06 pm

dont forgot to add level converters to the serial connection, to account for the fact that the PI uses 3V3 levels, while an arduino normally uses 5V.

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Easiest way to communicate with arduino through PHP

Sun Nov 02, 2014 1:49 pm

asandford wrote:You can use MQTT (to publish messages) from php without requiring root.

A subscribing program can run as root and control GPIO.

Google MQTT Mosquitto
With an ethernet shield on my Arduino and Nick O'Leary's MQTT library I can run MQTT on the Arduino.
http://knolleary.net/arduino-client-for-mqtt/

I've not yet tried running that with my SPI enc28j60 ethernet connected to my Arduino. That's an experiment for another day.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Networking and servers”