Ethernet 函式庫

86Duino 內建 10/100Mbps 的網路介面,不需使用 Arduino Ethernet Shield 即可連接網際網路。 86Duino 的網路介面透過本章介紹的 Ethernet 函式庫控制。
該 Ethernet 函式庫可以實做以下兩種功能,接收客戶端連線要求以及送出連線請求給伺服端。在 86Duino Coding 101 中,該函式庫最多同時支援 4 個連線(包含接收請求、送出請求及混合以上兩種);在之後的版本將把上限從 4 提高為 128。

Ethernet 類別

Ethernet 類別初始化 Ethernet 函式庫和網路設定。

begin()
localIP()
localMAC()
maintain()

IPAddress 類別

IPAddress 類別用以操作本地和遠端 IP 位址。

IPAddress()

Server 類別

Server 類別用以創建伺服端與客戶端連接,透過網路傳送與接收資料。

EthernetServer()
begin()
available()
write()
print()
println()

Client 類別

Client 類別用以創建客戶端與伺服端連接,透過網路傳送與接收資訊。

EthernetClient()
if (EthernetClient)
connected()
connect()
write()
print()
println()
available()
read()
flush()
stop()

EthernetUDP 類別

UDP 類別實作 UDP 協定建立連線,並傳送與接收資料。

begin()
read()
write()
beginPacket()
endPacket()
parsePacket()
available()
stop()
remoteIP()
remotePort()

範例

以下 Ethernet 函式庫的範例,是從 Arduino 課程而來。可以在 86Duino 上運行。(注意:以下範例在 86Duino 上運行時不需要 Arduino Ethernet Shield):

ChatServer:創建簡單的聊天伺服器。
WebClient:製作 HTTP 請求。
WebClientRepeating:重複製作 HTTP 請求。
WebServer:在 HTML 網頁上顯示類比感測器的值。
XivelyClient:連接到 Xively.com(免費的資料紀錄網站)。
XivelyClientString:傳送字串到 Xively.com。
BarometricPressureWebServer:在網頁上顯示氣壓感測器輸出的值。
UDPSendReceiveString:透過 UDP 傳送和接收文字訊息。
UdpNtpClient:過 UDP 送出 NTP 請求。
DnsWebClient:DNS 和 DHCP 為基礎的 Web 的客戶端
DhcpChatServer:簡單的 DHCP 聊天伺服器。
DhcpAddressPrinter:透過 DHCP 取得 IP 位址,並且印出 IP 位址。
TelnetClient:簡單的 Telnet 客戶端。

Hack

我們使用 Software Systems 的 SwsSock 函式庫實作 86Duino 的 Ethernet 函式庫。如果想要在 86Duino 上直接使用 SwsSock ,可以參考 SwsSock 的官網取得相關資訊。


函式庫參考主頁面

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.