Android app for MXQ TV box to control an Arduino UNO board via USB from PHP. Designed for data-logging applications (weather, hydroponics, greenhouses, aquariums, home automation, power consumption, solar or wind generators, etc.), this solution can also be useful in alarm systems.
On USBphpTunnel terminal you can see:
The data MUST be a relative URL, like: '"
"' and MUST start with "/". So
[phpPath (in config) + data]
makes an absolute URL, called by USBphpTunnel.
Note: Your Arduino Sketch will build relative URLs using the required PHP pages and actual values.
The PHP sample code in add.php (see test_files/www/testio/add.php):
- adds a record to MySQL table datatest.esempio
- builds the response: pure ASCII (not HTML)
USBphpTunnel sends the response to Arduino.
The data are commands, as defined in testser02.ino (see /test_files/arduino/testser02.ino):
- Analog write, sent as "A port value": A [3..11] [0..255] [0xD|0x0A] (as decimal, 0-octal, 0x-esa)
- Digital write, sent as "D pin value": D [2..13] [0|1|2] [0xD|0x0A] (as decimal, 0-octal, 0x-esa) values: 0 = LOW, 1 = HIGH, 2 = TOGGLE
- Parameter set, sent as "P index long-value": P [0..15] [[-]0..2'147'483'647] [0xD|0x0A] (as decimal, 0-octal, 0x-esa)
Note: USBphpTunnel accepts any line terminator (\n or \r or \r\n) and transforms it in single "0x0A" (\n)
Note: In your Arduino Sketch you can eliminate unused commands or add your custom commands. Commands MUST NOT start with "*" char.
The message MUST start with "*". It appears in the terminal (not sent to php).
Note: green - color set on config.ini
The message MUST start with "*". It is show on terminal (not sent to Arduino).
Note: red - color set on config.ini
Because this protocol is pure text, we can also do testing with a standard terminal application. Arduino console terminal: the only terminal app that worked with my Arduino board is "Serial USB terminal". Developed and tested using:
- MXQ 4K*2K 1080P Smart TV BOX XBMC/Kodi H.265 Android Quad Core WiFi 8GB Mini PC: http://www.ebay.it/itm/141956901542 (29.78 €)
- ARDUINO UNO R3 Scheda Micro USB ATmega328P CH340G Board Controlled by Arduino: http://www.ebay.it/itm/152002551433 (5.79 €)
- MXQ Palapa Web server: https://play.google.com/store/apps/details?id=com.alfanla.android.pws
- Download USBphpTunnel01_d.apk and the full /test_files/ dir
- See file: /test_files/readme.txt
Using this 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.
Using the new USBphpTunnel_fifo https://github.com/msillano/USBphpTunnel_fifo the master is php. It is NOT blocking the master, allows payload up to 4k, allows concurrence (many users via WIFI). Works in background and it is not fast (depending from polling Arduno frequence, 3-10 sec. plus processing time). Well placed for long Arduino processes (like waiting user actions).
Using the simple ArduinoLinuxSerial https://www.hackster.io/msillano/arduinolinuxserial-c17736 the Master is PHP, and you need the serial driver (it uses devices like /dev/ACMx or /dev/USBx). Blocking master, but fast and robust protocol (CRC and repetions). Useful with simple and fast Arduino responses.
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, or from ewerywhere using a Dynamic DNS (like the free no-ip).