如何透過 MCS switch 頻道點燈
- 首先請至 MCS 創建好一個內有 switch (control datachannel) 的 test device.
- 請參考這個 創建好 ml 專案
- 到您創建好的 ml 專案根目錄下:
npm install ml-mcs --save
npm install ml-wifi --save
npm install ml-gpio --save
- 至 featureConfig.json 添加:
{
"ml-mcs": true,
"ml-wifi": true,
"ml-gpio": true
}
- 範例程式碼:
__pinmux(35, 8);
var receiveChannel = 'switch';
var deviceId = 'Input your deviceId';
var deviceKey = 'Input your deviceKey';
var topic = 'mcs/' + deviceId + '/' + deviceKey + '/';
__wifi({
mode: 'station',
auth: 'PSK_WPA2',
ssid: 'Input your ssid',
password: 'Input your password',
});
global.eventStatus.on(receiveChannel, function(data) {
var status = Number(data.split(',')[2].split('\u5965')[0]);
__gpioWrite(35, status);
});
global.eventStatus.on('wifiConnect', function() {
__mcs(
'mqtt.mcs.mediatek.com',
'1883',
topic + '+',
'mqtt-7687-client',
1,
function(data) {
global.eventStatus.emit(data.split(',')[1], data);
}
);
});