物聯網應用系統 (三)

Page 1

物聯網系統整合應用 (三) IOT (Internet Of Things)


物聯網(IOT)系統整合應用 課程安排 Part 1, 物聯網系統架構介紹 實作: 各裝置硬體實體之熟悉, 以及Beaglebone WebServer基本操作

Part 2, 3 Arminno 軟硬體環境介紹及藍芽應用, 與ZigBee Coordinator 流程介紹 實作: Arminno 開發環境使用熟悉及 Arminno+ZigBee 程式說明

Part 3,4 Arduino 軟硬體及相關Ozone模組介紹, 及ZigBee End Devices 流程介紹 實作: Arminno 開發環境使用與ZigBee End, 以及其他感測器相關模組程 式練習

Part 5,6 Beaglebone WebServer 流程, 及 Phthon Script 程式 介紹 實作: 修改Beaglebone程式, 與其他Linux指令操作練習


課程主題 (Part 3)  Arminno + 藍芽應用實驗  ZigBee 通訊協定(Protocol)介紹  Arminno™ IOT 主程式流程解說 實作  手機藍芽操作  藍芽控制電子元件


Arminno + 藍芽模組 UART (Serial Port)

藍芽模組

Arminno GPIO UART1 設定

PB3 (Rx)  PB2 (Tx) 


藍芽模組操作步驟 Step1.手機先安裝app程式: Bluetooth remote control.apk

Step2.Arminno 端: 1. 接電源 (紅正,黑負) 2. 接訊號線 (PB2 <-> BT Rx; PB3 <-> BT Tx) 3. 執行 Keil上的藍芽程式 Step3.手機端: 1.打開app程式 2.掃描藍芽Connect Device (Scan) 3.Device名稱: HC-05 (20.13.xx.xx.xx.xx) 4.ID碼=1234


UART (Serial Port) 之設定 Arminno 上使用的指令 (參考"Arminno_v10.pdf") unsigned char State = SetUart1 (unsigned int Baudrate, unsigned char PIN, unsigned char OutputMode, unsigned char Parity, 127 unsigned char StopBit, unsigned char RxBufferTriggerLevel, unsigned char BitMode,); unsigned short State = GetUart1Data(void *Array, unsigned short Length);


BlueTooth 範例程式

#include "arminno.h" unsigned int Baudrate; unsigned char PIN, OutputMode, Parity, StopBit, RxBufferTriggerLevel, BitMode; unsigned char RxFifoLevel; char Buffer[32]; int main(void) { /*** 設定 Uart1 控制參數 ***/ Baudrate = 9600; // Baudrate PIN = 1; // 表示選擇 PB2, PB3為Uart1的接腳 OutputMode = 0; // Push Pull Parity = 0; // Parity=0 StopBit = 0; // Stop_Bit=0 RxBufferTriggerLevel = 1; // 緩衝Buffer為1byte BitMode = 0; // Parity檢查, LSB 輸出優先 /*** 設定 Uart1 參數 ***/ SetUart1(Baudrate,PIN, OutputMode, Parity, StopBit,RxBufferTriggerLevel,BitMode);

/*** 先將接收Buffer清空 ***/ ResetUart1RxFifo(); /*** 指定全部 PORTA 為輸出接腳 ***/ SetDirPort(PORTA,0);

/*** 先將LED全部熄滅 ***/ WritePort(PORTA,0x0000);


