Blynk IoT Platform

Yesterday I read an article about blink(1) which is essentially a USB connected and controlled RGB LED light. I got some ESP8266 and some WS2812 LEDs to do the same, and it even can connect via WiFi and the Internet. So that’ll what do on Sunday.

Somehow I arrived at Blynk which is a totally different thing, but they can be combined to make a LED light which is Internet connected and can be controlled via an API or the Blynk app. Neat!

Here’s the trivial Espruino code running on the ESP8266:

var Blynk = require('http://tiny.cc/blynk-js');

var SSID = 'MY_SSID';
var PASS = 'MY_PASSWORD_FOR_MY_SSID';
var AUTH = 'MY_BLYNK_AUTH_TOKEN_FOR_THIS_APP';

const np=require("neopixel");

var pixel=[0, 0, 0];

function updatePixel() {
  np.write(2, pixel);
}

function setLED(intensity) {
  pixel[0]=intensity;
  updatePixel();
}

function setRedBlink(count) {
  var time=0;
  for (var i=0 ; i<count; ++i) {
    setTimeout(()=>{pixel[1]=255; updatePixel();}, time);
    time += 200;
    setTimeout(()=>{pixel[1]=0; updatePixel();}, time);
    time += 200;
  }
}

function blynkInit() {
  var blynk = new Blynk.Blynk(AUTH);

  var v1 = new blynk.VirtualPin(1);
  var v2 = new blynk.VirtualPin(2);

  v1.on('write', function(param) {
    setLED(parseInt(param[0]));
  });
  v2.on('write', function(param) {
    setRedBlink(parseInt(param[0]));
  });

  blynk.on('connect', function() { console.log("Blynk ready."); });
  blynk.on('disconnect', function() { console.log("DISCONNECT"); });
}

function onInit() {
  blynkInit();
}

onInit();

and on the Blynk app side there’s 2 sliders: one for the intensity of the first (green) LED (virtual Pin 1), and one for how many times to blink the 2nd (red) LED (virtual Pin 2).

LED controlled by Blynk App

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create your website at WordPress.com
Get started
%d bloggers like this: