0.0.4 • Published 7 years ago

ml-tcp v0.0.4

Weekly downloads
-
License
Apache2
Repository
-
Last release
7 years ago

ml-tcp

API

  • tcpClient
  __tcpClient(
    ip,         // string
    port,       // number
    callback,   // callback
  )

  __tcpServer(
    port,       // number
    callback,   // callback
  )

  __tcpSend(
    data,       // data
  )

Example

  __pinmux(35, 8);

  var receiveChannel = 'switch';
  var deviceId = 'DU8xrUWV';
  var deviceKey = 'nE1EFLIlm3TrZg79';

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

  __wifi({
    mode: 'station', // default is station
    auth: 'PSK_WPA2',
    ssid: 'mcs',
    password: 'mcs12345678',
  });

  global.eventStatus.on('tcpConnect', function() {
    __tcpSend('DU8xrUWV,nE1EFLIlm3TrZg79,0');

    setInterval(function() {
      __tcpSend('DU8xrUWV,nE1EFLIlm3TrZg79,0');
    }, 20000);
  });

  global.eventStatus.on('wifiConnect', function() {
    __tcpClient('54.254.183.59', 443, function(data) {
      print(data);
      var Data = data.split(',');
      //DU8xrUWV,nE1EFLIlm3TrZg79,1471930717800,switch,0

      if (Data[3] === receiveChannel) {
        __gpioWrite(35, Number(Data[4]));
      }
    });
  });
0.0.4

7 years ago

0.0.3

8 years ago

0.0.2

8 years ago