講師:MakerPRO技術顧問 柯大
E-mail :kochingchang@gmail.com
手機: 0928226125
1
1.日立智慧型冷氣架構說明
2.工業控制協定RS485 MODBUS功能說明
2
3.串接RS485連接日立冷氣 MODBUS
4.利用PC設定及接收智慧空調資料
5. Ameba Arduino 開發環境安裝及各項功能
7. IoT 平台介紹
 各種IOT平台比較
 MQTT 介紹
 QNAP NAS 建立IoT私有平台雲
6 RS485 模組及 MODBUS Library功能
3
1.日立智慧型冷氣架構說明
4
5
6
7
1.日立智慧型冷氣架構說明
8
9
10
11
12
13
2.工業控制協定RS485 MODBUS功能說明
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
3.串接RS485連接日立冷氣 MODBUS
A
B
31
A
B
32
USB (COM) 轉 RS485 模組
USB connect to PC
A and B : the RS485 pair
Connect to RS485 Device
33
DI (data in) to pin 1 (D1) TX
RO (receive out) to pin 0 (D0) RX
DE (data enable)
RE (receive enable) jumpered together and to
DE pin 7 (D7)
Vcc 5V and Gnd connected (5V Gnd)
A and B : the RS485 pair
RS485 轉UART (TTL (RX/TX) 模組
34
4.利用PC設定及接收智慧空調資料
(1) 將USB (COM) 轉 RS485 模組與PC USB
埠連接。
(2) 安裝 COM port驅動程式:
目錄: CH341_USB_DriverCH341SER
安裝程式:SETUP.EXE
(4) 啟動PC modtool 讀取冷氣機暫存器值
目錄: RS485MODBUS-TOOL
執行程式: modtool.exe
(3) 查看裝置管理員中USB是否有新增加的序列(COM)埠
35
36
37
38
39
40
41
42
http://arduino-info.wikispaces.com/SoftwareSerialRS485Example
Arduino UNO RS485 模組 對接測試
43
Arduino UNO 與 AMEBA RS485 模組 對接
44
#include <SoftwareSerial.h>
#define SSerialRX 0 //Serial Receive pin
#define SSerialTX 1 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
int byteReceived;
int byteSend;
void setup()
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(38400);
Serial.println("Use Serial Monitor, type in upper window, ENTER");
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, LOW); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(4800); // set the data rate
}
void loop()
{
if (Serial.available()) {
byteReceived = Serial.read();
digitalWrite(SSerialTxControl, HIGH);
RS485Serial.write(byteReceived);
delay(10);
digitalWrite(SSerialTxControl, LOW);
}
if (RS485Serial.available()) {
byteReceived = RS485Serial.read();
Serial.write(byteReceived);
delay(10);
}
}
AmebaMaster.ino
45
ArduinoUNO Slave.ino
#include <SoftwareSerial.h>
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
int byteReceived;
int byteSend;
void setup()
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(38400);
Serial.println("SerialRemote"); // Can be ignored
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, LOW); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(4800); // set the data rate
}
void loop()
{
//Copy input data to output
if (RS485Serial.available()) {
byteSend = RS485Serial.read(); // Read the byte
delay(50);
//Serial.println(byteSend);
digitalWrite(SSerialTxControl, HIGH); // Enable RS485 Transmit
RS485Serial.write(byteSend); // Send the byte back
delay(10);
digitalWrite(SSerialTxControl, LOW); // Disable RS485 Transmit
}
}
46
5. Ameba Arduino 開發環境安裝及各項功能
Ameba module -RTL8195AM 本身規格
* 32-bit 166MHz ARM Cortex-M3 CPU
* 內建 低功耗 802.11 b/g/n 2.4G 無線 Wi-Fi
* 內建 NFC
* 介面支援 : GPIO / PWM / SPI / I2C / ADC / DAC / UART
* Crypto HW engine : 可做硬體加解密, 支援 MD5/ SHA-1 / SHA2-256
/ DES / 3DES / AES
* IC 本身有 512K RAM, 另外模組有包 2M SDRAM / 16M bit flash
47
米巴開發板功規格介紹
※資料來源:https://www.facebook.com/groups/1494719674163013/
Ameba板外接介面圖
連接PC USB
外接WiFi 天線
外接NFC
天線
48
49
PinD13 Reset鍵Gnd
50
1. <檔案>- <範例>-<01-Basic>-<blink>
2. 上傳燒錄程式
3. 按Reset鍵啟動新上傳的程式
 測試開發板功能運作是否正常
