Github Repo C Header C source JS source
mongoose-os-libs/blynk mgos_blynk.h   api_blynk.js

This Mongoose OS library allows your device remote control via the Blynk platform. Device side logic could be implemented in either C/C++ or JavaScript.

Blynk is a platform with iOS and Android apps to control Arduino, Raspberry Pi and the likes over the Internet.

See example video at:

How to use this library

In your Mongoose OS app, edit mos.yml file and add a reference to this library. See an example blynk app that does that.

Device configuration

This library adds blynk configuration section to the device:

mos config-get blynk
  "enable": true,
  "server": ""

In order for your device to authenticate with Blynk cloud, either use Web UI to change the blynk.auth value, or in a terminal:

mos config-set blynk.auth=YOUR_BLYNK_AUTH_TOKEN

Blynk API.

This library supports only a subset of Blynk protocol - namely, virtual pin reading and virtual pin writing. That is enough to implement a very wide class of applications.


typedef void (*blynk_handler_t)(struct mg_connection *, const char *cmd,
                                int pin, int val, int id, void *user_data);

Blynk event handler signature.


void blynk_set_handler(blynk_handler_t func, void *user_data);

Set Blynk event handler.


void blynk_send(struct mg_connection *c, uint8_t type, uint16_t id,
                const void *data, uint16_t len);

Send data to the Blynk server. data, len holds a message to send.


void blynk_printf(struct mg_connection *c, uint8_t type, uint16_t id,
                  const char *fmt, ...);

Same as as blynk_send(), formats message using printf() semantics.


void blynk_virtual_write(struct mg_connection *c, int pin, float val, int id);

Send a virtual write command



Blynk.send(conn, type, msg, id)

Send raw message to Blynk server.

conn is a network connection which is passed to the handler registered with Blynk.setHandler. type is one of the following:

  • Blynk.TYPE_LOGIN
  • Blynk.TYPE_PING

msg is a string with the data to send. id is the internal blynk message id; if undefined it will be autogenerated.

Return value: none. Example:

// Send "virtual write" command manually: write "1" to pin "16"
Blynk.send(conn, Blynk.TYPE_HARDWARE, 'vw\x0016\x001');


Blynk.virtualWrite(conn, pin, val, id)

Write to the virtual pin. If id is undefined, it will be autogenerated. This is a helper function that uses Blynk.send(). Return value: none. Example:

// Send "virtual write" command: write "1" to pin "16"
Blynk.virtualWrite(conn, 16, 1);


Blynk.setHandler(handler, userdata)

Set handler for the virtual pin reads / writes.


Blynk.setHandler(function(conn, cmd, pin, val, id) {
  print(cmd, pin, val);
}, null);
edit this doc