在 IOT 時代,如何將裝置所收集到的資訊傳送到雲端目前有許多方法可以做到,但過往透過 Hub 來處理裝置與雲之間的介接方式在 Google 所提倡的 Physical web 計劃下已漸漸被取代。
以下將說明進入 WOT (Web of thing) 第ㄧ步,如何將 mbed 裝置連上網路的方法。
準備工作
- 使用 Seeed Studio 設計與生產的 Arch Pro 開發板
- Arch pro 本身沒有 Wify 模組
- 使用 Arch pro + mbed shield 子板 (可以接有線網路)
- 使用 Arch pro + wifi shield (可以連無線網路)
連接有線網路-自定 IP 與 DHCP
- Step 1. 使用 EthernetInterface Library
先匯入 ARM mbed 提供的 EthernetInterface Library 後, 引入 EthernetInterface.h 標頭檔, 即可設定 Static IP 位址或使用 DHCP 進行網路組態。
- Step 2. 程式實作
#include "mbed.h"
#include "EthernetInterface.h"
int main(void) {
eth = new EthernetInterface;
// eth->init(); Use DHCP
eth->init("192.168.21.81",
"255.255.255.0",
"192.168.21.2" );
eth->connect() ;
printf("IP Address is %s\r\n", eth->getIPAddress());
}
連接無線網路熱點-自定 IP 與 DHCP
- Step 1. 使用 WiflyInterface Library
先匯入 ARM mbed 提供的 WiflyInterface Library 後, 引入WiflyInterface.h 標頭檔,即可設定 Static IP 位址或使用 DHCP 進行網路組態。
- Step 2. 程式實作
#include "mbed.h"
#include "WiflyInterface.h"
WiflyInterface wifly(p13, p14, p19, p26, "SSID", "password", WPA);
int main(void) {
wifly.init(); // Use DHCP
wifly.init("192.168.21.45",
"255.255.255.0",
"192.168.21.2");
while (!wifly.connect());
printf("IP Address is %s\r\n", eth->getIPAddress());
}