while(1) { *** 判斷是否接收到 Uart1 資料 ***/ GetUart1RxState(RxFifoLevel) ; if (RxFifoLevel > 0) { GetUart1Data(Buffer, RxFifoLevel); // Uart1 接收資料 switch (Buffer[0]) { // 接收了一個Byte資料,放在Buffer[0] /* 手機藍芽傳來"前"鍵 */ case 70: WritePort(PORTA,0x0000);//將LED全部熄滅 High (PA0); //點亮相對的 break; /* 手機藍芽傳來"後"鍵 */ case 66: WritePort(PORTA,0x0000);//將LED全部熄滅 High (PA1); //點亮相對的LED break; /* 手機藍芽傳來"右"鍵 */ case 82: WritePort(PORTA,0x0000);//將LED全部熄滅 High (PA2); //點亮相對的LED break; /* 手機藍芽傳來"左"鍵 */ case 76: WritePort(PORTA,0x0000);//將LED全部熄滅 High (PA3); //點亮相對的LED break; /* 手機藍芽傳來"X"鍵 */ case 83: WritePort(PORTA,0x0000);//將LED全部熄滅 break; default: break; }}}}


實作題目 習作目的 : 藉由手機上藍芽功能, 透過 Arminno上的藍芽模 組, 來控制 Arminno實驗板上的元件 (LED, Buzzer, 7-Seg Display)  用手機控制 Arminno 板的 LED  在 Arminno板上,用4顆LED分別顯示手機傳來的"前"," 後","左","右"按鍵  用手機控制 Arminno 板的 Buzzer (蜂鳴器) 在 Arminno板上,用手機傳來的"前","後","左","右" 按鍵放出不同音階


各位同學已經學到... 1. Arminno Uart 的使用

2. Arminno GPIO 的控制 (HIGH, WritePort )


物聯網系統架構示意圖(回顧...) WebServer (Beaglebone)

ZigBee Coordinator (Arminno)

ZigBee Protocol ZigBee End Devices (Ozone) + Sonar

ZigBee End Devices (Ozone) + Acc

ZigBee End Devices (Ozone) + Servo

ZigBee End Devices (Ozone) + MP3

ZigBee End Devices (Ozone) + Temp


系統流程 - Arminno + ZigBee

BeagleBone

感測器資料 (Sensor Data)

 

Arminno

控制指令 (Command)

Ozone

Ozone Ozone …


ZigBee 網路形態

 Only one coordinator in a network, and must to have one. Coordinator is in charge of distribute Short Address: 2 bytes address, which is used for zigbee networking.  Each one has it’s unique SA. For coordinator, it’s 0x00

0x00


ZigBee 網路連接規則  Router跟End device會在第一次啟動時尋找相同PAN ID及 Channel的Coordinator來加入,同一空間中若是有多個可能的選擇, 那 Router或 End-Devices會根據信號強度來選擇.

 在link成功時,每個device的Short Address(SA),都是唯一的, 在ZigBee的網路,溝通都是透過SA完成的.  Router/End deivce跟parent link 過後,會把Coordinator的 SA 記在自己的flash裏,之後如果斷電再啟動,會優先去找之前的 Coordinator,回復原來的連結 Coordinator也會記下連過 的End-Devices.


Arminno與ZigBee之間的通訊協定  Armninno  找出所有相同網路的 End-Devices, 並記錄 Short Address (于Arminno 程式中呼 叫 GetAccoList() )

Arminno 程式中將 ShortAddress與Type 作出對應, 以利後續 資料傳送

ZigBee Module 

 開機時, 自動尋找相同 的Pan ID, 與Channel

預先燒錄決定 Type,ID,Channel (即 決定Coordinator或 End-Device)

ZigBee Module 

Ozone

 Ozone程式於資料中 中回覆各End-Devices 的Type, 如 Sonar, Compass, MP3等


ZigBee 通訊協定格式內容 1. PanID 與 Channel Pan ID = FFFF (預訂值) Channel = 25 (預訂值)

2. 資料格式 SOP

CMD

LEN

DATA

FCS

SOP (Start of Packet) - 0xFE CMD (Command ID): This is a two byte field (MSByte transmitted first) LEN (Length): This one byte field is the number of bytes in the Data field Data:This is a field which varies in size according to the command FCS (Frame check sequence): This is a one byte computed as an XOR of all the bytes


常用的 ZigBee 通訊協定指令 CMD_SET_PAN_ID Command CMD 0x00F2

Len

Data(0x0000~0xFFFF)

CMD_SET_Channel Command CMD 0x00F3

Len(0x04)

Channel List

MSG_Send Command Command CMD 0x0043(P2P), 0x0042(Broadcast)

Len

Data

Assoc_List Command & Output CMD 0x0013 CMD 0x1013

Len 0x00 Len

Number of devices

(SA SA) (SA SA)…

Get Short Address Command & Output CMD 0x0005

Len 0x00

CMD 0x1005

02

Short address(HI LO)

參考 "Catcan ZigBee API.doc"


以 Get Accociate List 指令為例 舉例而言,Arminno由ZigBee Coordinator下達 "Get_Assoc_List"指令

>> FE 00 13 00 13 則將會由ZigBee End-Devices得到以下訊息 << FE 10 13 11 08 93 6D 15 89 2F 25 3C 1B F4 56 BD B2 5A E3 E7 71 D1

17 Bytes Length

8 EndDevices

Check-Sum

End-Device's Short Address


Arminno 程式解說 1. Main.cpp 2. ZigBee.cpp


ZigBee 程式內之函式呼叫流程 Main.cpp

ZigBee.cpp

 Main()

ProcessComman  d()

Initialization()

GetAssocList()

 

SendZigbeeData()

GetZigbeeData ()


各函式功能說明

End-Devices 資料結構建立

Coordinator 執行 Get Accociate List 指令取所有End-Devices SA

接收由ZigBee End-Devices (Ozone+感測器) 來的資料,並送至Web-Server 顯示

處理由Web-Server 來的使用者指令

呈以上步驟, 將使用者指令利用ZigBee送至EndDevices (Ozone+感測器)


Initial Uart0/Uart1

智慧感知資訊 分配控制器 程式架構圖

Wait 2 Second

Arminno + ZigBee 流程

Get Zigbee Association List Initial Timer Tm0

Uart 0 <-> WebSever Uart 1 <-> ZigBee EndDevices

No over 2 sec?

Reset Timer Tm0

Send command to end device & Receive Data from end device via Uart1 Merge Receive Data from end device

Last End device?

No Send Receive Data to Webserver via Uart0

Data from Web server via Uart0?

No Process Data


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.