Amazon Dash Buttonをハックしてテスラ・モデルSを操作する



つい先日、日本でもAmazonのDash Buttonが利用できるようになりましたが、さっそくハックしたという記事が話題になっています。

Amazon Dash ButtonをただのIoTボタンとして使う - Qiita
Amazon Dash Buttonを(正しくない方向で)使ってみた - Qiita
難病を患う娘のために、父は「Amazon Dash Button」をハックした|WIRED.jp

サントリー天然水 Dash Button

サントリー天然水 Dash Button

ハックする時のライブラリとしてはこちらが多く利用されているようですね。
GitHub - hortinstein/node-dash-button: A small module to emit events when an Amazon Dash Button is pressed

いくつかある事例の中でも、個人的に一番面白いなー、と思ったのはこちら。

Dash buttonを押すと、外の気温に合わせて、ガレージのテスラ・モデルSのエアコンを操作するという内容。
LEDライトの「Philips Hue」も組み合わせて利用することで、家の中から寒いのか暖かいのかがわかるようにもなっています。

ソースコードはこちらから公開されています。Python と C++ で書かれています。
arpguy.zip - Google ドライブ

テスラの操作に関しては公式のAPIを利用すれば簡単に出来るんですね。
Tesla Model S JSON API · Apiary

例えば、エアコンの温度の変更であれば、下記のPOSTリクエストを送信すれば可能です。

/api/1/vehicles/vehicle_id/command/set_temps?driver_temp=driver_degC&passenger_temp=pass_degC

ref. http://docs.timdorr.apiary.io/#reference/vehicle-commands/set-temperature/set-temperature

今回公開されているソースでは tesla.py の中に下記のように記述されています。

def set_interior_temp(self, new_temp_f):
    new_temp_c = (new_temp_f - 32) * 5/9.0
    params = { 'vehicle_id': self.car_id, 'driver_temp': new_temp_c, 'passenger_temp': new_temp_c }
    self.post('/api/1/vehicles/%d/command/set_temps' % self.car_id, params)

肝心の Dash Button のハックの部分ですが、基本的にはボタンからのARPプローブ送信を検知して、それをフックにして何かの処理をするのだと理解しています。
(ARP プローブ:「送信者 IP アドレス」がすべて 0 の ARP 要求パケット)

その部分は ArpGuy.cpp に記述されており、pcap (packet capture) という、パケットアナライザのためのAPIが利用されています。
(参考:http://www.cgitest.net/memo/wiki.cgi?page=libpcap)

pcap_if_t * pDevice = getEthernetDevice();

pcap_if_t * getEthernetDevice() {
    pcap_if_t *alldevs;
    char errbuf[PCAP_ERRBUF_SIZE];

    if (pcap_findalldevs(&alldevs, errbuf) == -1) {
        fprintf(stderr, "Error in pcap_findalldevs: %s\n", errbuf);
	exit(1);
    }

    // Look for our handy hardcoded name:
    for (pcap_if_t * d = alldevs; d; d = d->next) {
        if (strstr(d->description, "Ethernet") != NULL) {
	    return d;
	 }
    }
	
    fprintf(stderr, "Never found Ethernet device - what up, Mike D?\n");
    exit(1);
}

pcap_findalldevs() で、システムから利用可能なネットワークデバイスリストを取得しています。
続いて、pcap_open_live() で、実際にネットワーク上を流れるパケットを取得するための、パケットキャプチャディスクリプタを作成しています。

pAdapter = pcap_open_live(pDevice->name, 65536, 1, 1000, errorBuffer);

そして、pcap_loop() で実際に監視をしています。

// All right, looks like we're going into the infinite loop now:
pcap_loop(pAdapter, 0, ourPacketHandler, NULL);

ourPacketHandler() の内部で呼び出される handleARPReceived() にて、GATORADE_BUTTON で定義した Dash Button のMACアドレスが一致しているかチェックしています。
この時、一致していたらテスラを操作するための処理を呼び出しています。

if (!_stricmp(pMAC, GATORADE_BUTTON)) {
    printf("Received ARP from Gatorade button\n");
    // Point to wherever your stuff is.
    system("python d:\\mike\\arpguy\\prepare_car.py");
    lastCommandReceived = GetTickCount();
}

なるほどー、こうして実行していくんですね。面白い。
Youtubeのコメントにもありますが、テスラを操作するためのIDは流出してしまうと大変なことになってしまうので、試す時にはお気をつけください。

Note: the CLIENT_ID and CLIENT_SECRET in the video (and source) are not specific to my car. They're freely available on the Internet, just Google one of those big e4a99... strings. I appreciate the warnings from people concerned about me accidentally leaking my car's info, but there's no risk here.

Amazonからはすでに、自由にプログラム可能なDIY版Dash ButtonとしてAWS IoTもリリースしているんですね。
aws.amazon.com

Dash Buttonを使って様々なハックが可能になるのはもちろんのこと、Dash Button本来の機能も、流通に与えるインパクトはとても大きいものなので、今後の可能性に期待が高まりますね。

http://www.24jmn.com/entry/2016/12/09/140000www.24jmn.com
https://twitter.com/bishop_ring/status/807219292911464450


私も先日Dash Buttonが届いたので、
さっそくハックした何かを作ってみようと思います。


ファブリーズ Dash Button

ファブリーズ Dash Button

ネスカフェ Dash Button

ネスカフェ Dash Button

Philips Hue(ヒュー) スターターセット v2   929001156101 【AmazonAlexa認定取得製品】

Philips Hue(ヒュー) スターターセット v2 929001156101 【AmazonAlexa認定取得製品】