初台ラボ デジタルツインプロジェクト
今回はPlayCanvaでボタンを押すとNode-RED側にデータを送るのをやってみます。
button.jsの編集
button.jsを下記のようにします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | var Button = pc.createScript( 'button' ); // initialize code called once per entity Button.prototype.initialize = function () { // ボタンを押すアクション this .entity.button.on( "click" , this .onPress, this ); }; // update code called every frame Button.prototype.update = function (dt) { }; Button.prototype.onPress = function (dt) { let client = this .app.client; let topic = "mqtttest" ; let metric = "aaa" ; // Publishする client.publish(topic, metric); }; |
実行確認
ボタンを押すと、
MQTT inノードを通して、データを送ることができました。