-
Notifications
You must be signed in to change notification settings - Fork 4
80. deployment: android server
In production, the tuyaDEAMON must run in a dedicated HW server 24/7.
You can choose between many options.
I like, for my dedicated servers that work 24/7, to use a Tv Box. Why? They are small, ready to use, with a good case, and require little power (5V, 2A) easily upgradable to UPS. For tuyaDAEMON I used the rooted model H96 MAX 3318 (Android 10.0 Smart TV Box Rockchip RK3318 4GB RAM 32GB ROM BT4.0 USB3.0 2.4G 5G Dual WIFI 3D 4K HDR Media Player). For less than USD 35, you get the model 4GB/32GB, what more? Maybe you wanna use a Raspberry? You can, we live in a free world.
In setup, I use a mouse and keyboard via USB dongle, then I control it from my main PC.
The required SW:
- Termux, Linux 4.4 for node-red (a free version on F-Droid). The instruction to install node-red on Android can be found in the node-red site.
- Daily Update Server 2.4.2, a 'AAMP': LIGHTTPD as Web Server, PHP, MYSQL, PhpMyAdmin, MSMTP.
- For remote file management we have two options:
- File Explorer WiFi using a browser as client.
- Tiny FTP server using as client or Windows 'File Explorer' (slow), or WinSPC (better).
Continue the installation as usual..
Of course, I use my main Windows PC as a development environment. Updating the remote is easy: I open 2 node-red windows on the screen (local and remote) and export the flows to the clipboard from the PC then import them on the server.
I found myself in the position of needing another 24/7 TuyaDAEMON server for the beach house, for a typically domotic application: control of energy consumption and management of solar panels, management of air conditioners, and garden watering. The goal is to get a professional look, as I will use the TV screen in the living room, with small applications on the phone for the most frequent commands. Graphs and statistics via a cloud or via WEB server with dynamic DSN no_ip. The tuyaDAEMON autostart is mandatory for this server.
The starting HW is an X88 PRO Android 11, 4GB RAM 32GB ROM with a mini keyboard included (€ 43.99).
First of all I installed (download the APK
file, then open the FileBrowse
APP, and go to Download
dir and click and install the APK
file):
a) MacroDroid from APKpure, to make the start automatic and for the management of shortcuts.
b) Termux 118 (Android 7+) from f-droid. The next 119 version should be compatible from Android 5+. For more info see Termux-installazione.
c) ftpd installed inside Termux. Using the instructions I installed the FTP as service. In short:
pkg update
pkg upgrade
pkg install busybox termux-services
- restart (Android 'Settings', then 'Device preference', then 'About', then 'Reboot').
- fire Termux
sv-enable ftpd
sv up ftpd
Note on the keyboard: The small keyboard works well, except for some keys (CR, '/', '-' etc.) in some contexts. Instead of trying to fix it, I used a mix of HW keyboard and the on-screen virtual keyboard, smooth and quick enough to accomplish the required task.
SFPT: You can install also a safer SFTP, I don't install it because I use FTP only in the development phase.
Test with an FTP client at port: 8021, name: root
, password: none, dir: /data/data/com.termux
(on Windows I use WinSCP).
You can get access to internal storage (see here) and you can remotely edit any Termux file, setup a WEB application, create scripts, etc. as if everything were local.
Note for Windows users: take care to use the 'Unix' line terminator (only 'LF') when you edit remote script files, else you get garbled messages 'File not found' etc... I use, on Windows, WinSCP
+ external editor Notepad++
.
To enable Shared and External storage (sdcard, download, etc...), do:
termux-setup-storage
Verify that you can access shared storage ls ~/storage/shared
. If the test fails, see the workaround for Android 11 here.
d) utils required by LAMP installation:
pkg install git bc ncurses-utils
e) LAMP The complete instructions are here. In short:
git clone https://github.com/mayTermux/lampTermux
cd lampTermux
./install.sh
This will install:
- Apache v. 8.1 <top-box-IP>:8080
- MariaDB v. 2:10.9 <top-box-IP>:3306
- PHP v. 8.1
- PHPMyAdmin v. 5.1.3 <top-box-IP>:8080\phpmyadmin
and the utility lamp
. Run lamp
to enable the services.
Follow the instructions to activate the first user with a password (e.g. 'root'/'root', as required by PHPMyAdmin
) in MariaDB
(after more users can be managed with PHPMyAdmin). In short:
mysql -u $(whoami)
// try also: mysql -u root
MariaDB [(none)]> use mysql;
MariaDB [(mysql)]> set password for 'root'@'localhost' = password('root');
MariaDB [(mysql)]> exit;
Verify that everything is working: I had to edit the phpmyadmin/config.inc.ph
file, see the Troubleshooting.
f) node-red: before installation, the following packages are suggested:
pkg install clang make python pkg-config
The instruction to install node-red on Android can be found in the node-red site. In summary:
pkg install coreutils nano nodejs
npm i -g --unsafe-perm node-red
node-red -p:<port>
g) I added also a little script (using nano) in ~/
(aka /data/data/com.termux/files/home
): gored.sh
, only one line
#!/data/data/com.termux/files/usr/bin/sh
node-red -p:2022
and I made the file executable: I use this to run node-red from terminal
chmod 700 gored.sh
./gored.sh
h) Autostart
h.1) At device boot, to start Termux
: I make a macro ('gotermux') in MacroDroid
:
Trigger: 'Device Boot'
Actions:
- Wait for 1 second
- Launch Termux
h.2) The services ftpd, httpd, mysqld
, if enabled, will start automatically.
h.3) To start node-red
:
-
I created a file
~/.profile
that contains one line (see here):termux-wake-lock
-
I created a file
~/.bashrc
(see here):#!/data/data/com.termux/files/usr/bin/sh node-red -p 2022
h.4) More (optional):
-
PAW Server from paw-android.fun2code.de, a web server with extensions for Android ... (see also termux-API): it might be useful.
-
A simple Android launcher (Apex from APKpure) to manage the overall look and feel in production.
-
A backup can be done via FTP, or see here: this is my
backup.sh
file (very slow):#!/data/data/com.termux/files/usr/bin/sh tar -czfv ~/storage/dcim/termux-backup.tar.gz -C /data/data/com.termux/files ./home ./usr
and this is restore.sh
:
#!/data/data/com.termux/files/usr/bin/sh
tar -xzf ~/storage/dcim/termux-backup.tar.gz -C /data/data/com.termux/files --recursive-unlink --preserve-permissions
Then I opened, on the development PC, two node-red
windows: one local, the other connected to the Android server (in my case: http://192.168.100.100:2022
):
-
Looking at the local list of installed nodes (
manage palette|Nodes
) I installed the same nodes innode-red
on Android (manage palette|Install
). Here my actual list for the full tuyaDAEMON:node-red-contrib-aedes node-red-contrib-config node-red-contrib-jsontimer node-red-contrib-looptimer-advanced node-red-contrib-play-audio node-red-contrib-rtl_433 node-red-contrib-timerswitch node-red-contrib-tuya-smart-device node-red-contrib-ui-led node-red-dashboard node-red-node-base64 node-red-node-mysql node-red-node-serialport (*)
(*) note: Due to an issue in node-serialport this node doesn't work in Android, only in Windows and Linux. See also node-serialport on Termux (Linux on Android).
- Locally I opened the 'CORE' flow, then I did the
Export|current flow|Copy to clipboard
command. - In node-red on Android I used
Import Nodes|Paste flow json
, executedpaste
, and chosenew flow
.
Last I used the Deploy
command and tuyaDAEMON started working on the Android server. Driven by the error messages I had to:
- Update
GLOBAL.remotemap
(Node '* Global CORE config
') with the URLs of the new server. - Change
GLOBAL.instance_name
to the new name. - Update name/password for access to MariaDB (values are not copied from local by node-red for security) in '
MySQLdatabase configuration nodes
'. - Used a
sql
file and PHPMyAdmin to create the required DataBase tables.
Now I can continue the custom configuration of the tuyaDEAMON server by eliminating the devices that are not needed in the new server, updating alldevices
, and copying other modules (core_TRIGGER, core_MQTT...).
Enjoy.