如何透過 MCS 使用 PWM 頻道點燈(漸進式)

  • 首先請至 MCS 創建好一個內有 led (PWM control datachannel) 的 test device.
  • 請參考這個 創建好 ml 專案
  • 到您創建好的 ml 專案根目錄下:
    npm install ml-pwm --save
    npm install ml-mcs --save
    npm install ml-wifi --save
    
  • 至 featureConfig.json 添加:
    {
    "ml-pwm": true,
    "ml-mcs": true,
    "ml-wifi": true
    }
    
  • 範例程式碼:
__pinmux(31, 9);  // set pinmux
__pwmRegister(32, 4, 400000);  // registe pwm

var receiveChannel = 'PWM';
var deviceId = 'Input your deviceId';
var deviceKey = 'Input your deviceKey';

var topic = 'mcs/' + deviceId + '/' + deviceKey + '/';

__wifi({
  mode: 'station', // default is 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]);
  __pwmWrite(32, 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);
    }
  );
});

results matching ""

    No results matching ""