MT3620開発ボードを有線イーサネット接続

久しぶりのAzure Sphere投稿です。

MT3620にはWi-Fi 2.4G/5Gが内蔵されているので、ネットワークにサクッと繋がるのですが、、、
展示会や勉強会でWi-Fi混雑していると、ネットワークに繋がらないことがあります。

展示物がただの置物になってしまうなんて、、、想像しただけでも怖いですよね。

そんなあなたに朗報が!

Azure Sphereの18.11で、Private Networkとして有線イーサネットが利用可能になり、
そして、19.05から、Wi-Fiの代わりに(Public Networkとして)有線イーサネットが利用可能になりました!!

Ethernet is now supported as an alternative to Wi-Fi for communicating with the Azure Sphere Security Service and your own services. The HTTPS and AzureIoT samples can now be run over Ethernet in addition to Wi-Fi. The Azure Sphere Samples repository on GitHub includes documentation on how to wire the supported MicroChip part, bring up the Ethernet interface, and connect to Azure IoT or your own web services.

原文

ハードウェア

当初は、マイクロチップ社のイーサネットコントローラを自分で結線する必要がありました。
時が経ち、現在はSeeed社からシールドが販売されています。

結線面倒なので、シールドを入手しました。

MT3620イーサネットシールド
f:id:matsujirushix:20190901140754p:plain

MT3620開発ボードに重ねると、こんな感じ。

f:id:matsujirushix:20190901141005p:plain

LED見にくくなった、、、は、まぁ良しとして、
A/Bボタンが押せなくなったのは開発時に辛いなぁ、と思うわけで。

念のため、Groveシールドが載せれるか確認したところ、これは大丈夫でした。
開発時にインプット必要だったら、Groveシールド+Grove-Buttonを追加して対処しましょう。

f:id:matsujirushix:20190901141205p:plain

ソフトウェア

念のため、デバイスOSのバージョンを確認。
Azure Sphere OS 19.07。

C:\>azsphere device show-ota-status
Your device is running Azure Sphere OS version 19.07.
The Azure Sphere Security Service is targeting this device with Azure Sphere OS version 19.07.
Your device has the expected version of the Azure Sphere OS: 19.07.
Command completed successfully in 00:00:03.3995705.

Wi-Fiは未設定状態。

C:\>azsphere device wifi list
No networks found.

有線イーサネットを有効にするプログラム、enc28j60-isu0-int5.imagepackageを生成します。

C:\>azsphere image package-board-config --preset lan-enc28j60-isu0-int5 --output enc28j60-isu0-int5.imagepackage

生成したenc28j60-isu0-int5.imagepackageを、サイドローディングでデバイスにインストールします。

C:\>azsphere device prep-debug
Getting device capability configuration for application development.
...
C:\>azsphere device sideload deploy --imagepackage enc28j60-isu0-int5.imagepackage
Deploying 'enc28j60-isu0-int5.imagepackage' to the attached device.
Image package 'enc28j60-isu0-int5.imagepackage' has been deployed to the attached device.
The device is rebooting.

アプリケーション

それでは、AzureSphereサンプルのHTTPS_Curl_Easyを動かして、実際に有線イーサネットで通信できるか確認してみましょう。

github.com

実行!!

Remote debugging from host 192.168.35.1
cURL easy interface based application starting.
This sample periodically attempts to download a webpage, using curl's 'easy' API.
Not doing download because network is not up.

Not doing download because network is not up.

通信できない模様orz
接続しているスイッチの状態を見ると、Linkのランプが点灯していません。

アプリケーションのコード上で、有線イーサネットを有効にしないといけないようです。

app_manifest.jsonCapabilities"NetworkConfig": trueを追加して、コードの最初の方に下記を追加します。

int err = Networking_SetInterfaceState("eth0", true);
if (err < 0) {
    Log_Debug("Error setting interface state %d\n", errno);
    return -1;
}

実行すると、無事、HTTPS_Curl_Easyが動いて、https://example.com/からページを取得することができました。

f:id:matsujirushix:20190910172742p:plain

わかったこと