As part of a bigger project, I need a reliable communication between a TVbox (MXQ) and an Arduino board. On the TVbox, used as dedicated Linux PC, will run a web server (Palapa) and a DBMS (mySQL), while the data are collected and commands are processed by an Arduino UNO. This is an alternative to use an Arduino Jùn. The main advantage is the local screen.
So after some googling I build this little project - small, simple and robust:
- The max length of a master message from php is 60 char (serial Arduino rx buffer limit), the response (from Arduino) as no limits.
- The LF ('\n', 0x0A) is used internally as delimiter.
- The protocol uses CRC8 to insure correctness. In case of error the message is resended 3 times before exit in error state.
- A Bash script (serialArduino.sh) automatically sets the USB serial device on Linux, after every startup or USB re-connection.
- ERROR LCRC: bad CRC Linux -> Arduino
- ERROR ACRC: bad CRC Arduino -> Linux
- ERROR CODE: sended a command code not implemented in Arduino
- ERROR SERIAL: USB not plugged, Arduino not running or fail on open the serial device.
A demo allows to control the built-in LED13 by a web page.
Using this ArduinoLinuxSerial the Master is php, and you need the serial driver (it uses devices like /dev/ACMx or /dev/USBx).
Using USBphpTunnel the master is Arduino, and the Android app uses ports like /dev/bus/dev/00X/00Y, so you don't need the serial driver.
Now you can develop MySQL and web-enabled Arduino applications only working on Arduino and PHP. To keep the Arduino Sketch light, you can port all non-realtime logic to PHP side. At the end, your application will work on MXQ+Arduino UNO even 24/7 with only 20 Watt AC power, and can be controlled by smartphone via WiFi.