51
6 RS485 模組及 MODBUS Library功能
// 利用UART 控制通訊接收、傳送
#include <SoftwareSerial.h>
// 定義半雙工送收控制接腳的PIN
#define RS485CtrlPin 7
// 定義 通訊延遲時間
#define TIME_REQUEST 7
unsigned long interframe_delay = 2; /* Modbus t3.5 = 2 ms */
// 宣告回傳值及buffer 、傳輸速度等變數
int retval;
int data[12];
int baud_rate = 9600;
// 宣告冷氣回傳暫存器變數
int v00,v03,v04,v20,v21,v22,v23,v24,v29,v2a,v2b;
// 讀取冷氣暫存器值
retval= read_holding_registers( AC_no,0,1,data,10);
v00= (unsigned int) (256 *( data[0]>>8) + (data[0] & 0x00ff) );
Modbus.ino
52
RT_HT_MODbus_Get12_20160827_V3.ino
// RS485 MODBUS 通訊副程式模組
HT_MODbus.ino
//序列埠監控視窗顯示冷氣機資料副程式模組
displayDATA.ino
//讀取冷氣機資料副程式模組
readAC.ino
//主程式
Void Setup() {
…
}
Void Loop() {
…
}
7. 實作練習
53
申請Temboo帳號
https://www.temboo.com/
申請Xively帳號
https://personal.xively.com/signup/
申請ThingSpeak帳號
https://thingspeak.com/users/sign_up
申請Thethings.io帳號
https://panel.thethings.io/#/login
申請Yeelink.net帳號
http://www.yeelink.net/register
申請lewei樂為聯網 帳號
http://www.lewei50.com/home/register
申請pieceduino Cloud帳號
http://www.pieceduino.com/pieceduino-web-panel/
IoT雲端平台參考網站
申請MediaTek Cloud Sandbox 帳號
https://mcs.mediatek.com/oauth/en/login
申請Thethingsnetwork 帳號
https://account.thethingsnetwork.org/register
54
http://thethings.io/
55
https://www.thethingsnetwork.org/
56
https://www.temboo.com/
57
58
https://mcs.mediatek.com/zh-TW/
59
60
61
https://thingspeak.com/
62
功能
63
64
https://xively.com/
65
66
67
68
http://developer.xively.com/
69
http://developer.xively.com/api/
70
http://developer.xively.com/tutorials/
71
http://www.yeelink.net/
72
73
74
http://www.lewei50.com/home/index
75
76
下载地址:userfiles/app/lewei5020130116.apk
77
https://cayenne.mydevices.com/cayenne/login
78
MQTT (Message Queuing Telemetry Transport),它是為IBM和Eurotech共同
製定出來的protocol,在MQTT的官網可以看到它對MQTT的介紹:
MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity
protocol. It was designed as an extremely lightweight publish/subscribe
messaging transport.
所以它是為了IOT而設計的protocol,它是基於TCP/IP的協定,並且透過
publish/subscribe的方式做資料傳送與接收。
它的架構如下圖:
MQTT簡介
79
Publish/Subscribe:
在看MQTT之前,最好要先知道Publish/Subscribe的訊息傳送機
制為何,這樣之後在看其協定時,才會更快上手。
Publish/Subscribe有三種主要的組成元件,分別為Publisher、
Subscriber以及Topic。
Publisher為訊息的來源,它會將訊息發送給Topic,而
Subscriber向Topic註冊,表示他們想要接收此Topic的訊息;因
此當有某個Publisher對Topic發送訊息時,只要是有對此Topic
註冊的Subscriber,都會收到此則訊息。
它們的關係如下圖:
80
MQTT特性:
1. Publish/Subscribe的訊息傳送模式,來提供一對多的訊息分配。
2. 使用TCP/IP來提供基本的網路連結。
3. 三種訊息傳送服務的qualities: (QoS)
4. 由於他的header固定長度為2byte,因此可以減少封包傳送
時的額外負載,並減少所需的網路頻寬。
5. 當異常斷線發生時,會使用最後遺囑(Last Will and
Testament)的機制,通知各個感興趣的client。
0: "At most once",最多一次,訊息遺失或是重複發送的狀況可能會發生;
這種quality適合應用在環境感測,不在意資料是否會遺失,因為下一
次的資料取樣很快就會被published出來。
1: "At least once",至少一次,這種quality保證訊息會送達,只是可能會
發生重複發送訊息的狀況。
2:"Exactly once",確定一次,確認訊息只會送到一次。這種quality適合用
在計費系統,系統只要有重複收到資料、或是資料遺失狀況發生,就
會造成系統錯誤。
81
82
83
84
85
86
自建MQTT Server(Broker)介紹
QNAP NAS 讓您快速建立自己的 MQTT Server
https://www.qnap.com/zh-tw/
87
Docker 架構的 NAS ,Container Station 可自建更多 IoT Service
88
89
90
91
Container 列表
Blockly Blockly is a library for building visual programming editors.
Dashing Dashing is a Sinatra-based framework that lets you build beautiful dashboards.
Freeboard A Open Source Dashboard.
Intel Edison Intel® Edison technology is a hardware and software platform that, when
combined with sensors and your imagination, empowers you to invent new Internet-
enabled products and solutions.
Kafka Apache Kafka is a publish-subscribe messaging rethought as a distributed commit
log.
MariaDB MariaDB is a community-developed fork of the MySQL relational database
management system intended to remain free under the GNU GPL.
MongoDB MongoDB (from humongous) is a cross-platform document-oriented database.
Node-RED Node-RED is a tool for wiring together hardware devices, APIs and online
services in new and interesting ways.
Ponte Ponte allows you to publish and receive data using any protocol: HTTP, MQTT and
CoAP.
RabbitMQ Robust messaging for applications.
Redis Redis is a data structure server. It is open-source, networked, in-memory, and
stores keys with optional durability.
RPI The Raspberry Pi is a series of credit-card-sized, single-board computers developed in
the United Kingdom by the Raspberry Pi Foundation with the intent to promote the
teaching of basic computer science in schools and developing countries.
92
93
94
95
96
97
98
利用QNAP NAS Server 提供的Node-RED container 來接收以儀表板顯示數值及曲數
99
100
101
102
103
104

20170415- 智慧空調通訊系統實務_柯大