Blynk transfers binary messages with the following structure:
Command | Message Id | Length/Status | Body |
---|---|---|---|
1 byte | 2 bytes | 2 bytes | Variable |
Message Id and Length are big endian. Body has a command-specific format.
Command and Status definitions: BlynkProtocolDefs.h
Another protocol description can be found here.
Typical Blynk library knows how to send(S)/process(P):
S BLYNK_CMD_LOGIN + auth token
SP BLYNK_CMD_PING
SP BLYNK_CMD_RESPONSE
SP BLYNK_CMD_BRIDGE
SP BLYNK_CMD_HARDWARE
S BLYNK_CMD_TWEET
S BLYNK_CMD_EMAIL
S BLYNK_CMD_PUSH_NOTIFICATION
The body of these commands are encoded as a sequence of strings, separated by '\0'
(Null character). Please note that the last value may be not Null-terminated. In the following command examples \0
chars are replaced with spaces.
PinMode command is received by library after connection, or when a mobile application starts.
pm <pin> <mode>
pm <pin> <mode> <pin> <mode> <pin> <mode> ...
Mode:
- in - INPUT
- out - OUTPUT
- pu - INPUT_PULLUP
- pd - INPUT_PULLDOWN
Digital write:
dw <pin> <val>
Digital read:
dr <pin>
aw <pin> <val>
ar <pin>
vw <pin> <param0> <param1> <param2> <param3> ...
vr <pin>
info
TODO
- Values in HW commands are plain text.
- In response to
dr/ar
command, library should senddw/aw
command on the same pin and with the same message id. - These situations should cause a connection drop, or reconnection attempt:
- Message with
ID=0
is received - Message with unknown type is received
- Message with
4 entities should be created to add a new network interface to Blynk:
- Select connection interface that will be used for Blynk operation. This should be something like http://www.arduino.cc/en/Tutorial/WebClient Based on the API of the connection, create the Transport. Some examples may be found in the Adapters folder:
- BlynkTransportSerial
- BlynkTransportCC3000
- BlynkArduinoClient - can be reused, if possible
- Create Blynk representative class, which contains connection-specific helper functions (like begin). Examples:
- BlynkEthernet
- BlynkSerial
- BlynkCC3000
- BlynkWildFire
- BlynkYun
- Create BlynkSimple* header for your connection. This constructs main Blynk instance, so the user (mostly) doesn't need to get into such details. Examples:
- BlynkSimpleEthernet.h
- BlynkSimpleCC3000.h
- BlynkSimpleWifi.h
- BlynkSimpleUIPEthernet.h
- Create a simple example for your platform ;)
Use these to play with the protocol and understand the basics: