Fork me on GitHub

Blynk integration for Mongoose OS

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

C API Reference mgos_blynk.h

#include "mgos_blynk.h"

See on GitHub: mgos_blynk.h, mgos_blynk.c

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.

enum blynk_msg_type {

Message types for blynk_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

bool mgos_blynk_init(void);

JAVASCRIPT API Reference api_blynk.js


Blynk.send(conn, type, msg)

Send raw message to Blynk server. If id is undefined, it will be autogenerated.

Blynk.virtualWrite(conn, pin, val)

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


Set handler for the virtual pin reads / writes.


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