# コラム 技術的な内容

LEDの制御はAdafruit NeoPixelを利用し、余っていたESP-WROOM-02のボードで行うことにしました。このボードは数行のプログラムとライブラリだけでWifiへの接続が行え、豊富なArduinoのライブラリが使用できることもあり、LEDの制御、MQTTのサブスクライブもかなり簡単に実装できます。

![図17 IoTデバイスの作成を容易にしたWifiモジュール](/files/-LLTL2v0U6shlXJuNiXg)

### !camcheckコマンドの実装

コマンドの実装はGoogle Compute Engine上にf1-microのNode-REDインスタンスを立てて、実況スレッドの最新のレスを12秒間隔で監視、コマンド条件にマッチするレスがあった場合はMQTTでSend(サーバーにデータを保存せずサブスクライバに転送のみ)を行うという簡単なものです。コマンドの書き込みから20秒以内で動作します。

![図18 使用したNode-REDのフロー](/files/-LLTN7ADjr-1G2znPanT)

当初はMilkCocoaをMQTTバックエンドとして利用していましたが原因不明の503 Service Unavailableが出るようになり、サービスのアップグレードも受付停止しているので類似サービスのCloudAMQP\[1]へ移行しました。

{% hint style="info" %}

#### \[1] CloudAMQP - RabbitMQ as a Service

<https://www.cloudamqp.com/plans.html>
{% endhint %}

プログラム上で詰まった場所は、Milkcocoaのドキュメントには`DataElement elem`と記載されているところが実際は`DataElement *elem`であること。\[2]

ESP-WROOM-02ではPROGMEMが使えないことで一部サンプルから書き直す必要があったことでした。\[3]

したらばの文字コードがeucjpだったことも手抜きプログラミングでは厄介なことでした。

{% hint style="warning" %}

#### \[2] Getting Started(Arduino, ESP8266, mbed)

#### [https://mlkcca.com/document/start-arduino.html](< https://mlkcca.com/document/start-arduino.html>)

{% endhint %}

{% hint style="warning" %}

#### \[3] mqtt.connect() throws Exception (3) rst cause:2, boot mode:(1,6) #68

[https://github.com/adafruit/Adafruit\_MQTT\_Library/issues/68](< https://github.com/adafruit/Adafruit_MQTT_Library/issues/68>)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://18a.casket.jpnkn.com/na.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
