(5)綁定(關聯) project 內各 DA,
包括左方提供資料的 DA 和右方收資料的 DA (DM 是DataServer)
(6)在 Dashboard上 點 Management, 點 User 設定各 User 可以看到哪些場域(Field)資料 !
以及該 user 登入時預設顯示的場域 (active field)。
這樣登入 Dashboard 每個 User 可看到不同資料 !
TOP
FarmDashboard 可以使用 mysql 或 sqlite,
要使用 sqlite 或 mysql 可以修改 FarmDashboard 根目錄的 config.py
vim config.py
大約在 LINE 10 ~ LINE 13 處, copy 註解掉的去用即可
# DB_CONFIG =
'<database>[+<orm_lib>]://[<user>[:<password>]]<host>[:<port>]/[db_name][?charset=utf8]'
# ex: DB_CONFIG = 'mysql+pymysql://user:pass@localhost:3306/dashboard?charset=utf8'
# ex: DB_CONFIG = 'sqlite+pysqlite:///db.sqlite3'
DB_CONFIG = ''
#注意用 mysql 時 user:pass 就是你在MySQL的帳號:密碼 請不要用引號夾住!!!
如果使用 MySql 需要安裝並設定 mysql,
如果使用 SQLite 則 SQLite 已經內建在 Python3 內!
SQLite is a self-contained, file-based SQL database.
SQLite comes bundled with Python and can be used in any of
your Python applications without having to install any additional software.
See How To Use the sqlite3 Module in Python 3
System environment for FarmDashboard
1.)Open VirtualBox and select New . A new window will come out.
2.)Choose your guest OS and architecture (選 64 bit, select Ubuntu)
3.)Set your Base Memory (RAM) 建議至少 2GB
4.)Click next until it show the vm storage size. 建議設定 10GB 應該就夠用!
Put how much space you need depending on your hardisk and finish the wizard
by clicking the create button.
5.)On VirtualBox main window, select START and pick your MEDIA SOURCE.
For example, select the .iso on your desktop.
6.)Finish the installation as normal install.
7.)Remove your installation .iso from the virtual optical disk drive before restarting the VM.
關於 MySql 與其安全設定 (如果使用 sqlite 則這部份不用看:-)
How To Install MySQL on Ubuntu 16.04
mysql security setting (mysql 安全設定)
Ubuntu 安裝完Mysql的時候預設是沒有root密碼以及相關設定的,
這時候就需要先用mysql_secure_installation這個指令來對MySQL進行初始化設定。
mysql_secure_installation
若問密碼, 按 ENTER 鍵即可
然後,原則上全部回答 y 就對了:-)
如果啟動 mysql 有啥 PID 錯誤, 就 :
sudo rm -rf /usr/local/var/mysql/*.err
sudo service mysql restart
按ESC退出insert mode
存檔並結束修改
:wq
然後重啟mysql以更新設定,
接著登入 mysql(以root使用者登入),
打 status 再次查看 characterset status
sudo service mysql restart
mysql -u root -p
status
在 MySql 建立 (create) new user for dashboard
# 登進mysql新增 MySQL 內的 user,允許連線 IP,與資料庫( db_name ),以及權限 :
CREATE USER 'user_name'@'%' IDENTIFIED BY 'user_password';
# 設定new user的user_name(e.g dashboard),允許連線的IP( % 代表允許任一IP連線)和user_password
注意, password 千萬不要含有 @ 阿不然有大麻煩 !!!
這裡的 user_name 是指 mysql 內的 user, 與 Linux user name 無關,
也不必要叫做 dashboard, 但這是要用來放在 FarmDashboard 的 config.py
內設定 DB_CONFIG = ' ... ' 用的,大約在 config.py 的 LINE 10 ~ LINE 13處。
# 看看已經有哪些 user
SELECT * FROM mysql.user;
# 給予使用者權限 privileges for new user
GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'%';
flush privileges;
說明:
ALL PRIVILEGES: allow the user to read, edit, execute and perform all tasks
across all the databases and tables.
*.*:The asterisks in this command refer to the database and table that they can access.
(* represents that all databases and tables are available)
@'%': allow the user from any IP
flush privileges; #:刷新權限以更新權限設定
詳細 mysql 的 user 與 權限 (Permissions)請參考這:
https://www.strongdm.com/blog/mysql-create-user-manage-access-privileges-how-to
建立給dashboard使用的database,設定db_name (e.g dashboard)
create database db_name;
注意 db_name 不要亂取 ! 就用 dashboard
例如:
create database dashboard;
與 mysql 有關的一些常用 Linux 命令
# Start the MySQL service normally.
sudo service mysql start
# 或 sudo systemctl start mysql
#If you are receiving the following error message:
MySQL services are masked
# Do the below commands
sudo systemctl unmask mysql.service
sudo service mysql start
# Stop MySQL
sudo service mysql stop
# To restart MySQL service
sudo systemctl restart mysql
# 或這樣
sudo service mysql restart
# To verify if the MySQL service is started or not
sudo systemctl status mysql
# 或這樣
sudo service mysql status
# To check the MySQL version
mysql --version
# To enable MySQL to start automatically on every reboot
sudo systemctl enable mysql
# Turn off MySQL.
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
# reset mysql root password
sudo mysqladmin -u root password
# Set MySQL root user password and policy, RUN mysql_secure_installation script
sudo mysql_secure_installation
# (原則上都回答 y 就是了:-)
# Start MySQL manually, without permission checks or networking.
#(通常是因忘了密碼用來進入 mysql 內修改 root 或 user 的密碼用, 正常不建議!)
sudo mysqld_safe --skip-grant-tables --skip-networking &
# 執行上句子後, 可以不用輸入密碼直接連入 mysql
mysql -u root
######
###### 如果前述 start MySQL 有錯誤, 可以做以下兩步驟後重來:
# Make MySQL service directory.
sudo mkdir /var/run/mysqld
# Give MySQL user permission to write to the service directory.
sudo chown -R mysql:mysql /var/run/mysqld
常用的 SQL commands:
# Log in without a password.
mysql -uroot mysql
*** Note that MySQL command is not case sensitive.
But also note that database name/table name/column name ARE Case sensitive.
create database [database_name];
show databases
use [database_name];
show tables
SELECT * FROM [table_name];
drop table [table_name];
drop database [database_name];
建立 場域 (create fields)
5.1 click Field to look through Fields list
5.2 press the add button to enter Field Management interface
5.3 fill in corresponding field contents
(e.g)
name alias
floor1 蘭花屋一樓
5.4 press the + button besides sensors to add corresponding sensors to the field
5.5 press the create button to add field to the dashboard
在iottalk server 新增project
(e.g 點 首頁 project 會開新窗 http://140.113.199.213:7788/connection)
6.1 根據project選擇對應IDF和ODF
6.2 將IDF與ODF連線(注意:一個project內不能出現超過30個join否則會出現internal server error)
6.3 綁定(關聯)各 Device Model 對應 device_name
open dashboard (e.g http://140.113.199.223:7788/) to see the result
(check the result with iottalk server IP/list_all)
(e.g http://140.113.199.213:9999/list_all)
可參考video進行操作:
多語系(i18n)使用說明 .. (from FarmDashboard README.md)
文字準備
## python
# use gettext('') to the needing change words.
from flask_babel import gettext
msg = gettext('Babel is good.')
# or if you want to use constant strings somewhere in
# your application and define them outside of a request,
# you can use a lazy strings lazy_gettext('').
from flask_babel import lazy_gettext
msg = lazy_gettext('Babel is good.')
## Javascript
# use {{ _('') }} to the needing change words. for example: