Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ubuntu で eclipse paho クライアントを使用しており、緯度、経度、タイムスタンプの情報を JSON 形式で MQTT ブローカーに送信しようとしています。それ、どうやったら出来るの?
この記事を見つけましたが、完全ではありません。
JSON オブジェクトを文字列として作成し、その文字列に対して getBytes() を呼び出して、メッセージのペイロードとして使用するバイト配列を取得するだけです。
MqttMessage message = new MqttMessage(); message.setPayload("{foo: bar, lat: 0.23443, long: 12.3453245}".getBytes()); client.publish("foo", message);