初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
/**
* @file BlynkParam.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkArduinoClient_h
#define BlynkArduinoClient_h
#include <BlynkApiArduino.h>
#include <Blynk/BlynkDebug.h>
#include <Client.h>
#if defined(ESP8266) && !defined(BLYNK_NO_YIELD)
#define YIELD_FIX() BLYNK_RUN_YIELD();
#else
#define YIELD_FIX()
#endif
template <typename Client>
class BlynkArduinoClientGen
{
public:
BlynkArduinoClientGen(Client& c)
: client(NULL), domain(NULL), port(0), isConn(false)
{
setClient(&c);
}
BlynkArduinoClientGen()
: client(NULL), domain(NULL), port(0), isConn(false)
{}
void setClient(Client* c) {
client = c;
client->setTimeout(BLYNK_TIMEOUT_MS);
}
void begin(IPAddress a, uint16_t p) {
domain = NULL;
port = p;
addr = a;
}
void begin(const char* d, uint16_t p) {
domain = d;
port = p;
}
bool connect() {
if (domain) {
BLYNK_LOG4(BLYNK_F("Connecting to "), domain, ':', port);
isConn = (1 == client->connect(domain, port));
return isConn;
} else { //if (uint32_t(addr) != 0) {
BLYNK_LOG_IP("Connecting to ", addr);
isConn = (1 == client->connect(addr, port));
return isConn;
}
return false;
}
void disconnect() { isConn = false; client->stop(); }
#ifdef BLYNK_ENC28J60_FIX
size_t read(void* buf, size_t len) {
while (client->available() < len) { BLYNK_RUN_YIELD(); }
return client->read((uint8_t*)buf, len);
}
#else
size_t read(void* buf, size_t len) {
size_t res = client->readBytes((char*)buf, len);
YIELD_FIX();
return res;
}
#endif
#ifdef BLYNK_RETRY_SEND
size_t write(const void* buf, size_t len) {
size_t sent = 0;
int retry = 0;
while (sent < len && ++retry < 10) {
size_t w = client->write((const uint8_t*)buf+sent, len-sent);
if (w != 0 && w != -1) {
sent += w;
} else {
BlynkDelay(50);
#if defined(BLYNK_DEBUG) && defined(BLYNK_PRINT)
BLYNK_PRINT_TIME();
BLYNK_PRINT.print(BLYNK_F("Retry "));
BLYNK_PRINT.print(retry);
BLYNK_PRINT.print(BLYNK_F(" send: "));
BLYNK_PRINT.print(sent);
BLYNK_PRINT.print('/');
BLYNK_PRINT.println(len);
#endif
}
}
return sent;
}
#else
size_t write(const void* buf, size_t len) {
YIELD_FIX();
size_t res = client->write((const uint8_t*)buf, len);
YIELD_FIX();
return res;
}
#endif
bool connected() { YIELD_FIX(); return isConn && client->connected(); }
int available() { YIELD_FIX(); return client->available(); }
protected:
Client* client;
IPAddress addr;
const char* domain;
uint16_t port;
bool isConn;
};
typedef BlynkArduinoClientGen<Client> BlynkArduinoClient;
#endif

View File

@@ -0,0 +1,96 @@
/**
* @file BlynkArduinoGSM.h
* @author Riccardo Rizzo
* @license This project is released under the MIT License (MIT)
* @date Dec 2018
* @brief
*
*/
#ifndef BlynkArduinoGSM_h
#define BlynkArduinoGSM_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "MKRGSM"
#endif
#ifndef BLYNK_HEARTBEAT
#define BLYNK_HEARTBEAT 60
#endif
#ifndef BLYNK_TIMEOUT_MS
#define BLYNK_TIMEOUT_MS 6000
#endif
#define BLYNK_SEND_ATOMIC
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <MKRGSM.h>
class BlynkSIM
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkSIM(BlynkArduinoClient& transp)
: Base(transp)
{}
bool connectNetwork(GSM& modem, GPRS& gprs, const char* pin ,const char* apn, const char* user, const char* pass)
{
BLYNK_LOG1(BLYNK_F("Modem init..."));
if (!modem.begin(pin)) {
BLYNK_FATAL(BLYNK_F("Cannot init"));
return false;
}
BLYNK_LOG3(BLYNK_F("Connecting to "), apn, BLYNK_F(" ..."));
if (!gprs.attachGPRS(apn, user, pass)) {
BLYNK_FATAL(BLYNK_F("Connect GPRS failed"));
return false;
}
BLYNK_LOG1(BLYNK_F("Connected to GPRS"));
return true;
}
void config(GSM& gsm,
GPRS& gprs,
GSMClient& gsmclient,
const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
modem = &gsm;
modemGPRS = &gprs;
this->conn.setClient(&gsmclient);
this->conn.begin(domain, port);
}
void begin(const char* auth,
GSM& gsm,
GPRS& gprs,
GSMClient& gsmclient,
const char* pin,
const char* apn,
const char* user,
const char* pass,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
config(gsm, gprs, gsmclient, auth, domain, port);
connectNetwork(gsm, gprs, pin, apn, user, pass);
while(this->connect() != true) {}
}
private:
GSM* modem;
GPRS* modemGPRS;
GSMClient* gsmclient;
};
#endif

View File

@@ -0,0 +1,93 @@
/**
* @file BlynkArduinoNB.h
* @author Riccardo Rizzo
* @license This project is released under the MIT License (MIT)
* @date Dec 2018
* @brief
*
*/
#ifndef BlynkArduinoNB_h
#define BlynkArduinoNB_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "MKRNB"
#endif
#ifndef BLYNK_HEARTBEAT
#define BLYNK_HEARTBEAT 60
#endif
#ifndef BLYNK_TIMEOUT_MS
#define BLYNK_TIMEOUT_MS 6000
#endif
#define BLYNK_SEND_ATOMIC
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <MKRNB.h>
class BlynkSIM
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkSIM(BlynkArduinoClient& transp)
: Base(transp)
{}
bool connectNetwork(NB& modem, GPRS& gprs, const char* pin)
{
BLYNK_LOG1(BLYNK_F("Modem init..."));
if (!modem.begin(pin)) {
BLYNK_FATAL(BLYNK_F("Cannot init"));
return false;
}
BLYNK_LOG3(BLYNK_F("Connecting to "),"", BLYNK_F(" ..."));
if (!gprs.attachGPRS()) {
BLYNK_FATAL(BLYNK_F("Connect GPRS failed"));
return false;
}
BLYNK_LOG1(BLYNK_F("Connected to GPRS"));
return true;
}
void config(NB& nb,
GPRS& gprs,
NBClient& nbclient,
const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
modem = &nb;
modemGPRS = &gprs;
this->conn.setClient(&nbclient);
this->conn.begin(domain, port);
}
void begin(const char* auth,
NB& nb,
GPRS& gprs,
NBClient& nbclient,
const char* pin,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
config(nb, gprs, nbclient, auth, domain, port);
connectNetwork(nb, gprs, pin);
while(this->connect() != true) {}
}
private:
NB* modem;
GPRS* modemGPRS;
NBClient* nbclient;
};
#endif

View File

@@ -0,0 +1,189 @@
#ifndef BlynkBLEPeripheralSerial_h
#define BlynkBLEPeripheralSerial_h
#include <BLEPeripheral.h>
class BLESerial : public BLEPeripheral, public Stream
{
public:
BLESerial(unsigned char req = BLE_DEFAULT_REQ, unsigned char rdy = BLE_DEFAULT_RDY, unsigned char rst = BLE_DEFAULT_RST);
void begin(...);
void poll();
void end();
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
virtual size_t write(uint8_t byte);
using Print::write;
virtual operator bool();
private:
unsigned long _flushed;
static BLESerial* _instance;
size_t _rxHead;
size_t _rxTail;
size_t _rxCount() const;
uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
size_t _txCount;
uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART");
BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)");
BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)");
void _received(const uint8_t* data, size_t size);
static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic);
};
// #define BLE_SERIAL_DEBUG
BLESerial* BLESerial::_instance = NULL;
inline
BLESerial::BLESerial(unsigned char req, unsigned char rdy, unsigned char rst) :
BLEPeripheral(req, rdy, rst)
{
this->_txCount = 0;
this->_rxHead = this->_rxTail = 0;
this->_flushed = 0;
BLESerial::_instance = this;
addAttribute(this->_uartService);
addAttribute(this->_uartNameDescriptor);
setAdvertisedServiceUuid(this->_uartService.uuid());
addAttribute(this->_rxCharacteristic);
addAttribute(this->_rxNameDescriptor);
this->_rxCharacteristic.setEventHandler(BLEWritten, BLESerial::_received);
addAttribute(this->_txCharacteristic);
addAttribute(this->_txNameDescriptor);
}
inline
void BLESerial::begin(...) {
BLEPeripheral::begin();
#ifdef BLE_SERIAL_DEBUG
Serial.println(F("BLESerial::begin()"));
#endif
}
inline
void BLESerial::poll() {
if (millis() < this->_flushed + 100) {
BLEPeripheral::poll();
} else {
flush();
}
}
inline
void BLESerial::end() {
this->_rxCharacteristic.setEventHandler(BLEWritten, NULL);
this->_rxHead = this->_rxTail = 0;
flush();
BLEPeripheral::disconnect();
}
inline
int BLESerial::available(void) {
BLEPeripheral::poll();
int retval = (this->_rxHead - this->_rxTail + sizeof(this->_rxBuffer)) % sizeof(this->_rxBuffer);
#ifdef BLE_SERIAL_DEBUG
Serial.print(F("BLESerial::available() = "));
Serial.println(retval);
#endif
return retval;
}
inline
int BLESerial::peek(void) {
BLEPeripheral::poll();
if (this->_rxTail == this->_rxHead) return -1;
uint8_t byte = this->_rxBuffer[ (this->_rxTail + 1) % sizeof(this->_rxBuffer)];
#ifdef BLE_SERIAL_DEBUG
Serial.print(F("BLESerial::peek() = "));
Serial.print((char) byte);
Serial.print(F(" 0x"));
Serial.println(byte, HEX);
#endif
return byte;
}
inline
int BLESerial::read(void) {
BLEPeripheral::poll();
if (this->_rxTail == this->_rxHead) return -1;
this->_rxTail = (this->_rxTail + 1) % sizeof(this->_rxBuffer);
uint8_t byte = this->_rxBuffer[this->_rxTail];
#ifdef BLE_SERIAL_DEBUG
Serial.print(F("BLESerial::read() = "));
Serial.print((char) byte);
Serial.print(F(" 0x"));
Serial.println(byte, HEX);
#endif
return byte;
}
inline
void BLESerial::flush(void) {
if (this->_txCount == 0) return;
this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount);
this->_flushed = millis();
this->_txCount = 0;
BLEPeripheral::poll();
#ifdef BLE_SERIAL_DEBUG
Serial.println(F("BLESerial::flush()"));
#endif
}
inline
size_t BLESerial::write(uint8_t byte) {
BLEPeripheral::poll();
if (this->_txCharacteristic.subscribed() == false) return 0;
this->_txBuffer[this->_txCount++] = byte;
if (this->_txCount == sizeof(this->_txBuffer)) flush();
#ifdef BLE_SERIAL_DEBUG
Serial.print(F("BLESerial::write("));
Serial.print((char) byte);
Serial.print(F(" 0x"));
Serial.print(byte, HEX);
Serial.println(F(") = 1"));
#endif
return 1;
}
inline
BLESerial::operator bool() {
bool retval = BLEPeripheral::connected();
#ifdef BLE_SERIAL_DEBUG
Serial.print(F("BLESerial::operator bool() = "));
Serial.println(retval);
#endif
return retval;
}
inline
void BLESerial::_received(const uint8_t* data, size_t size) {
for (int i = 0; i < size; i++) {
this->_rxHead = (this->_rxHead + 1) % sizeof(this->_rxBuffer);
this->_rxBuffer[this->_rxHead] = data[i];
}
#ifdef BLE_SERIAL_DEBUG
Serial.print(F("BLESerial::received("));
for (int i = 0; i < size; i++) Serial.print((char) data[i]);
Serial.println(F(")"));
#endif
}
inline
void BLESerial::_received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic) {
BLESerial::_instance->_received(rxCharacteristic.value(), rxCharacteristic.valueLength());
}
#endif

View File

@@ -0,0 +1,190 @@
/**
* @file BlynkCC3000.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*
*/
#ifndef BlynkCC3000_h
#define BlynkCC3000_h
#define BLYNK_INFO_CONNECTION "CC3000"
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adafruit_CC3000.h>
#include <utility/netapp.h>
class BlynkTransportCC3000
{
public:
BlynkTransportCC3000(Adafruit_CC3000& cc3000)
: cc3000(cc3000)
, host(NULL)
, addr(0)
, port(0)
{}
void begin(uint32_t a, uint16_t p) {
host = NULL;
port = p;
addr = a;
}
void begin(const char* h, uint16_t p) {
host = h;
port = p;
}
bool connect() {
if (host) {
BLYNK_LOG2(BLYNK_F("Looking for "), host);
while (addr == 0) {
if (!cc3000.getHostByName((char*)host, &addr)) {
BLYNK_LOG1(BLYNK_F("Couldn't locate server"));
BlynkDelay(500);
}
}
}
uint8_t* a = (uint8_t*)&addr;
BLYNK_LOG_IP_REV("Connecting to ", a);
client = cc3000.connectTCP(addr, port);
return client.connected();
}
void disconnect() { client.stop(); }
size_t read(void* buf, size_t len) {
return client.readBytes((char*)buf, len);
}
size_t write(const void* buf, size_t len) {
return client.write((const uint8_t*)buf, len);
}
bool connected() { return client.connected(); }
int available() { return client.available(); }
private:
Adafruit_CC3000& cc3000;
Adafruit_CC3000_Client client;
const char* host;
uint32_t addr;
uint16_t port;
};
class BlynkCC3000
: public BlynkProtocol<BlynkTransportCC3000>
{
typedef BlynkProtocol<BlynkTransportCC3000> Base;
public:
BlynkCC3000(Adafruit_CC3000& cc3000, BlynkTransportCC3000& transp)
: Base(transp), cc3000(cc3000)
{}
void connectWiFi(const char* ssid,
const char* pass,
uint8_t secmode)
{
if (!cc3000.begin())
{
BLYNK_FATAL("Couldn't begin()! Check your wiring?");
}
#if !defined(CC3000_TINY_DRIVER) && defined(BLYNK_DEBUG)
uint8_t major, minor;
if(!cc3000.getFirmwareVersion(&major, &minor))
{
if(major != 0x1 || minor < 0x13) {
BLYNK_LOG1(BLYNK_F("CC3000 upgrade needed?"));
}
}
#endif
// Remove socket inactivity timeout
/*unsigned long aucDHCP = 14400;
unsigned long aucARP = 3600;
unsigned long aucKeepalive = 30;
unsigned long aucInactivity = 0;
int iRet = netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity);
if (iRet != 0) {
BLYNK_FATAL("Cannot set netapp timeout!");
}*/
/*if (!cc3000.deleteProfiles())
{
BLYNK_FATAL("Fail deleting old profiles");
}*/
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
if (!cc3000.connectToAP(ssid, pass, secmode))
{
BLYNK_FATAL("Failed to connect to AP");
}
BLYNK_LOG1(BLYNK_F("Getting IP..."));
while (!cc3000.checkDHCP())
{
BlynkDelay(100);
}
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
BLYNK_FATAL("DHCP failed.");
}
#ifdef BLYNK_PRINT
uint8_t* addr = (uint8_t*)&ipAddress;
BLYNK_LOG_IP_REV("IP: ", addr);
addr = (uint8_t*)&gateway;
BLYNK_LOG_IP_REV("GW: ", addr);
addr = (uint8_t*)&dnsserv;
BLYNK_LOG_IP_REV("DNS: ", addr);
#endif
}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(cc3000.IP2U32(ip[0],ip[1],ip[2],ip[3]), port);
}
void begin( const char* auth,
const char* ssid,
const char* pass,
uint8_t secmode,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass, secmode);
config(auth, domain, port);
while(this->connect() != true) {}
}
void begin( const char* auth,
const char* ssid,
const char* pass,
uint8_t secmode,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass, secmode);
config(auth, ip, port);
while(this->connect() != true) {}
}
private:
Adafruit_CC3000& cc3000;
};
#endif

View File

@@ -0,0 +1,205 @@
/**
* @file BlynkEthernet.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkEthernet_h
#define BlynkEthernet_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "W5000"
#endif
#ifdef BLYNK_USE_SSL
#define BLYNK_SERVER_PORT BLYNK_DEFAULT_PORT_SSL
#else
#define BLYNK_SERVER_PORT BLYNK_DEFAULT_PORT
#endif
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
class BlynkEthernet
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkEthernet(BlynkArduinoClient& transp)
: Base(transp)
{}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_SERVER_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_SERVER_PORT)
{
Base::begin(auth);
this->conn.begin(ip, port);
}
// DHCP with domain
void begin( const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_SERVER_PORT,
const byte mac[] = NULL)
{
BLYNK_LOG1(BLYNK_F("Getting IP..."));
if (!Ethernet.begin(SelectMacAddress(auth, mac))) {
BLYNK_FATAL(BLYNK_F("DHCP Failed!"));
}
// give the Ethernet shield a second to initialize:
BlynkDelay(1000);
IPAddress myip = Ethernet.localIP();
BLYNK_LOG_IP("IP:", myip);
config(auth, domain, port);
while(this->connect() != true) {}
}
// Static IP with domain
void begin( const char* auth,
const char* domain,
uint16_t port,
IPAddress local,
IPAddress dns,
const byte mac[] = NULL)
{
BLYNK_LOG1(BLYNK_F("Using static IP"));
Ethernet.begin(SelectMacAddress(auth, mac), local, dns);
// give the Ethernet shield a second to initialize:
BlynkDelay(1000);
IPAddress myip = Ethernet.localIP();
BLYNK_LOG_IP("IP:", myip);
config(auth, domain, port);
while(this->connect() != true) {}
}
// Static IP with domain, gateway, etc
void begin( const char* auth,
const char* domain,
uint16_t port,
IPAddress local,
IPAddress dns,
IPAddress gateway,
IPAddress subnet,
const byte mac[] = NULL)
{
BLYNK_LOG1(BLYNK_F("Using static IP"));
Ethernet.begin(SelectMacAddress(auth, mac), local, dns, gateway, subnet);
// give the Ethernet shield a second to initialize:
BlynkDelay(1000);
IPAddress myip = Ethernet.localIP();
BLYNK_LOG_IP("IP:", myip);
config(auth, domain, port);
while(this->connect() != true) {}
}
// DHCP with server IP
void begin( const char* auth,
IPAddress addr,
uint16_t port = BLYNK_SERVER_PORT,
const byte mac[] = NULL)
{
BLYNK_LOG1(BLYNK_F("Getting IP..."));
if (!Ethernet.begin(SelectMacAddress(auth, mac))) {
BLYNK_FATAL(BLYNK_F("DHCP Failed!"));
}
// give the Ethernet shield a second to initialize:
BlynkDelay(1000);
IPAddress myip = Ethernet.localIP();
BLYNK_LOG_IP("IP:", myip);
config(auth, addr, port);
while(this->connect() != true) {}
}
// Static IP with server IP
void begin( const char* auth,
IPAddress addr,
uint16_t port,
IPAddress local,
const byte mac[] = NULL)
{
BLYNK_LOG1(BLYNK_F("Using static IP"));
Ethernet.begin(SelectMacAddress(auth, mac), local);
// give the Ethernet shield a second to initialize:
BlynkDelay(1000);
IPAddress myip = Ethernet.localIP();
BLYNK_LOG_IP("IP:", myip);
config(auth, addr, port);
while(this->connect() != true) {}
}
// Static IP with server IP, DNS, gateway, etc
void begin( const char* auth,
IPAddress addr,
uint16_t port,
IPAddress local,
IPAddress dns,
IPAddress gateway,
IPAddress subnet,
const byte mac[] = NULL)
{
BLYNK_LOG1(BLYNK_F("Using static IP"));
Ethernet.begin(SelectMacAddress(auth, mac), local, dns, gateway, subnet);
// give the Ethernet shield a second to initialize:
BlynkDelay(1000);
IPAddress myip = Ethernet.localIP();
BLYNK_LOG_IP("IP:", myip);
config(auth, addr, port);
while(this->connect() != true) {}
}
private:
byte* SelectMacAddress(const char* token, const byte mac[])
{
if (mac != NULL) {
return (byte*)mac;
}
macAddress[0] = 0xFE;
macAddress[1] = 0xED;
macAddress[2] = 0xBA;
macAddress[3] = 0xFE;
macAddress[4] = 0xFE;
macAddress[5] = 0xED;
int len = strlen(token);
int mac_index = 1;
for (int i=0; i<len; i++) {
macAddress[mac_index++] ^= token[i];
if (mac_index > 5) { mac_index = 1; }
}
/* BLYNK_LOG("MAC: %02X-%02X-%02X-%02X-%02X-%02X",
macAddress[0], macAddress[1],
macAddress[2], macAddress[3],
macAddress[4], macAddress[5]);
*/
return macAddress;
}
private:
byte macAddress[6];
};
#endif

View File

@@ -0,0 +1,122 @@
/**
* @file BlynkGsmClient.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Nov 2016
* @brief
*
*/
#ifndef BlynkGsmClient_h
#define BlynkGsmClient_h
#ifndef BLYNK_INFO_CONNECTION
#if defined(TINY_GSM_MODEM_SIM800)
#define BLYNK_INFO_CONNECTION "SIM800"
#elif defined(TINY_GSM_MODEM_SIM900)
#define BLYNK_INFO_CONNECTION "SIM900"
#elif defined(TINY_GSM_MODEM_UBLOX)
#define BLYNK_INFO_CONNECTION "UBLOX"
#elif defined(TINY_GSM_MODEM_BG96)
#define BLYNK_INFO_CONNECTION "BG96"
#elif defined(TINY_GSM_MODEM_A6)
#define BLYNK_INFO_CONNECTION "A6"
#elif defined(TINY_GSM_MODEM_A7)
#define BLYNK_INFO_CONNECTION "A7"
#elif defined(TINY_GSM_MODEM_M590)
#define BLYNK_INFO_CONNECTION "M590"
#elif defined(TINY_GSM_MODEM_XBEE)
#define BLYNK_INFO_CONNECTION "XBEE"
#else
#define BLYNK_INFO_CONNECTION "TinyGSM"
#endif
#endif
#ifndef BLYNK_HEARTBEAT
#define BLYNK_HEARTBEAT 60
#endif
#ifndef BLYNK_TIMEOUT_MS
#define BLYNK_TIMEOUT_MS 6000
#endif
#define BLYNK_SEND_ATOMIC
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <TinyGsmClient.h>
class BlynkSIM
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkSIM(BlynkArduinoClient& transp)
: Base(transp)
, modem(NULL)
{}
bool connectNetwork(const char* apn, const char* user, const char* pass)
{
BLYNK_LOG1(BLYNK_F("Modem init..."));
if (!modem->begin()) {
BLYNK_FATAL(BLYNK_F("Cannot init"));
}
switch (modem->getSimStatus()) {
case SIM_ERROR: BLYNK_FATAL(BLYNK_F("SIM is missing")); break;
case SIM_LOCKED: BLYNK_FATAL(BLYNK_F("SIM is PIN-locked")); break;
default: break;
}
BLYNK_LOG1(BLYNK_F("Connecting to network..."));
if (modem->waitForNetwork()) {
String op = modem->getOperator();
BLYNK_LOG2(BLYNK_F("Network: "), op);
} else {
BLYNK_FATAL(BLYNK_F("Register in network failed"));
}
BLYNK_LOG3(BLYNK_F("Connecting to "), apn, BLYNK_F(" ..."));
if (!modem->gprsConnect(apn, user, pass)) {
BLYNK_FATAL(BLYNK_F("Connect GPRS failed"));
return false;
}
BLYNK_LOG1(BLYNK_F("Connected to GPRS"));
return true;
}
void config(TinyGsm& gsm,
const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
modem = &gsm;
client.init(modem);
this->conn.setClient(&client);
this->conn.begin(domain, port);
}
void begin(const char* auth,
TinyGsm& gsm,
const char* apn,
const char* user,
const char* pass,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
config(gsm, auth, domain, port);
connectNetwork(apn, user, pass);
while(this->connect() != true) {}
}
private:
TinyGsm* modem;
TinyGsmClient client;
};
#endif

View File

@@ -0,0 +1,96 @@
/**
* @file BlynkSerial.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkStream_h
#define BlynkStream_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "Serial"
#endif
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
class BlynkTransportStream
{
public:
BlynkTransportStream()
: stream(NULL), conn(0)
{}
// IP redirect not available
void begin(char BLYNK_UNUSED *h, uint16_t BLYNK_UNUSED p) {}
void begin(Stream& s) {
stream = &s;
}
bool connect() {
BLYNK_LOG1(BLYNK_F("Connecting..."));
stream->flush();
return conn = true;
}
void disconnect() { conn = false; }
size_t read(void* buf, size_t len) {
char* beg = (char*)buf;
char* end = beg + len;
millis_time_t startMillis = BlynkMillis();
while ((beg < end) && (BlynkMillis() - startMillis < BLYNK_TIMEOUT_MS)) {
int c = stream->read();
if (c < 0)
continue;
*beg++ = (char)c;
}
return beg-(char*)buf;
}
size_t write(const void* buf, size_t len) {
stream->write((const uint8_t*)buf, len);
return len;
}
bool connected() { return conn; }
int available() { return stream->available(); }
protected:
Stream* stream;
bool conn;
};
class BlynkStream
: public BlynkProtocol<BlynkTransportStream>
{
typedef BlynkProtocol<BlynkTransportStream> Base;
public:
BlynkStream(BlynkTransportStream& transp)
: Base(transp)
{}
void config(Stream& stream,
const char* auth)
{
Base::begin(auth);
this->conn.begin(stream);
}
void begin(Stream& stream, const char* auth) {
config(stream, auth);
while(this->connect() != true) {}
}
// Please use Blynk.begin(Stream, "auth")
BLYNK_DEPRECATED
void begin(const char* auth, Stream& stream) {
config(stream, auth);
while(this->connect() != true) {}
}
};
#endif

View File

@@ -0,0 +1,111 @@
/**
* @file BlynkWiFiCommon.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkWiFiCommon_h
#define BlynkWiFiCommon_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "WiFi"
#endif
#ifdef BLYNK_USE_SSL
#define BLYNK_SERVER_PORT BLYNK_DEFAULT_PORT_SSL
#else
#define BLYNK_SERVER_PORT BLYNK_DEFAULT_PORT
#endif
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
class BlynkWifiCommon
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkWifiCommon(BlynkArduinoClient& transp)
: Base(transp)
{}
void connectWiFi(const char* ssid, const char* pass)
{
int status = WiFi.status();
// check for the presence of the shield:
if (status == WL_NO_SHIELD) {
BLYNK_FATAL("WiFi module not found");
}
#ifdef BLYNK_DEBUG
BLYNK_LOG2(BLYNK_F("WiFi firmware: "), WiFi.firmwareVersion());
#endif
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
if (pass && strlen(pass)) {
status = WiFi.begin((char*)ssid, (char*)pass);
} else {
status = WiFi.begin((char*)ssid);
}
millis_time_t started = BlynkMillis();
while ((status != WL_CONNECTED) &&
(BlynkMillis() - started < 10000))
{
BlynkDelay(100);
status = WiFi.status();
}
}
IPAddress myip = WiFi.localIP();
BLYNK_LOG_IP("IP: ", myip);
}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_SERVER_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_SERVER_PORT)
{
Base::begin(auth);
this->conn.begin(ip, port);
}
void begin(const char* auth,
const char* ssid,
const char* pass,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_SERVER_PORT)
{
connectWiFi(ssid, pass);
config(auth, domain, port);
while(this->connect() != true) {}
}
void begin(const char* auth,
const char* ssid,
const char* pass,
IPAddress ip,
uint16_t port = BLYNK_SERVER_PORT)
{
connectWiFi(ssid, pass);
config(auth, ip, port);
while(this->connect() != true) {}
}
};
#endif

View File

@@ -0,0 +1,120 @@
/**
* @file BlynkWiFly.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkWiFly_h
#define BlynkWiFly_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "RN-XV"
#endif
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <WiFlyHQ.h>
class BlynkTransportWiFly
{
public:
BlynkTransportWiFly()
: wifly(NULL)
, domain(NULL)
, port(0)
{}
void setWiFly(WiFly* rnxv) {
wifly = rnxv;
}
void begin(const char* h, uint16_t p) {
domain = h;
port = p;
}
bool connect() {
return wifly->open(domain, port);
}
void disconnect() { wifly->close(); }
size_t read(void* buf, size_t len) {
return wifly->readBytes((char*)buf, len);
}
size_t write(const void* buf, size_t len) {
wifly->write((const uint8_t*)buf, len);
return len;
}
bool connected() { return wifly->isConnected(); }
int available() { return wifly->available(); }
private:
WiFly* wifly;
const char* domain;
uint16_t port;
};
class BlynkWiFly
: public BlynkProtocol<BlynkTransportWiFly>
{
typedef BlynkProtocol<BlynkTransportWiFly> Base;
public:
BlynkWiFly(BlynkTransportWiFly& transp)
: Base(transp)
, wifly(NULL)
{}
void connectWiFi(const char* ssid, const char* pass) {
if (!wifly->isAssociated()) {
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
wifly->setSSID(ssid);
if (pass && strlen(pass)) {
wifly->setPassphrase(pass);
}
wifly->enableDHCP();
if (!wifly->join()) {
BLYNK_FATAL("Failed.");
}
} else {
BLYNK_LOG1(BLYNK_F("Already connected to WiFi"));
}
if (wifly->isConnected()) {
wifly->close();
}
wifly->setIpFlags(1 << 1);
}
void config(WiFly& rnxv,
const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
wifly = &rnxv;
this->conn.setWiFly(wifly);
this->conn.begin(domain, port);
}
void begin( const char* auth,
WiFly& rnxv,
const char* ssid,
const char* pass,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
wifly = &rnxv;
connectWiFi(ssid, pass);
config(rnxv, auth, domain, port);
while(this->connect() != true) {}
}
private:
WiFly* wifly;
};
#endif

View File

@@ -0,0 +1,203 @@
/**
* @file BlynkWildFire.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*
*/
#ifndef BlynkWildFire_h
#define BlynkWildFire_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "CC3000"
#endif
#define BLYNK_SEND_ATOMIC
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <IPAddress.h>
#include <WildFire_CC3000.h>
#include <utility/netapp.h>
class BlynkTransportWildFire
{
public:
BlynkTransportWildFire(WildFire_CC3000& cc3000)
: cc3000(cc3000)
, host(NULL)
, addr(0)
, port(0)
{}
void begin(uint32_t a, uint16_t p) {
host = NULL;
port = p;
addr = a;
}
void begin(const char* h, uint16_t p) {
host = h;
port = p;
}
bool connect() {
if (host) {
BLYNK_LOG2(BLYNK_F("Looking for "), host);
while (addr == 0) {
if (!cc3000.getHostByName((char*)host, &addr)) {
BLYNK_LOG1(BLYNK_F("Couldn't locate server"));
BlynkDelay(500);
}
}
}
uint8_t* a = (uint8_t*)&addr;
BLYNK_LOG_IP_REV("Connecting to ", a);
client = cc3000.connectTCP(addr, port);
return client.connected();
}
void disconnect() { client.close(); }
size_t read(void* buf, size_t len) {
char* beg = (char*)buf;
char* end = beg + len;
while (beg < end) {
int c = client.read();
if (c < 0)
break;
*beg++ = (char)c;
}
return len;
}
size_t write(const void* buf, size_t len) {
return client.write((const uint8_t*)buf, len);
}
bool connected() { return client.connected(); }
int available() { return client.available(); }
private:
WildFire_CC3000& cc3000;
WildFire_CC3000_Client client;
const char* host;
uint32_t addr;
uint16_t port;
};
class BlynkWildFire
: public BlynkProtocol<BlynkTransportWildFire>
{
typedef BlynkProtocol<BlynkTransportWildFire> Base;
public:
BlynkWildFire(WildFire_CC3000& cc3000, BlynkTransportWildFire& transp)
: Base(transp), cc3000(cc3000)
{}
void connectWiFi(const char* ssid,
const char* pass,
uint8_t secmode)
{
if (!cc3000.begin())
{
BLYNK_FATAL("Couldn't begin()! Check your wiring?");
}
#if !defined(CC3000_TINY_DRIVER) && defined(BLYNK_DEBUG)
uint8_t major, minor;
if(!cc3000.getFirmwareVersion(&major, &minor))
{
if(major != 0x1 || minor < 0x13) {
BLYNK_LOG1(BLYNK_F("CC3000 upgrade needed?"));
}
}
#endif
// Remove socket inactivity timeout
/*unsigned long aucDHCP = 14400;
unsigned long aucARP = 3600;
unsigned long aucKeepalive = 30;
unsigned long aucInactivity = 0;
int iRet = netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity);
if (iRet != 0) {
BLYNK_FATAL("Cannot set netapp timeout!");
}*/
/*if (!cc3000.deleteProfiles())
{
BLYNK_FATAL("Fail deleting old profiles");
}*/
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
if (!cc3000.connectToAP(ssid, pass, secmode))
{
BLYNK_FATAL("Failed to connect to AP");
}
BLYNK_LOG1(BLYNK_F("Getting IP..."));
while (!cc3000.checkDHCP())
{
BlynkDelay(100);
}
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
BLYNK_FATAL("DHCP failed.");
}
#ifdef BLYNK_PRINT
uint8_t* addr = (uint8_t*)&ipAddress;
BLYNK_LOG_IP_REV("IP: ", addr);
addr = (uint8_t*)&gateway;
BLYNK_LOG_IP_REV("GW: ", addr);
addr = (uint8_t*)&dnsserv;
BLYNK_LOG_IP_REV("DNS: ", addr);
#endif
}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(cc3000.IP2U32(ip[0],ip[1],ip[2],ip[3]), port);
}
void begin( const char* auth,
const char* ssid,
const char* pass,
uint8_t secmode,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass, secmode);
config(auth, domain, port);
while(this->connect() != true) {}
}
void begin( const char* auth,
const char* ssid,
const char* pass,
uint8_t secmode,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass, secmode);
config(auth, ip, port);
while(this->connect() != true) {}
}
private:
WildFire_CC3000& cc3000;
};
#endif

View File

@@ -0,0 +1,17 @@
/**
* @file Blynk.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Nov 2016
* @brief
*
*/
#ifndef Blynk_h
#define Blynk_h
#include <Blynk/BlynkApi.h>
#warning "Please include a board-specific header file, instead of Blynk.h (see examples)"
#endif

View File

@@ -0,0 +1,321 @@
/**
* @file BlynkApi.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief High-level functions
*
*/
#ifndef BlynkApi_h
#define BlynkApi_h
#include <Blynk/BlynkConfig.h>
#include <Blynk/BlynkDebug.h>
#include <Blynk/BlynkParam.h>
#include <Blynk/BlynkTimer.h>
#include <Blynk/BlynkHandlers.h>
#include <Blynk/BlynkProtocolDefs.h>
#if defined(BLYNK_EXPERIMENTAL)
#include <Blynk/BlynkEveryN.h>
#endif
/**
* Represents high-level functions of Blynk
*/
template <class Proto>
class BlynkApi
{
public:
BlynkApi() {
}
#ifdef DOXYGEN // These API here are only for the documentation
/**
* Connects to the server.
* Blocks until connected or timeout happens.
* May take less or more then timeout value.
*
* @param timeout Connection timeout
* @returns True if connected to the server
*/
bool connect(unsigned long timeout = BLYNK_TIMEOUT_MS*3);
/**
* Disconnects from the server.
* It will not try to reconnect, until connect() is called
*/
void disconnect();
/**
* @returns True if connected to the server
*/
bool connected();
/**
* Performs Blynk-related housekeeping
* and processes incoming commands
*
* @param available True if there is incoming data to process
* Only used when user manages connection manually.
*/
bool run(bool available = false);
#endif // DOXYGEN
/**
* Sends value to a Virtual Pin
*
* @param pin Virtual Pin number
* @param data Value to be sent
*/
template <typename... Args>
void virtualWrite(int pin, Args... values) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add("vw");
cmd.add(pin);
cmd.add_multi(values...);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
/**
* Sends buffer to a Virtual Pin
*
* @param pin Virtual Pin number
* @param buff Data buffer
* @param len Length of data
*/
void virtualWriteBinary(int pin, const void* buff, size_t len) {
char mem[8];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add("vw");
cmd.add(pin);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength(), buff, len);
}
/**
* Sends BlynkParam to a Virtual Pin
*
* @param pin Virtual Pin number
* @param param
*/
void virtualWrite(int pin, const BlynkParam& param) {
virtualWriteBinary(pin, param.getBuffer(), param.getLength());
}
void virtualWrite(int pin, const BlynkParamAllocated& param) {
virtualWriteBinary(pin, param.getBuffer(), param.getLength());
}
/**
* Requests Server to re-send current values for all widgets.
*/
void syncAll() {
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE_SYNC);
}
/**
* Sends internal command
*/
template <typename... Args>
void sendInternal(Args... params) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add_multi(params...);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_INTERNAL, 0, cmd.getBuffer(), cmd.getLength()-1);
}
/**
* Requests App or Server to re-send current value of a Virtual Pin.
* This will probably cause user-defined BLYNK_WRITE handler to be called.
*
* @param pin Virtual Pin number
*/
template <typename... Args>
void syncVirtual(Args... pins) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add("vr");
cmd.add_multi(pins...);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE_SYNC, 0, cmd.getBuffer(), cmd.getLength()-1);
}
/**
* Tweets a message
*
* @param msg Text of the message
*/
template<typename T>
void tweet(const T& msg) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(msg);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_TWEET, 0, cmd.getBuffer(), cmd.getLength()-1);
}
/**
* Sends a push notification to the App
*
* @param msg Text of the message
*/
template<typename T>
void notify(const T& msg) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(msg);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_NOTIFY, 0, cmd.getBuffer(), cmd.getLength()-1);
}
/**
* Sends an SMS
*
* @param msg Text of the message
*/
template<typename T>
void sms(const T& msg) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(msg);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_SMS, 0, cmd.getBuffer(), cmd.getLength()-1);
}
/**
* Sends an email message
*
* @param email Email to send to
* @param subject Subject of message
* @param msg Text of the message
*/
template <typename T1, typename T2>
void email(const char* email, const T1& subject, const T2& msg) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(email);
cmd.add(subject);
cmd.add(msg);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_EMAIL, 0, cmd.getBuffer(), cmd.getLength()-1);
}
/**
* Sends an email message
*
* @param subject Subject of message
* @param msg Text of the message
*/
template <typename T1, typename T2>
void email(const T1& subject, const T2& msg) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(subject);
cmd.add(msg);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_EMAIL, 0, cmd.getBuffer(), cmd.getLength()-1);
}
/**
* Sets property of a Widget
*
* @experimental
*
* @param pin Virtual Pin number
* @param property Property name ("label", "labels", "color", ...)
* @param value Property value
*/
template <typename T, typename... Args>
void setProperty(int pin, const T& property, Args... values) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(pin);
cmd.add(property);
cmd.add_multi(values...);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_PROPERTY, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename T>
void setProperty(int pin, const T& property, const BlynkParam& param) {
char mem[32];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(pin);
cmd.add(property);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_PROPERTY, 0, cmd.getBuffer(), cmd.getLength(), param.getBuffer(), param.getLength());
}
template <typename T>
void setProperty(int pin, const T& property, const BlynkParamAllocated& param) {
char mem[32];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(pin);
cmd.add(property);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_PROPERTY, 0, cmd.getBuffer(), cmd.getLength(), param.getBuffer(), param.getLength());
}
template <typename NAME>
void logEvent(const NAME& event_name) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(event_name);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_EVENT_LOG, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename NAME, typename DESCR>
void logEvent(const NAME& event_name, const DESCR& description) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(event_name);
cmd.add(description);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_EVENT_LOG, 0, cmd.getBuffer(), cmd.getLength()-1);
}
#if defined(BLYNK_EXPERIMENTAL)
// Attention!
// Every function in this section may be changed, removed or renamed.
/**
* Refreshes value of a widget by running
* user-defined BLYNK_READ handler of a pin.
*
* @experimental
*
* @param pin Virtual Pin number
*/
void refresh(int pin) {
if (WidgetReadHandler handler = GetReadHandler(pin)) {
BlynkReq req = { 0, BLYNK_SUCCESS, (uint8_t)pin };
handler(req);
}
}
/**
* Delays for N milliseconds, handling server communication in background.
*
* @experimental
* @warning Should be used very carefully, especially on platforms with small RAM.
*
* @param ms Milliseconds to wait
*/
void delay(unsigned long ms) {
uint16_t start = (uint16_t)micros();
while (ms > 0) {
static_cast<Proto*>(this)->run();
#if !defined(BLYNK_NO_YIELD)
yield();
#endif
if (((uint16_t)micros() - start) >= 1000) {
ms--;
start += 1000;
}
}
}
#endif
protected:
void processCmd(const void* buff, size_t len);
void sendInfo();
};
#endif

View File

@@ -0,0 +1,95 @@
/**
* @file BlynkConfig.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief Configuration of different aspects of library
*
*/
#ifndef BlynkConfig_h
#define BlynkConfig_h
#include <Blynk/BlynkDetectDevice.h>
/***************************************************
* Change these settings to match your need
***************************************************/
#define BLYNK_DEFAULT_DOMAIN "blynk-cloud.com"
#define BLYNK_DEFAULT_PORT 80
#define BLYNK_DEFAULT_PORT_SSL 443
/***************************************************
* Professional settings
***************************************************/
// Library version.
#define BLYNK_VERSION "0.6.1"
// Heartbeat period in seconds.
#ifndef BLYNK_HEARTBEAT
#define BLYNK_HEARTBEAT 10
#endif
// Network timeout in milliseconds.
#ifndef BLYNK_TIMEOUT_MS
#define BLYNK_TIMEOUT_MS 3000UL
#endif
// Limit the amount of outgoing commands per second.
#ifndef BLYNK_MSG_LIMIT
#define BLYNK_MSG_LIMIT 15
#endif
// Limit the incoming command length.
#ifndef BLYNK_MAX_READBYTES
#define BLYNK_MAX_READBYTES 256
#endif
// Limit the outgoing command length.
#ifndef BLYNK_MAX_SENDBYTES
#define BLYNK_MAX_SENDBYTES 128
#endif
// Uncomment to use Let's Encrypt Root CA
//#define BLYNK_SSL_USE_LETSENCRYPT
// Uncomment to disable built-in analog and digital operations.
//#define BLYNK_NO_BUILTIN
// Uncomment to disable providing info about device to the server.
//#define BLYNK_NO_INFO
// Uncomment to enable debug prints.
//#define BLYNK_DEBUG
// Uncomment to force-enable 128 virtual pins
//#define BLYNK_USE_128_VPINS
// Uncomment to disable fancy logo
//#define BLYNK_NO_FANCY_LOGO
// Uncomment to enable 3D fancy logo
//#define BLYNK_FANCY_LOGO_3D
// Uncomment to enable experimental functions.
//#define BLYNK_EXPERIMENTAL
// Uncomment to disable all float/double usage
//#define BLYNK_NO_FLOAT
// Uncomment to switch to direct-connect mode
//#define BLYNK_USE_DIRECT_CONNECT
// Uncomment to append command body to header (uses more RAM)
//#define BLYNK_SEND_ATOMIC
// Split whole command into chunks (in bytes)
//#define BLYNK_SEND_CHUNK 64
// Wait after sending each chunk (in milliseconds)
//#define BLYNK_SEND_THROTTLE 10
#endif

View File

@@ -0,0 +1,305 @@
/**
* @file BlynkDebug.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief Debug utilities
*
*/
#ifndef BlynkDebug_h
#define BlynkDebug_h
#include <Blynk/BlynkConfig.h>
#include <stddef.h>
#ifdef ESP8266
extern "C" {
#include "ets_sys.h"
#include "os_type.h"
#include "mem.h"
}
#else
#include <inttypes.h>
#endif
#if defined(ARDUINO_ARCH_ARC32)
typedef uint64_t millis_time_t;
#else
typedef uint32_t millis_time_t;
#endif
void BlynkDelay(millis_time_t ms);
millis_time_t BlynkMillis();
size_t BlynkFreeRam();
void BlynkReset() BLYNK_NORETURN;
void BlynkFatal() BLYNK_NORETURN;
#if defined(SPARK) || defined(PARTICLE)
#include "application.h"
#endif
#if defined(ARDUINO)
#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#endif
#if defined(LINUX)
#if defined(RASPBERRY)
#include <wiringPi.h>
#endif
#endif
#if !defined(BLYNK_RUN_YIELD)
#if defined(BLYNK_NO_YIELD)
#define BLYNK_RUN_YIELD() {}
#elif defined(SPARK) || defined(PARTICLE)
#define BLYNK_RUN_YIELD() { Particle.process(); }
#elif !defined(ARDUINO) || (ARDUINO < 151)
#define BLYNK_RUN_YIELD() {}
#else
#define BLYNK_RUN_YIELD() { BlynkDelay(0); }
#endif
#endif
#if defined(__AVR__)
#include <avr/pgmspace.h>
#define BLYNK_HAS_PROGMEM
#define BLYNK_PROGMEM PROGMEM
#define BLYNK_F(s) F(s)
#define BLYNK_PSTR(s) PSTR(s)
#else
#define BLYNK_PROGMEM
#define BLYNK_F(s) s
#define BLYNK_PSTR(s) s
#endif
#ifdef ARDUINO_AVR_DIGISPARK
typedef fstr_t __FlashStringHelper;
#endif
#if defined(BLYNK_DEBUG_ALL) && !(__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__))
#warning "Compiler features not enabled -> please contact yor board vendor to enable c++0x"
#endif
// Diagnostic defines
#define BLYNK_FATAL(msg) { BLYNK_LOG1(msg); BlynkFatal(); }
#define BLYNK_LOG_RAM() { BLYNK_LOG2(BLYNK_F("Free RAM: "), BlynkFreeRam()); }
#define BLYNK_LOG_FN() BLYNK_LOG3(BLYNK_F(__FUNCTION__), '@', __LINE__);
#define BLYNK_LOG_TROUBLE(t) BLYNK_LOG2(BLYNK_F("Trouble detected: http://docs.blynk.cc/#troubleshooting-"), t)
#ifndef BLYNK_PRINT
#undef BLYNK_DEBUG
#endif
#ifdef BLYNK_DEBUG_ALL
#define BLYNK_DEBUG
#endif
#ifdef BLYNK_PRINT
#if defined(ARDUINO) || defined(SPARK) || defined(PARTICLE)
#if defined(ARDUINO_ARCH_ARC32)
// This will cause error - on purpose
#define BLYNK_LOG(msg, ...) BLYNK_LOG_UNAVAILABLE(msg, ##__VA_ARGS__)
#else
#define BLYNK_LOG(msg, ...) blynk_dbg_print(BLYNK_PSTR(msg), ##__VA_ARGS__)
#endif
#define BLYNK_LOG1(p1) { BLYNK_LOG_TIME(); BLYNK_PRINT.println(p1); }
#define BLYNK_LOG2(p1,p2) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(p1); BLYNK_PRINT.println(p2); }
#define BLYNK_LOG3(p1,p2,p3) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(p1); BLYNK_PRINT.print(p2); BLYNK_PRINT.println(p3); }
#define BLYNK_LOG4(p1,p2,p3,p4) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(p1); BLYNK_PRINT.print(p2); BLYNK_PRINT.print(p3); BLYNK_PRINT.println(p4); }
#define BLYNK_LOG6(p1,p2,p3,p4,p5,p6) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(p1); BLYNK_PRINT.print(p2); BLYNK_PRINT.print(p3); BLYNK_PRINT.print(p4); BLYNK_PRINT.print(p5); BLYNK_PRINT.println(p6); }
#define BLYNK_LOG_IP(msg, ip) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(BLYNK_F(msg)); \
BLYNK_PRINT.print(ip[0]); BLYNK_PRINT.print('.'); \
BLYNK_PRINT.print(ip[1]); BLYNK_PRINT.print('.'); \
BLYNK_PRINT.print(ip[2]); BLYNK_PRINT.print('.'); \
BLYNK_PRINT.println(ip[3]); }
#define BLYNK_LOG_IP_REV(msg, ip) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(BLYNK_F(msg)); \
BLYNK_PRINT.print(ip[3]); BLYNK_PRINT.print('.'); \
BLYNK_PRINT.print(ip[2]); BLYNK_PRINT.print('.'); \
BLYNK_PRINT.print(ip[1]); BLYNK_PRINT.print('.'); \
BLYNK_PRINT.println(ip[0]); }
static
void BLYNK_LOG_TIME() {
BLYNK_PRINT.print('[');
BLYNK_PRINT.print(BlynkMillis());
BLYNK_PRINT.print(BLYNK_F("] "));
}
#ifdef BLYNK_DEBUG
#include <ctype.h>
#define BLYNK_DBG_BREAK() { for(;;); }
#define BLYNK_ASSERT(expr) { if(!(expr)) { BLYNK_LOG2(BLYNK_F("Assertion failed: "), BLYNK_F(#expr)); BLYNK_DBG_BREAK() } }
static
void BLYNK_DBG_DUMP(const char* msg, const void* addr, size_t len) {
if (len) {
BLYNK_LOG_TIME();
BLYNK_PRINT.print(msg);
int l2 = len;
const uint8_t* octets = (const uint8_t*)addr;
bool prev_print = true;
while (l2--) {
const uint8_t c = *octets++ & 0xFF;
if (c >= 32 && c < 127) {
if (!prev_print) { BLYNK_PRINT.print(']'); }
BLYNK_PRINT.print((char)c);
prev_print = true;
} else {
BLYNK_PRINT.print(prev_print?'[':'|');
if (c < 0x10) { BLYNK_PRINT.print('0'); }
BLYNK_PRINT.print(c, HEX);
prev_print = false;
}
}
if (!prev_print) {
BLYNK_PRINT.print(']');
}
BLYNK_PRINT.println();
}
}
#endif
#if !defined(ARDUINO_ARCH_ARC32)
#include <stdio.h>
#include <stdarg.h>
BLYNK_UNUSED
void blynk_dbg_print(const char* BLYNK_PROGMEM fmt, ...)
{
va_list ap;
va_start(ap, fmt);
char buff[128];
BLYNK_PRINT.print('[');
BLYNK_PRINT.print(BlynkMillis());
BLYNK_PRINT.print(BLYNK_F("] "));
#if defined(__AVR__)
vsnprintf_P(buff, sizeof(buff), fmt, ap);
#else
vsnprintf(buff, sizeof(buff), fmt, ap);
#endif
BLYNK_PRINT.println(buff);
va_end(ap);
}
#endif // ARDUINO_ARCH_ARC32
#elif defined(__MBED__)
#define BLYNK_LOG(msg, ...) { BLYNK_PRINT.printf("[%ld] " msg BLYNK_NEWLINE, BlynkMillis(), ##__VA_ARGS__); }
#define BLYNK_LOG1(p1) { BLYNK_LOG(p1);}
#define BLYNK_LOG2(p1,p2) { BLYNK_LOG(p1,p2);}
#define BLYNK_LOG3(p1,p2,p3) { BLYNK_LOG(p1,p2,p3);}
#define BLYNK_LOG4(p1,p2,p3,p4) { BLYNK_LOG(p1,p2,p3,p4);}
#define BLYNK_LOG6(p1,p2,p3,p4,p5,p6) { BLYNK_LOG(p1,p2,p3,p4,p5,p6);}
#define BLYNK_LOG_TIME() BLYNK_PRINT.printf("[%ld]", BlynkMillis());
#ifdef BLYNK_DEBUG
#define BLYNK_DBG_BREAK() raise(SIGTRAP);
#define BLYNK_ASSERT(expr) assert(expr)
static
void BLYNK_DBG_DUMP(const char* msg, const void* addr, size_t len) {
BLYNK_LOG_TIME();
BLYNK_PRINT.printf(msg);
int l2 = len;
const uint8_t* octets = (const uint8_t*)addr;
bool prev_print = true;
while (l2--) {
const uint8_t c = *octets++ & 0xFF;
if (c >= 32 && c < 127) {
if (!prev_print) { BLYNK_PRINT.putc(']'); }
BLYNK_PRINT.putc((char)c);
prev_print = true;
} else {
BLYNK_PRINT.putc(prev_print?'[':'|');
BLYNK_PRINT.printf("%02x", c);
prev_print = false;
}
}
BLYNK_PRINT.printf("%s" BLYNK_NEWLINE, prev_print?"":"]");
}
#endif
#elif defined(LINUX)
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <iostream>
using namespace std;
#define BLYNK_LOG(msg, ...) { fprintf(BLYNK_PRINT, "[%ld] " msg BLYNK_NEWLINE, BlynkMillis(), ##__VA_ARGS__); }
#define BLYNK_LOG1(p1) { BLYNK_LOG_TIME(); cout << p1 << endl; }
#define BLYNK_LOG2(p1,p2) { BLYNK_LOG_TIME(); cout << p1 << p2 << endl; }
#define BLYNK_LOG3(p1,p2,p3) { BLYNK_LOG_TIME(); cout << p1 << p2 << p3 << endl; }
#define BLYNK_LOG4(p1,p2,p3,p4) { BLYNK_LOG_TIME(); cout << p1 << p2 << p3 << p4 << endl; }
#define BLYNK_LOG6(p1,p2,p3,p4,p5,p6) { BLYNK_LOG_TIME(); cout << p1 << p2 << p3 << p4 << p5 << p6 << endl; }
#define BLYNK_LOG_TIME() cout << '[' << BlynkMillis() << "] ";
#ifdef BLYNK_DEBUG
#define BLYNK_DBG_BREAK() raise(SIGTRAP);
#define BLYNK_ASSERT(expr) assert(expr)
static
void BLYNK_DBG_DUMP(const char* msg, const void* addr, size_t len) {
BLYNK_LOG_TIME();
fprintf(BLYNK_PRINT, "%s", msg);
int l2 = len;
const uint8_t* octets = (const uint8_t*)addr;
bool prev_print = true;
while (l2--) {
const uint8_t c = *octets++ & 0xFF;
if (c >= 32 && c < 127) {
if (!prev_print) { fputc(']', BLYNK_PRINT); }
fputc((char)c, BLYNK_PRINT);
prev_print = true;
} else {
fputc(prev_print?'[':'|', BLYNK_PRINT);
fprintf(BLYNK_PRINT, "%02x", c);
prev_print = false;
}
}
fprintf(BLYNK_PRINT, "%s" BLYNK_NEWLINE, prev_print?"":"]");
}
#endif
#else
#warning "Cannot detect platform"
#endif
#endif
#ifndef BLYNK_LOG
#define BLYNK_LOG(...)
#define BLYNK_LOG1(p1)
#define BLYNK_LOG2(p1,p2)
#define BLYNK_LOG3(p1,p2,p3)
#define BLYNK_LOG4(p1,p2,p3,p4)
#define BLYNK_LOG6(p1,p2,p3,p4,p5,p6)
#define BLYNK_LOG_IP(msg, ip)
#define BLYNK_LOG_IP_REV(msg, ip)
#endif
#ifndef BLYNK_DBG_BREAK
#define BLYNK_DBG_BREAK()
#define BLYNK_ASSERT(expr)
#define BLYNK_DBG_DUMP(msg, addr, len)
#endif
#endif

View File

@@ -0,0 +1,459 @@
/**
* @file BlynkDetectDevice.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
* @date May 2016
* @brief
*
*/
#ifndef BlynkDetectDevice_h
#define BlynkDetectDevice_h
// General defines
#define BLYNK_NEWLINE "\r\n"
#define BLYNK_CONCAT(a, b) a ## b
#define BLYNK_CONCAT2(a, b) BLYNK_CONCAT(a, b)
#define BLYNK_STRINGIFY(x) #x
#define BLYNK_TOSTRING(x) BLYNK_STRINGIFY(x)
#define BLYNK_COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define BLYNK_ATTR_PACKED __attribute__ ((__packed__))
#define BLYNK_NORETURN __attribute__ ((noreturn))
#define BLYNK_UNUSED __attribute__((__unused__))
#define BLYNK_DEPRECATED __attribute__ ((deprecated))
#define BLYNK_CONSTRUCTOR __attribute__((constructor))
// Causes problems on some platforms
#define BLYNK_FORCE_INLINE inline //__attribute__((always_inline))
#ifndef BLYNK_INFO_CPU
/******************************************
* ATmega
*/
#if defined(__AVR_ATmega168__)
#define BLYNK_INFO_CPU "ATmega168"
#elif defined(__AVR_ATmega328P__)
#define BLYNK_INFO_CPU "ATmega328P"
#elif defined(__AVR_ATmega1280__)
#define BLYNK_INFO_CPU "ATmega1280"
#elif defined(__AVR_ATmega1284__)
#define BLYNK_INFO_CPU "ATmega1284"
#elif defined(__AVR_ATmega2560__)
#define BLYNK_INFO_CPU "ATmega2560"
#elif defined(__AVR_ATmega32U4__)
#define BLYNK_INFO_CPU "ATmega32U4"
#elif defined(__SAM3X8E__)
#define BLYNK_INFO_CPU "AT91SAM3X8E"
/******************************************
* ATtiny
*/
#elif defined(__AVR_ATtiny25__)
#define BLYNK_INFO_CPU "ATtiny25"
#elif defined(__AVR_ATtiny45__)
#define BLYNK_INFO_CPU "ATtiny45"
#elif defined(__AVR_ATtiny85__)
#define BLYNK_INFO_CPU "ATtiny85"
#elif defined(__AVR_ATtiny24__)
#define BLYNK_INFO_CPU "ATtiny24"
#elif defined(__AVR_ATtiny44__)
#define BLYNK_INFO_CPU "ATtiny44"
#elif defined(__AVR_ATtiny84__)
#define BLYNK_INFO_CPU "ATtiny84"
#elif defined(__AVR_ATtiny2313__)
#define BLYNK_INFO_CPU "ATtiny2313"
#elif defined(__AVR_ATtiny4313__)
#define BLYNK_INFO_CPU "ATtiny4313"
#endif
#endif
#ifndef BLYNK_INFO_DEVICE
#if defined(ENERGIA)
#define BLYNK_NO_YIELD
#define BLYNK_USE_128_VPINS
#define BLYNK_USE_INTERNAL_DTOSTRF
#if defined(ENERGIA_ARCH_MSP430)
#define BLYNK_INFO_DEVICE "LaunchPad MSP430"
#define BLYNK_INFO_CPU "MSP430"
#define BLYNK_NO_FLOAT
#elif defined(ENERGIA_ARCH_MSP432)
#define BLYNK_INFO_DEVICE "LaunchPad MSP432"
#define BLYNK_INFO_CPU "MSP432"
#elif defined(ENERGIA_ARCH_TIVAC)
#define BLYNK_INFO_DEVICE "LaunchPad"
#elif defined(ENERGIA_ARCH_CC3200EMT) || defined(ENERGIA_ARCH_CC3200)
#define BLYNK_INFO_CONNECTION "CC3200"
#define BLYNK_SEND_CHUNK 64
#define BLYNK_BUFFERS_SIZE 1024
#if defined(ENERGIA_CC3200_LAUNCHXL) //TODO: This is a bug in Energia IDE
#define BLYNK_INFO_DEVICE "CC3200 LaunchXL"
#elif defined(ENERGIA_RedBearLab_CC3200)
#define BLYNK_INFO_DEVICE "RBL CC3200"
#elif defined(ENERGIA_RedBearLab_WiFiMini)
#define BLYNK_INFO_DEVICE "RBL WiFi Mini"
#elif defined(ENERGIA_RedBearLab_WiFiMicro)
#define BLYNK_INFO_DEVICE "RBL WiFi Micro"
#endif
#elif defined(ENERGIA_ARCH_CC3220EMT) || defined(ENERGIA_ARCH_CC3220)
#define BLYNK_INFO_CONNECTION "CC3220"
#define BLYNK_SEND_CHUNK 64
#define BLYNK_BUFFERS_SIZE 1024
#define BLYNK_INFO_DEVICE "CC3220"
#define BLYNK_INFO_CPU "CC3220"
#endif
#if !defined(BLYNK_INFO_DEVICE)
#define BLYNK_INFO_DEVICE "Energia"
#endif
#elif defined(LINUX)
#define BLYNK_INFO_DEVICE "Linux"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 4096
#elif defined(SPARK) || defined(PARTICLE)
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#if PLATFORM_ID==0
#define BLYNK_INFO_DEVICE "Particle Core"
#undef BLYNK_BUFFERS_SIZE // Use default on Core
#elif PLATFORM_ID==6
#define BLYNK_INFO_DEVICE "Particle Photon"
#elif PLATFORM_ID==8
#define BLYNK_INFO_DEVICE "Particle P1"
#elif PLATFORM_ID==9
#define BLYNK_INFO_DEVICE "Particle Ethernet"
#elif PLATFORM_ID==10
#define BLYNK_INFO_DEVICE "Particle Electron"
#elif PLATFORM_ID==31
#define BLYNK_INFO_DEVICE "Particle RPi"
#elif PLATFORM_ID==82
#define BLYNK_INFO_DEVICE "Digistump Oak"
#elif PLATFORM_ID==88
#define BLYNK_INFO_DEVICE "RedBear Duo"
#elif PLATFORM_ID==103
#define BLYNK_INFO_DEVICE "Bluz"
#else
#if defined(BLYNK_DEBUG_ALL)
#warning "Cannot detect board type"
#endif
#define BLYNK_INFO_DEVICE "Particle"
#endif
#elif defined(__MBED__)
#define BLYNK_INFO_DEVICE "MBED"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 512
#define noInterrupts() __disable_irq()
#define interrupts() __enable_irq()
#elif defined(ARDUINO) && defined(MPIDE)
#define BLYNK_NO_YIELD
#if defined(_BOARD_UNO_)
#define BLYNK_INFO_DEVICE "chipKIT Uno32"
#else
#define BLYNK_INFO_DEVICE "chipKIT"
#endif
#elif defined(ARDUINO) && defined(ARDUINO_AMEBA)
#if defined(BOARD_RTL8710)
#define BLYNK_INFO_DEVICE "RTL8710"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(BOARD_RTL8711AM)
#define BLYNK_INFO_DEVICE "RTL8711AM"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(BOARD_RTL8195A)
#define BLYNK_INFO_DEVICE "RTL8195A"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#else
#define BLYNK_INFO_DEVICE "Ameba"
#endif
#elif defined(ARDUINO) && defined(TEENSYDUINO)
#if defined(__MK66FX1M0__)
#define BLYNK_INFO_DEVICE "Teensy 3.6"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(__MK64FX512__)
#define BLYNK_INFO_DEVICE "Teensy 3.5"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(__MK20DX256__)
#define BLYNK_INFO_DEVICE "Teensy 3.2/3.1"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(__MK20DX128__)
#define BLYNK_INFO_DEVICE "Teensy 3.0"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(__MKL26Z64__)
#define BLYNK_INFO_DEVICE "Teensy LC"
#define BLYNK_BUFFERS_SIZE 512
#elif defined(ARDUINO_ARCH_AVR)
#define BLYNK_INFO_DEVICE "Teensy 2.0"
#else
#define BLYNK_INFO_DEVICE "Teensy"
#endif
#elif defined(ARDUINO)
#if defined(ARDUINO_ARCH_SAMD) || defined(ESP32) || defined(ESP8266)
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#endif
/* Arduino AVR */
#if defined(ARDUINO_AVR_NANO)
#define BLYNK_INFO_DEVICE "Arduino Nano"
#elif defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_DUEMILANOVE)
#define BLYNK_INFO_DEVICE "Arduino Uno"
#elif defined(ARDUINO_AVR_YUN)
#define BLYNK_INFO_DEVICE "Arduino Yun"
#elif defined(ARDUINO_AVR_MINI)
#define BLYNK_INFO_DEVICE "Arduino Mini"
#elif defined(ARDUINO_AVR_ETHERNET)
#define BLYNK_INFO_DEVICE "Arduino Ethernet"
#elif defined(ARDUINO_AVR_FIO)
#define BLYNK_INFO_DEVICE "Arduino Fio"
#elif defined(ARDUINO_AVR_BT)
#define BLYNK_INFO_DEVICE "Arduino BT"
#elif defined(ARDUINO_AVR_PRO)
#define BLYNK_INFO_DEVICE "Arduino Pro"
#elif defined(ARDUINO_AVR_NG)
#define BLYNK_INFO_DEVICE "Arduino NG"
#elif defined(ARDUINO_AVR_GEMMA)
#define BLYNK_INFO_DEVICE "Arduino Gemma"
#elif defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560)
#define BLYNK_INFO_DEVICE "Arduino Mega"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(ARDUINO_AVR_ADK)
#define BLYNK_INFO_DEVICE "Arduino Mega ADK"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(ARDUINO_AVR_LEONARDO)
#define BLYNK_INFO_DEVICE "Arduino Leonardo"
#elif defined(ARDUINO_AVR_MICRO)
#define BLYNK_INFO_DEVICE "Arduino Micro"
#elif defined(ARDUINO_AVR_ESPLORA)
#define BLYNK_INFO_DEVICE "Arduino Esplora"
#elif defined(ARDUINO_AVR_LILYPAD)
#define BLYNK_INFO_DEVICE "Lilypad"
#elif defined(ARDUINO_AVR_LILYPAD_USB)
#define BLYNK_INFO_DEVICE "Lilypad USB"
#elif defined(ARDUINO_AVR_ROBOT_MOTOR)
#define BLYNK_INFO_DEVICE "Robot Motor"
#elif defined(ARDUINO_AVR_ROBOT_CONTROL)
#define BLYNK_INFO_DEVICE "Robot Control"
/* Arduino megaAVR */
#elif defined(ARDUINO_AVR_UNO_WIFI_REV2)
#define BLYNK_INFO_DEVICE "Arduino UNO WiFi Rev2"
/* Arduino SAM */
#elif defined(ARDUINO_SAM_DUE)
#define BLYNK_INFO_DEVICE "Arduino Due"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
/* Arduino SAMD */
#elif defined(ARDUINO_SAMD_ZERO)
#define BLYNK_INFO_DEVICE "Arduino Zero"
#elif defined(ARDUINO_SAMD_MKR1000)
#define BLYNK_INFO_DEVICE "MKR1000"
#elif defined(ARDUINO_SAMD_MKRZERO)
#define BLYNK_INFO_DEVICE "MKRZERO"
#elif defined(ARDUINO_SAMD_MKRNB1500)
#define BLYNK_INFO_DEVICE "MKR NB 1500"
#elif defined(ARDUINO_SAMD_MKRGSM1400)
#define BLYNK_INFO_DEVICE "MKR GSM 1400"
#elif defined(ARDUINO_SAMD_MKRWAN1300)
#define BLYNK_INFO_DEVICE "MKR WAN 1300"
#elif defined(ARDUINO_SAMD_MKRFox1200)
#define BLYNK_INFO_DEVICE "MKR FOX 1200"
#elif defined(ARDUINO_SAMD_MKRWIFI1010)
#define BLYNK_INFO_DEVICE "MKR WiFi 1010"
#elif defined(ARDUINO_SAMD_MKRVIDOR4000)
#define BLYNK_INFO_DEVICE "MKR Vidor 4000"
/* Intel */
#elif defined(ARDUINO_GALILEO)
#define BLYNK_INFO_DEVICE "Galileo"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 4096
#elif defined(ARDUINO_GALILEOGEN2)
#define BLYNK_INFO_DEVICE "Galileo Gen2"
#define BLYNK_BUFFERS_SIZE 4096
#define BLYNK_USE_128_VPINS
#elif defined(ARDUINO_EDISON)
#define BLYNK_INFO_DEVICE "Edison"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 4096
#elif defined(ARDUINO_ARCH_ARC32)
#define BLYNK_INFO_DEVICE "Arduino 101"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
/* Konekt */
#elif defined(ARDUINO_DASH)
#define BLYNK_INFO_DEVICE "Dash"
#elif defined(ARDUINO_DASHPRO)
#define BLYNK_INFO_DEVICE "Dash Pro"
/* Red Bear Lab */
#elif defined(ARDUINO_RedBear_Duo)
#define BLYNK_INFO_DEVICE "RedBear Duo"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(ARDUINO_BLEND)
#define BLYNK_INFO_DEVICE "Blend"
#elif defined(ARDUINO_BLEND_MICRO_8MHZ) || defined(ARDUINO_BLEND_MICRO_16MHZ)
#define BLYNK_INFO_DEVICE "Blend Micro"
#elif defined(ARDUINO_RBL_nRF51822)
#define BLYNK_INFO_DEVICE "BLE Nano"
/* ESP8266 */
#elif defined(ARDUINO_ESP8266_NODEMCU)
#define BLYNK_INFO_DEVICE "NodeMCU"
#elif defined(ARDUINO_ARCH_ESP8266)
#define BLYNK_INFO_DEVICE "ESP8266"
/* ESP32 */
#elif defined(ARDUINO_ARCH_ESP32)
#define BLYNK_INFO_DEVICE "ESP32"
/* STM32 */
#elif defined(ARDUINO_ARCH_STM32F1)
#define BLYNK_INFO_DEVICE "STM32F1"
#define BLYNK_NO_YIELD
#elif defined(ARDUINO_ARCH_STM32F3)
#define BLYNK_INFO_DEVICE "STM32F3"
#define BLYNK_NO_YIELD
#elif defined(ARDUINO_ARCH_STM32F4)
#define BLYNK_INFO_DEVICE "STM32F4"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#define BLYNK_NO_YIELD
/* Digistump */
#elif defined(ARDUINO_ESP8266_OAK)
#define BLYNK_INFO_DEVICE "Oak"
#define BLYNK_USE_128_VPINS
#elif defined(ARDUINO_AVR_DIGISPARK)
#define BLYNK_INFO_DEVICE "Digispark"
#define BLYNK_NO_YIELD
#elif defined(ARDUINO_AVR_DIGISPARKPRO)
#define BLYNK_INFO_DEVICE "Digispark Pro"
#define BLYNK_NO_YIELD
/* Microduino */
#elif defined(ARDUINO_AVR_USB)
#define BLYNK_INFO_DEVICE "CoreUSB"
#elif defined(ARDUINO_AVR_PLUS)
#define BLYNK_INFO_DEVICE "Core+"
#elif defined(ARDUINO_AVR_RF)
#define BLYNK_INFO_DEVICE "CoreRF"
/* Wildfire */
#elif defined(ARDUINO_WILDFIRE_V2)
#define BLYNK_INFO_DEVICE "Wildfire V2"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(ARDUINO_WILDFIRE_V3)
#define BLYNK_INFO_DEVICE "Wildfire V3"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#elif defined(ARDUINO_WILDFIRE_V4)
#define BLYNK_INFO_DEVICE "Wildfire V4"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
/* Simblee */
#elif defined(__Simblee__)
#define BLYNK_INFO_DEVICE "Simblee"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 512
/* RFduino */
#elif defined(__RFduino__)
#define BLYNK_INFO_DEVICE "RFduino"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 512
/* Nordic NRF5x */
#elif defined(ARDUINO_ARCH_NRF5)
#define BLYNK_INFO_DEVICE "nRF5"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 512
#else
#if defined(BLYNK_DEBUG_ALL)
#warning "Cannot detect board type"
#endif
#define BLYNK_INFO_DEVICE "Arduino"
#endif
#elif defined(TI_CC3220)
#define BLYNK_INFO_DEVICE "TI CC3220"
#define BLYNK_USE_128_VPINS
#define BLYNK_BUFFERS_SIZE 1024
#define BLYNK_USE_INTERNAL_DTOSTRF
#else
#define BLYNK_INFO_DEVICE "Custom platform"
#endif
#if !defined(BLYNK_MAX_READBYTES) && defined(BLYNK_BUFFERS_SIZE)
#define BLYNK_MAX_READBYTES BLYNK_BUFFERS_SIZE
#endif
#if !defined(BLYNK_MAX_SENDBYTES) && defined(BLYNK_BUFFERS_SIZE)
#define BLYNK_MAX_SENDBYTES BLYNK_BUFFERS_SIZE
#endif
// Print diagnostics
#if defined(BLYNK_DEBUG_ALL)
#if defined(BLYNK_INFO_DEVICE)
#pragma message ("BLYNK_INFO_DEVICE=" BLYNK_TOSTRING(BLYNK_INFO_DEVICE))
#endif
#if defined(BLYNK_INFO_CPU)
#pragma message ("BLYNK_INFO_CPU=" BLYNK_TOSTRING(BLYNK_INFO_CPU))
#endif
#if defined(BLYNK_BUFFERS_SIZE)
#pragma message ("BLYNK_BUFFERS_SIZE=" BLYNK_TOSTRING(BLYNK_BUFFERS_SIZE))
#endif
#endif
#endif
#endif

View File

@@ -0,0 +1,69 @@
#ifndef BLYNKEVERYN_H
#define BLYNKEVERYN_H
#include <Blynk/BlynkDebug.h>
millis_time_t blynk_count_millis() {
const millis_time_t ms = BlynkMillis();
return ms;
}
uint16_t blynk_count_seconds16() {
const millis_time_t ms = BlynkMillis();
return (ms / 1000);
}
uint16_t blynk_count_minutes16()
{
const millis_time_t ms = BlynkMillis();
return (ms / (60000L)) & 0xFFFF;
}
uint8_t blynk_count_hours8()
{
const millis_time_t ms = BlynkMillis();
return (ms / (3600000L)) & 0xFF;
}
template<typename T, T (*timeGetter)()>
class BlynkPeriodic {
public:
T mPrev;
T mPeriod;
BlynkPeriodic() { reset(); mPeriod = 1; };
BlynkPeriodic(T period) { reset(); setPeriod(period); };
void setPeriod( T period) { mPeriod = period; };
T getTime() { return (T)(timeGetter()); };
T getPeriod() { return mPeriod; };
T getElapsed() { return getTime() - mPrev; }
T getRemaining() { return mPeriod - getElapsed(); }
T getLastTriggerTime() { return mPrev; }
bool ready() {
bool isReady = (getElapsed() >= mPeriod);
if( isReady ) { reset(); }
return isReady;
}
void reset() { mPrev = getTime(); };
void trigger() { mPrev = getTime() - mPeriod; };
operator bool() { return ready(); }
};
typedef BlynkPeriodic<millis_time_t,blynk_count_millis> BlynkEveryNMillis;
typedef BlynkPeriodic<uint16_t,blynk_count_seconds16> BlynkEveryNSeconds;
typedef BlynkPeriodic<uint16_t,blynk_count_minutes16> BlynkEveryNMinutes;
typedef BlynkPeriodic<uint8_t,blynk_count_hours8> BlynkEveryNHours;
#define BLYNK_EVERY_N_MILLIS_I(NAME,N) static BlynkEveryNMillis NAME(N); if(NAME)
#define BLYNK_EVERY_N_SECONDS_I(NAME,N) static BlynkEveryNSeconds NAME(N); if(NAME)
#define BLYNK_EVERY_N_MINUTES_I(NAME,N) static BlynkEveryNMinutes NAME(N); if(NAME)
#define BLYNK_EVERY_N_HOURS_I(NAME,N) static BlynkEveryNHours NAME(N); if(NAME)
#define BLYNK_EVERY_N_MILLIS(N) BLYNK_EVERY_N_MILLIS_I(BLYNK_CONCAT2(PER, __COUNTER__),N)
#define BLYNK_EVERY_N_SECONDS(N) BLYNK_EVERY_N_SECONDS_I(BLYNK_CONCAT2(PER, __COUNTER__),N)
#define BLYNK_EVERY_N_MINUTES(N) BLYNK_EVERY_N_MINUTES_I(BLYNK_CONCAT2(PER, __COUNTER__),N)
#define BLYNK_EVERY_N_HOURS(N) BLYNK_EVERY_N_HOURS_I(BLYNK_CONCAT2(PER, __COUNTER__),N)
#endif

View File

@@ -0,0 +1,511 @@
/**
* @file BlynkHandlers.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief Handlers for virtual pin operations
*
*/
#ifndef BlynkHandlers_h
#define BlynkHandlers_h
#include <Blynk/BlynkConfig.h>
#include <Blynk/BlynkParam.h>
// Helper macro
#define V0 0
#define V1 1
#define V2 2
#define V3 3
#define V4 4
#define V5 5
#define V6 6
#define V7 7
#define V8 8
#define V9 9
#define V10 10
#define V11 11
#define V12 12
#define V13 13
#define V14 14
#define V15 15
#define V16 16
#define V17 17
#define V18 18
#define V19 19
#define V20 20
#define V21 21
#define V22 22
#define V23 23
#define V24 24
#define V25 25
#define V26 26
#define V27 27
#define V28 28
#define V29 29
#define V30 30
#define V31 31
#ifdef BLYNK_USE_128_VPINS
#define V32 32
#define V33 33
#define V34 34
#define V35 35
#define V36 36
#define V37 37
#define V38 38
#define V39 39
#define V40 40
#define V41 41
#define V42 42
#define V43 43
#define V44 44
#define V45 45
#define V46 46
#define V47 47
#define V48 48
#define V49 49
#define V50 50
#define V51 51
#define V52 52
#define V53 53
#define V54 54
#define V55 55
#define V56 56
#define V57 57
#define V58 58
#define V59 59
#define V60 60
#define V61 61
#define V62 62
#define V63 63
#define V64 64
#define V65 65
#define V66 66
#define V67 67
#define V68 68
#define V69 69
#define V70 70
#define V71 71
#define V72 72
#define V73 73
#define V74 74
#define V75 75
#define V76 76
#define V77 77
#define V78 78
#define V79 79
#define V80 80
#define V81 81
#define V82 82
#define V83 83
#define V84 84
#define V85 85
#define V86 86
#define V87 87
#define V88 88
#define V89 89
#define V90 90
#define V91 91
#define V92 92
#define V93 93
#define V94 94
#define V95 95
#define V96 96
#define V97 97
#define V98 98
#define V99 99
#define V100 100
#define V101 101
#define V102 102
#define V103 103
#define V104 104
#define V105 105
#define V106 106
#define V107 107
#define V108 108
#define V109 109
#define V110 110
#define V111 111
#define V112 112
#define V113 113
#define V114 114
#define V115 115
#define V116 116
#define V117 117
#define V118 118
#define V119 119
#define V120 120
#define V121 121
#define V122 122
#define V123 123
#define V124 124
#define V125 125
#define V126 126
#define V127 127
#endif
// Initial syntax:
#define BLYNK_WRITE_2(pin) \
void BlynkWidgetWrite ## pin (BlynkReq BLYNK_UNUSED &request, const BlynkParam BLYNK_UNUSED &param)
#define BLYNK_READ_2(pin) \
void BlynkWidgetRead ## pin (BlynkReq BLYNK_UNUSED &request)
#define BLYNK_WRITE_DEFAULT() BLYNK_WRITE_2(Default)
#define BLYNK_READ_DEFAULT() BLYNK_READ_2(Default)
#define BLYNK_WRITE(pin) BLYNK_WRITE_2(pin)
#define BLYNK_READ(pin) BLYNK_READ_2(pin)
// New, more readable syntax:
#define BLYNK_IN_2(pin) \
void BlynkWidgetWrite ## pin (BlynkReq BLYNK_UNUSED &request, const BlynkParam BLYNK_UNUSED &getValue)
#define BLYNK_OUT_2(pin) \
void BlynkWidgetRead ## pin (BlynkReq BLYNK_UNUSED &request)
#define BLYNK_INPUT_DEFAULT() BLYNK_IN_2(Default)
#define BLYNK_OUTPUT_DEFAULT() BLYNK_OUT_2(Default)
#define BLYNK_INPUT(pin) BLYNK_IN_2(pin)
#define BLYNK_OUTPUT(pin) BLYNK_OUT_2(pin)
// Additional handlers
#define BLYNK_CONNECTED() void BlynkOnConnected()
#define BLYNK_DISCONNECTED() void BlynkOnDisconnected()
// Advanced functions
#define BLYNK_VAR_INT(name, pin) \
int name; \
BLYNK_WRITE(pin) { name = param.asInt(); } \
BLYNK_READ(pin) { Blynk.virtualWrite(pin, name); }
#define BLYNK_VAR_LONG(name, pin) \
long name; \
BLYNK_WRITE(pin) { name = param.asLong(); } \
BLYNK_READ(pin) { Blynk.virtualWrite(pin, name); }
#ifndef BLYNK_NO_FLOAT
#define BLYNK_VAR_DOUBLE(name, pin) \
double name; \
BLYNK_WRITE(pin) { name = param.asDouble(); } \
BLYNK_READ(pin) { Blynk.virtualWrite(pin, name); }
#endif
#ifdef ARDUINO
#define BLYNK_VAR_STRING(name, pin) \
String name; \
BLYNK_WRITE(pin) { name = param.asStr(); } \
BLYNK_READ(pin) { Blynk.virtualWrite(pin, name); }
#endif
// Default read/write handlers (you can redefine them in your code)
#ifdef __cplusplus
extern "C" {
#endif
struct BlynkReq
{
uint8_t pin;
};
typedef void (*WidgetReadHandler)(BlynkReq BLYNK_UNUSED &request);
typedef void (*WidgetWriteHandler)(BlynkReq BLYNK_UNUSED &request, const BlynkParam BLYNK_UNUSED &param);
WidgetReadHandler GetReadHandler(uint8_t pin);
WidgetWriteHandler GetWriteHandler(uint8_t pin);
// Declare placeholders
BLYNK_READ();
BLYNK_WRITE();
void BlynkNoOpCbk();
// Declare all pin handlers (you can redefine them in your code)
BLYNK_CONNECTED();
BLYNK_DISCONNECTED();
// Internal Virtual Pins
BLYNK_WRITE(InternalPinACON);
BLYNK_WRITE(InternalPinADIS);
BLYNK_WRITE(InternalPinRTC);
BLYNK_WRITE(InternalPinOTA);
// Aliases
#define BLYNK_APP_CONNECTED() BLYNK_WRITE(InternalPinACON)
#define BLYNK_APP_DISCONNECTED() BLYNK_WRITE(InternalPinADIS)
// Regular Virtual Pins
BLYNK_READ_DEFAULT();
BLYNK_WRITE_DEFAULT();
BLYNK_READ(0 );
BLYNK_READ(1 );
BLYNK_READ(2 );
BLYNK_READ(3 );
BLYNK_READ(4 );
BLYNK_READ(5 );
BLYNK_READ(6 );
BLYNK_READ(7 );
BLYNK_READ(8 );
BLYNK_READ(9 );
BLYNK_READ(10);
BLYNK_READ(11);
BLYNK_READ(12);
BLYNK_READ(13);
BLYNK_READ(14);
BLYNK_READ(15);
BLYNK_READ(16);
BLYNK_READ(17);
BLYNK_READ(18);
BLYNK_READ(19);
BLYNK_READ(20);
BLYNK_READ(21);
BLYNK_READ(22);
BLYNK_READ(23);
BLYNK_READ(24);
BLYNK_READ(25);
BLYNK_READ(26);
BLYNK_READ(27);
BLYNK_READ(28);
BLYNK_READ(29);
BLYNK_READ(30);
BLYNK_READ(31);
#ifdef BLYNK_USE_128_VPINS
BLYNK_READ(32);
BLYNK_READ(33);
BLYNK_READ(34);
BLYNK_READ(35);
BLYNK_READ(36);
BLYNK_READ(37);
BLYNK_READ(38);
BLYNK_READ(39);
BLYNK_READ(40);
BLYNK_READ(41);
BLYNK_READ(42);
BLYNK_READ(43);
BLYNK_READ(44);
BLYNK_READ(45);
BLYNK_READ(46);
BLYNK_READ(47);
BLYNK_READ(48);
BLYNK_READ(49);
BLYNK_READ(50);
BLYNK_READ(51);
BLYNK_READ(52);
BLYNK_READ(53);
BLYNK_READ(54);
BLYNK_READ(55);
BLYNK_READ(56);
BLYNK_READ(57);
BLYNK_READ(58);
BLYNK_READ(59);
BLYNK_READ(60);
BLYNK_READ(61);
BLYNK_READ(62);
BLYNK_READ(63);
BLYNK_READ(64);
BLYNK_READ(65);
BLYNK_READ(66);
BLYNK_READ(67);
BLYNK_READ(68);
BLYNK_READ(69);
BLYNK_READ(70);
BLYNK_READ(71);
BLYNK_READ(72);
BLYNK_READ(73);
BLYNK_READ(74);
BLYNK_READ(75);
BLYNK_READ(76);
BLYNK_READ(77);
BLYNK_READ(78);
BLYNK_READ(79);
BLYNK_READ(80);
BLYNK_READ(81);
BLYNK_READ(82);
BLYNK_READ(83);
BLYNK_READ(84);
BLYNK_READ(85);
BLYNK_READ(86);
BLYNK_READ(87);
BLYNK_READ(88);
BLYNK_READ(89);
BLYNK_READ(90);
BLYNK_READ(91);
BLYNK_READ(92);
BLYNK_READ(93);
BLYNK_READ(94);
BLYNK_READ(95);
BLYNK_READ(96);
BLYNK_READ(97);
BLYNK_READ(98);
BLYNK_READ(99);
BLYNK_READ(100);
BLYNK_READ(101);
BLYNK_READ(102);
BLYNK_READ(103);
BLYNK_READ(104);
BLYNK_READ(105);
BLYNK_READ(106);
BLYNK_READ(107);
BLYNK_READ(108);
BLYNK_READ(109);
BLYNK_READ(110);
BLYNK_READ(111);
BLYNK_READ(112);
BLYNK_READ(113);
BLYNK_READ(114);
BLYNK_READ(115);
BLYNK_READ(116);
BLYNK_READ(117);
BLYNK_READ(118);
BLYNK_READ(119);
BLYNK_READ(120);
BLYNK_READ(121);
BLYNK_READ(122);
BLYNK_READ(123);
BLYNK_READ(124);
BLYNK_READ(125);
BLYNK_READ(126);
BLYNK_READ(127);
#endif
BLYNK_WRITE(0 );
BLYNK_WRITE(1 );
BLYNK_WRITE(2 );
BLYNK_WRITE(3 );
BLYNK_WRITE(4 );
BLYNK_WRITE(5 );
BLYNK_WRITE(6 );
BLYNK_WRITE(7 );
BLYNK_WRITE(8 );
BLYNK_WRITE(9 );
BLYNK_WRITE(10);
BLYNK_WRITE(11);
BLYNK_WRITE(12);
BLYNK_WRITE(13);
BLYNK_WRITE(14);
BLYNK_WRITE(15);
BLYNK_WRITE(16);
BLYNK_WRITE(17);
BLYNK_WRITE(18);
BLYNK_WRITE(19);
BLYNK_WRITE(20);
BLYNK_WRITE(21);
BLYNK_WRITE(22);
BLYNK_WRITE(23);
BLYNK_WRITE(24);
BLYNK_WRITE(25);
BLYNK_WRITE(26);
BLYNK_WRITE(27);
BLYNK_WRITE(28);
BLYNK_WRITE(29);
BLYNK_WRITE(30);
BLYNK_WRITE(31);
#ifdef BLYNK_USE_128_VPINS
BLYNK_WRITE(32);
BLYNK_WRITE(33);
BLYNK_WRITE(34);
BLYNK_WRITE(35);
BLYNK_WRITE(36);
BLYNK_WRITE(37);
BLYNK_WRITE(38);
BLYNK_WRITE(39);
BLYNK_WRITE(40);
BLYNK_WRITE(41);
BLYNK_WRITE(42);
BLYNK_WRITE(43);
BLYNK_WRITE(44);
BLYNK_WRITE(45);
BLYNK_WRITE(46);
BLYNK_WRITE(47);
BLYNK_WRITE(48);
BLYNK_WRITE(49);
BLYNK_WRITE(50);
BLYNK_WRITE(51);
BLYNK_WRITE(52);
BLYNK_WRITE(53);
BLYNK_WRITE(54);
BLYNK_WRITE(55);
BLYNK_WRITE(56);
BLYNK_WRITE(57);
BLYNK_WRITE(58);
BLYNK_WRITE(59);
BLYNK_WRITE(60);
BLYNK_WRITE(61);
BLYNK_WRITE(62);
BLYNK_WRITE(63);
BLYNK_WRITE(64);
BLYNK_WRITE(65);
BLYNK_WRITE(66);
BLYNK_WRITE(67);
BLYNK_WRITE(68);
BLYNK_WRITE(69);
BLYNK_WRITE(70);
BLYNK_WRITE(71);
BLYNK_WRITE(72);
BLYNK_WRITE(73);
BLYNK_WRITE(74);
BLYNK_WRITE(75);
BLYNK_WRITE(76);
BLYNK_WRITE(77);
BLYNK_WRITE(78);
BLYNK_WRITE(79);
BLYNK_WRITE(80);
BLYNK_WRITE(81);
BLYNK_WRITE(82);
BLYNK_WRITE(83);
BLYNK_WRITE(84);
BLYNK_WRITE(85);
BLYNK_WRITE(86);
BLYNK_WRITE(87);
BLYNK_WRITE(88);
BLYNK_WRITE(89);
BLYNK_WRITE(90);
BLYNK_WRITE(91);
BLYNK_WRITE(92);
BLYNK_WRITE(93);
BLYNK_WRITE(94);
BLYNK_WRITE(95);
BLYNK_WRITE(96);
BLYNK_WRITE(97);
BLYNK_WRITE(98);
BLYNK_WRITE(99);
BLYNK_WRITE(100);
BLYNK_WRITE(101);
BLYNK_WRITE(102);
BLYNK_WRITE(103);
BLYNK_WRITE(104);
BLYNK_WRITE(105);
BLYNK_WRITE(106);
BLYNK_WRITE(107);
BLYNK_WRITE(108);
BLYNK_WRITE(109);
BLYNK_WRITE(110);
BLYNK_WRITE(111);
BLYNK_WRITE(112);
BLYNK_WRITE(113);
BLYNK_WRITE(114);
BLYNK_WRITE(115);
BLYNK_WRITE(116);
BLYNK_WRITE(117);
BLYNK_WRITE(118);
BLYNK_WRITE(119);
BLYNK_WRITE(120);
BLYNK_WRITE(121);
BLYNK_WRITE(122);
BLYNK_WRITE(123);
BLYNK_WRITE(124);
BLYNK_WRITE(125);
BLYNK_WRITE(126);
BLYNK_WRITE(127);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,380 @@
/**
* @file BlynkParam.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief Container for handler parameters
*
*/
#ifndef BlynkParam_h
#define BlynkParam_h
#include <string.h>
#include <stdlib.h>
#include <Blynk/BlynkConfig.h>
#include <Blynk/BlynkDebug.h>
#define BLYNK_PARAM_KV(k, v) k "\0" v "\0"
#define BLYNK_PARAM_PLACEHOLDER_64 "PlaceholderPlaceholderPlaceholderPlaceholderPlaceholderPlaceholder"
class BlynkParam
{
public:
class iterator
{
public:
iterator(const char* c, const char* l) : ptr(c), limit(l) {}
static iterator invalid() { return iterator(NULL, NULL); }
operator const char* () const { return asStr(); }
operator int () const { return asInt(); }
const char* asStr() const { return ptr; }
const char* asString() const { return ptr; }
int asInt() const { if(!isValid()) return 0; return atoi(ptr); }
long asLong() const { if(!isValid()) return 0; return atol(ptr); }
//long long asLongLong() const { return atoll(ptr); }
#ifndef BLYNK_NO_FLOAT
double asDouble() const { if(!isValid()) return 0; return atof(ptr); }
float asFloat() const { if(!isValid()) return 0; return atof(ptr); }
#endif
bool isValid() const { return ptr != NULL && ptr < limit; }
bool isEmpty() const { if(!isValid()) return true; return *ptr == '\0'; }
bool operator < (const iterator& it) const { return ptr < it.ptr; }
bool operator >= (const iterator& it) const { return ptr >= it.ptr; }
iterator& operator ++() {
if(isValid()) {
ptr += strlen(ptr) + 1;
}
return *this;
}
private:
const char* ptr;
const char* limit;
};
public:
explicit
BlynkParam(const void* addr, size_t length)
: buff((char*)addr), len(length), buff_size(length)
{}
explicit
BlynkParam(void* addr, size_t length, size_t buffsize)
: buff((char*)addr), len(length), buff_size(buffsize)
{}
const char* asStr() const { return buff; }
const char* asString() const { return buff; }
int asInt() const { return atoi(buff); }
long asLong() const { return atol(buff); }
//long long asLongLong() const { return atoll(buff); }
#ifndef BLYNK_NO_FLOAT
double asDouble() const { return atof(buff); }
float asFloat() const { return atof(buff); }
#endif
bool isEmpty() const { return *buff == '\0'; }
iterator begin() const { return iterator(buff, buff+len); }
iterator end() const { return iterator(buff+len, buff+len); }
iterator operator[](int index) const;
iterator operator[](const char* key) const;
void* getBuffer() const { return (void*)buff; }
size_t getLength() const { return len; }
// Modification
void add(int value);
void add(unsigned int value);
void add(long value);
void add(unsigned long value);
void add(long long value);
void add(unsigned long long value);
#ifndef BLYNK_NO_FLOAT
void add(float value);
void add(double value);
#endif
void add(const char* str);
void add(const void* b, size_t l);
#if defined(ARDUINO) || defined(SPARK) || defined(PARTICLE)
void add(const String& str);
#if defined(BLYNK_HAS_PROGMEM)
void add(const __FlashStringHelper* str);
#endif
#endif
template<typename T, typename... Args>
void add_multi(T last) {
add(last);
}
template<typename T, typename... Args>
void add_multi(T head, Args... tail) {
add(head);
add_multi(tail...);
}
template <typename TV>
void add_key(const char* key, const TV& val) {
add(key);
add(val);
}
protected:
char* buff;
size_t len;
size_t buff_size;
};
class BlynkParamAllocated
: public BlynkParam
{
public:
BlynkParamAllocated(size_t size)
: BlynkParam(malloc(size), 0, size)
{}
~BlynkParamAllocated() {
free(buff);
}
};
inline
BlynkParam::iterator BlynkParam::operator[](int index) const
{
const iterator e = end();
for (iterator it = begin(); it < e; ++it) {
if (!index--) {
return it;
}
}
return iterator::invalid();
}
inline
BlynkParam::iterator BlynkParam::operator[](const char* key) const
{
const iterator e = end();
for (iterator it = begin(); it < e; ++it) {
if (!strcmp(it.asStr(), key)) {
return ++it;
}
++it;
if (it >= e) break;
}
return iterator::invalid();
}
inline
void BlynkParam::add(const void* b, size_t l)
{
if (len + l > buff_size)
return;
memcpy(buff+len, b, l);
len += l;
}
inline
void BlynkParam::add(const char* str)
{
if (str == NULL) {
buff[len++] = '\0';
return;
}
add(str, strlen(str)+1);
}
#if defined(ARDUINO) || defined(SPARK) || defined(PARTICLE)
inline
void BlynkParam::add(const String& str)
{
#if defined(ARDUINO_AVR_DIGISPARK) \
|| defined(__ARDUINO_X86__) \
|| defined(__RFduino__)
size_t len = str.length()+1;
char buff[len];
const_cast<String&>(str).toCharArray(buff, len);
add(buff, len);
#else
add(str.c_str());
#endif
}
#if defined(BLYNK_HAS_PROGMEM)
inline
void BlynkParam::add(const __FlashStringHelper* ifsh)
{
PGM_P p = reinterpret_cast<PGM_P>(ifsh);
size_t l = strlen_P(p) + 1;
if (len + l > buff_size)
return;
memcpy_P(buff+len, p, l);
len += l;
buff[len] = '\0';
}
#endif
#endif
#if defined(__AVR__) || defined (ARDUINO_ARCH_ARC32)
#include <stdlib.h>
inline
void BlynkParam::add(int value)
{
char str[2 + 8 * sizeof(value)];
itoa(value, str, 10);
add(str);
}
inline
void BlynkParam::add(unsigned int value)
{
char str[1 + 8 * sizeof(value)];
utoa(value, str, 10);
add(str);
}
inline
void BlynkParam::add(long value)
{
char str[2 + 8 * sizeof(value)];
ltoa(value, str, 10);
add(str);
}
inline
void BlynkParam::add(unsigned long value)
{
char str[1 + 8 * sizeof(value)];
ultoa(value, str, 10);
add(str);
}
inline
void BlynkParam::add(long long value) // TODO: this currently adds just a long
{
char str[2 + 8 * sizeof(value)];
ltoa(value, str, 10);
add(str);
}
inline
void BlynkParam::add(unsigned long long value) // TODO: this currently adds just a long
{
char str[1 + 8 * sizeof(value)];
ultoa(value, str, 10);
add(str);
}
#ifndef BLYNK_NO_FLOAT
inline
void BlynkParam::add(float value)
{
char str[33];
dtostrf(value, 5, 3, str);
add(str);
}
inline
void BlynkParam::add(double value)
{
char str[33];
dtostrf(value, 5, 7, str);
add(str);
}
#endif
#else
#include <stdio.h>
inline
void BlynkParam::add(int value)
{
len += snprintf(buff+len, buff_size-len, "%i", value)+1;
}
inline
void BlynkParam::add(unsigned int value)
{
len += snprintf(buff+len, buff_size-len, "%u", value)+1;
}
inline
void BlynkParam::add(long value)
{
len += snprintf(buff+len, buff_size-len, "%li", value)+1;
}
inline
void BlynkParam::add(unsigned long value)
{
len += snprintf(buff+len, buff_size-len, "%lu", value)+1;
}
inline
void BlynkParam::add(long long value)
{
len += snprintf(buff+len, buff_size-len, "%lli", value)+1;
}
inline
void BlynkParam::add(unsigned long long value)
{
len += snprintf(buff+len, buff_size-len, "%llu", value)+1;
}
#ifndef BLYNK_NO_FLOAT
#if defined(BLYNK_USE_INTERNAL_DTOSTRF)
extern char* dtostrf_internal(double number, signed char width, unsigned char prec, char *s);
inline
void BlynkParam::add(float value)
{
char str[33];
dtostrf_internal(value, 5, 3, str);
add(str);
}
inline
void BlynkParam::add(double value)
{
char str[33];
dtostrf_internal(value, 5, 7, str);
add(str);
}
#else
inline
void BlynkParam::add(float value)
{
len += snprintf(buff+len, buff_size-len, "%2.3f", value)+1;
}
inline
void BlynkParam::add(double value)
{
len += snprintf(buff+len, buff_size-len, "%2.7f", value)+1;
}
#endif
#endif
#endif
#endif

View File

@@ -0,0 +1,544 @@
/**
* @file BlynkProtocol.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief Blynk protocol implementation
*
*/
#ifndef BlynkProtocol_h
#define BlynkProtocol_h
#include <string.h>
#include <stdlib.h>
#include <Blynk/BlynkDebug.h>
#include <Blynk/BlynkProtocolDefs.h>
#include <Blynk/BlynkApi.h>
#include <utility/BlynkUtility.h>
template <class Transp>
class BlynkProtocol
: public BlynkApi< BlynkProtocol<Transp> >
{
friend class BlynkApi< BlynkProtocol<Transp> >;
public:
enum BlynkState {
CONNECTING,
CONNECTED,
DISCONNECTED,
TOKEN_INVALID,
};
BlynkProtocol(Transp& transp)
: conn(transp)
, authkey(NULL)
, redir_serv(NULL)
, lastActivityIn(0)
, lastActivityOut(0)
, lastHeartbeat(0)
, msgIdOut(0)
, msgIdOutOverride(0)
, nesting(0)
, state(CONNECTING)
{}
bool connected() const { return state == CONNECTED; }
bool isTokenInvalid() const { return state == TOKEN_INVALID; }
bool connect(uint32_t timeout = BLYNK_TIMEOUT_MS*3) {
conn.disconnect();
state = CONNECTING;
millis_time_t started = BlynkMillis();
while ((state != CONNECTED) &&
(BlynkMillis() - started < timeout))
{
run();
}
return state == CONNECTED;
}
void disconnect() {
conn.disconnect();
state = DISCONNECTED;
BLYNK_LOG1(BLYNK_F("Disconnected"));
}
bool run(bool avail = false);
// TODO: Fixme
void startSession() {
conn.connect();
state = CONNECTING;
msgIdOut = 0;
lastHeartbeat = lastActivityIn = lastActivityOut = (BlynkMillis() - 5000UL);
}
void sendCmd(uint8_t cmd, uint16_t id = 0, const void* data = NULL, size_t length = 0, const void* data2 = NULL, size_t length2 = 0);
void printBanner() {
#if defined(BLYNK_NO_FANCY_LOGO)
BLYNK_LOG1(BLYNK_F("Blynk v" BLYNK_VERSION " on " BLYNK_INFO_DEVICE));
#else
BLYNK_LOG1(BLYNK_F(BLYNK_NEWLINE
" ___ __ __" BLYNK_NEWLINE
" / _ )/ /_ _____ / /__" BLYNK_NEWLINE
" / _ / / // / _ \\/ '_/" BLYNK_NEWLINE
" /____/_/\\_, /_//_/_/\\_\\" BLYNK_NEWLINE
" /___/ v" BLYNK_VERSION " on " BLYNK_INFO_DEVICE BLYNK_NEWLINE
));
#endif
}
private:
void internalReconnect() {
state = CONNECTING;
conn.disconnect();
BlynkOnDisconnected();
}
int readHeader(BlynkHeader& hdr);
uint16_t getNextMsgId();
protected:
void begin(const char* auth) {
this->authkey = auth;
lastHeartbeat = lastActivityIn = lastActivityOut = (BlynkMillis() - 5000UL);
#if !defined(BLYNK_NO_DEFAULT_BANNER)
printBanner();
#endif
}
bool processInput(void);
Transp& conn;
private:
const char* authkey;
char* redir_serv;
millis_time_t lastActivityIn;
millis_time_t lastActivityOut;
union {
millis_time_t lastHeartbeat;
millis_time_t lastLogin;
};
uint16_t msgIdOut;
uint16_t msgIdOutOverride;
uint8_t nesting;
protected:
BlynkState state;
};
template <class Transp>
bool BlynkProtocol<Transp>::run(bool avail)
{
BLYNK_RUN_YIELD();
if (state == DISCONNECTED) {
return false;
}
// Detect nesting
BlynkHelperAutoInc guard(nesting);
if (msgIdOutOverride || nesting > 2) {
//BLYNK_LOG1(BLYNK_F("Nested run() skipped"));
return true;
}
if (conn.connected()) {
while (avail || conn.available() > 0) {
//BLYNK_LOG2(BLYNK_F("Available: "), conn.available());
//const unsigned long t = micros();
if (!processInput()) {
conn.disconnect();
// TODO: Only when in direct mode?
#ifdef BLYNK_USE_DIRECT_CONNECT
state = CONNECTING;
#endif
BlynkOnDisconnected();
return false;
}
avail = false;
//BLYNK_LOG2(BLYNK_F("Proc time: "), micros() - t);
}
}
const millis_time_t t = BlynkMillis();
// Update connection status after running commands
const bool tconn = conn.connected();
if (state == CONNECTED) {
if (!tconn) {
lastHeartbeat = t;
internalReconnect();
return false;
}
if (t - lastActivityIn > (1000UL * BLYNK_HEARTBEAT + BLYNK_TIMEOUT_MS*3)) {
#ifdef BLYNK_DEBUG
BLYNK_LOG6(BLYNK_F("Heartbeat timeout: "), t, BLYNK_F(", "), lastActivityIn, BLYNK_F(", "), lastHeartbeat);
#else
BLYNK_LOG1(BLYNK_F("Heartbeat timeout"));
#endif
internalReconnect();
return false;
} else if ((t - lastActivityIn > 1000UL * BLYNK_HEARTBEAT ||
t - lastActivityOut > 1000UL * BLYNK_HEARTBEAT) &&
t - lastHeartbeat > BLYNK_TIMEOUT_MS)
{
// Send ping if we didn't either send or receive something
// for BLYNK_HEARTBEAT seconds
sendCmd(BLYNK_CMD_PING);
lastHeartbeat = t;
}
} else if (state == CONNECTING) {
#ifdef BLYNK_USE_DIRECT_CONNECT
if (!tconn)
conn.connect();
#else
if (tconn && (t - lastLogin > BLYNK_TIMEOUT_MS)) {
BLYNK_LOG1(BLYNK_F("Login timeout"));
conn.disconnect();
state = CONNECTING;
return false;
} else if (!tconn && (t - lastLogin > 5000UL)) {
conn.disconnect();
if (!conn.connect()) {
lastLogin = t;
return false;
}
msgIdOut = 1;
sendCmd(BLYNK_CMD_HW_LOGIN, 1, authkey, strlen(authkey));
lastLogin = lastActivityOut;
return true;
}
#endif
}
return true;
}
template <class Transp>
BLYNK_FORCE_INLINE
bool BlynkProtocol<Transp>::processInput(void)
{
BlynkHeader hdr;
const int ret = readHeader(hdr);
if (ret == 0) {
return true; // Considered OK (no data on input)
}
if (ret < 0 || hdr.msg_id == 0) {
#ifdef BLYNK_DEBUG
BLYNK_LOG2(BLYNK_F("Bad hdr len: "), ret);
#endif
return false;
}
if (hdr.type == BLYNK_CMD_RESPONSE) {
lastActivityIn = BlynkMillis();
#ifndef BLYNK_USE_DIRECT_CONNECT
if (state == CONNECTING && (1 == hdr.msg_id)) {
switch (hdr.length) {
case BLYNK_SUCCESS:
case BLYNK_ALREADY_REGISTERED:
BLYNK_LOG3(BLYNK_F("Ready (ping: "), lastActivityIn-lastHeartbeat, BLYNK_F("ms)."));
lastHeartbeat = lastActivityIn;
state = CONNECTED;
#ifdef BLYNK_DEBUG
if (size_t ram = BlynkFreeRam()) {
BLYNK_LOG2(BLYNK_F("Free RAM: "), ram);
}
#endif
this->sendInfo();
BLYNK_RUN_YIELD();
BlynkOnConnected();
return true;
case BLYNK_INVALID_TOKEN:
BLYNK_LOG1(BLYNK_F("Invalid auth token"));
state = TOKEN_INVALID;
break;
default:
BLYNK_LOG2(BLYNK_F("Connect failed. code: "), hdr.length);
}
return false;
}
if (BLYNK_NOT_AUTHENTICATED == hdr.length) {
return false;
}
#endif
// TODO: return code may indicate App presence
return true;
}
if (hdr.length > BLYNK_MAX_READBYTES) {
BLYNK_LOG2(BLYNK_F("Packet too big: "), hdr.length);
// TODO: Flush
internalReconnect();
return true;
}
uint8_t inputBuffer[hdr.length+1]; // Add 1 to zero-terminate
if (hdr.length != conn.read(inputBuffer, hdr.length)) {
#ifdef BLYNK_DEBUG
BLYNK_LOG1(BLYNK_F("Can't read body"));
#endif
return false;
}
inputBuffer[hdr.length] = '\0';
BLYNK_DBG_DUMP(">", inputBuffer, hdr.length);
lastActivityIn = BlynkMillis();
switch (hdr.type)
{
case BLYNK_CMD_LOGIN:
case BLYNK_CMD_HW_LOGIN: {
#ifdef BLYNK_USE_DIRECT_CONNECT
if (strncmp(authkey, (char*)inputBuffer, 32)) {
BLYNK_LOG1(BLYNK_F("Invalid token"));
sendCmd(BLYNK_CMD_RESPONSE, hdr.msg_id, NULL, BLYNK_INVALID_TOKEN);
break;
}
#endif
if (state == CONNECTING) {
BLYNK_LOG1(BLYNK_F("Ready"));
state = CONNECTED;
#ifdef BLYNK_DEBUG
if (size_t ram = BlynkFreeRam()) {
BLYNK_LOG2(BLYNK_F("Free RAM: "), ram);
}
#endif
this->sendInfo();
BLYNK_RUN_YIELD();
BlynkOnConnected();
}
sendCmd(BLYNK_CMD_RESPONSE, hdr.msg_id, NULL, BLYNK_SUCCESS);
} break;
case BLYNK_CMD_PING: {
sendCmd(BLYNK_CMD_RESPONSE, hdr.msg_id, NULL, BLYNK_SUCCESS);
} break;
case BLYNK_CMD_REDIRECT: {
if (!redir_serv) {
redir_serv = (char*)malloc(32);
}
BlynkParam param(inputBuffer, hdr.length);
uint16_t redir_port = BLYNK_DEFAULT_PORT; // TODO: Fixit
BlynkParam::iterator it = param.begin();
if (it >= param.end())
return false;
strncpy(redir_serv, it.asStr(), 32);
if (++it < param.end())
redir_port = it.asLong();
BLYNK_LOG4(BLYNK_F("Redirecting to "), redir_serv, ':', redir_port);
conn.disconnect();
conn.begin(redir_serv, redir_port);
state = CONNECTING;
lastHeartbeat = lastActivityIn = lastActivityOut = (BlynkMillis() - 5000UL);
} break;
case BLYNK_CMD_HARDWARE:
case BLYNK_CMD_BRIDGE: {
msgIdOutOverride = hdr.msg_id;
this->processCmd(inputBuffer, hdr.length);
msgIdOutOverride = 0;
} break;
case BLYNK_CMD_INTERNAL: {
BlynkReq req = { 0 };
BlynkParam param(inputBuffer, hdr.length);
BlynkParam::iterator it = param.begin();
if (it >= param.end())
return true;
uint32_t cmd32;
memcpy(&cmd32, it.asStr(), sizeof(cmd32));
++it;
char* start = (char*)(it).asStr();
unsigned length = hdr.length - (start - (char*)inputBuffer);
BlynkParam param2(start, length);
switch (cmd32) {
case BLYNK_INT_RTC: BlynkWidgetWriteInternalPinRTC(req, param2); break;
case BLYNK_INT_OTA: BlynkWidgetWriteInternalPinOTA(req, param2); break;
case BLYNK_INT_ACON: BlynkWidgetWriteInternalPinACON(req, param2); break;
case BLYNK_INT_ADIS: BlynkWidgetWriteInternalPinADIS(req, param2); break;
#ifdef BLYNK_DEBUG
default: BLYNK_LOG2(BLYNK_F("Invalid internal cmd:"), param.asStr());
#endif
}
} break;
case BLYNK_CMD_DEBUG_PRINT: {
if (hdr.length) {
BLYNK_LOG2(BLYNK_F("Server: "), (char*)inputBuffer);
}
} break;
default: {
#ifdef BLYNK_DEBUG
BLYNK_LOG2(BLYNK_F("Invalid header type: "), hdr.type);
#endif
// TODO: Flush
internalReconnect();
} break;
}
return true;
}
template <class Transp>
int BlynkProtocol<Transp>::readHeader(BlynkHeader& hdr)
{
size_t rlen = conn.read(&hdr, sizeof(hdr));
if (rlen == 0) {
return 0;
}
if (sizeof(hdr) != rlen) {
return -1;
}
BLYNK_DBG_DUMP(">", &hdr, sizeof(BlynkHeader));
hdr.msg_id = ntohs(hdr.msg_id);
hdr.length = ntohs(hdr.length);
return rlen;
}
#ifndef BLYNK_SEND_THROTTLE
#define BLYNK_SEND_THROTTLE 0
#endif
#ifndef BLYNK_SEND_CHUNK
#define BLYNK_SEND_CHUNK 1024 // Just a big number
#endif
template <class Transp>
void BlynkProtocol<Transp>::sendCmd(uint8_t cmd, uint16_t id, const void* data, size_t length, const void* data2, size_t length2)
{
if (!conn.connected() || (cmd != BLYNK_CMD_RESPONSE && cmd != BLYNK_CMD_PING && cmd != BLYNK_CMD_LOGIN && cmd != BLYNK_CMD_HW_LOGIN && state != CONNECTED) ) {
#ifdef BLYNK_DEBUG_ALL
BLYNK_LOG2(BLYNK_F("Cmd skipped:"), cmd);
#endif
return;
}
if (0 == id) {
id = getNextMsgId();
}
#if defined(BLYNK_MSG_LIMIT) && BLYNK_MSG_LIMIT > 0
if (cmd >= BLYNK_CMD_TWEET && cmd <= BLYNK_CMD_HARDWARE) {
const millis_time_t allowed_time = BlynkMax(lastActivityOut, lastActivityIn) + 1000/BLYNK_MSG_LIMIT;
int32_t wait_time = allowed_time - BlynkMillis();
if (wait_time >= 0) {
#ifdef BLYNK_DEBUG_ALL
BLYNK_LOG2(BLYNK_F("Waiting:"), wait_time);
#endif
while (wait_time >= 0) {
run();
wait_time = allowed_time - BlynkMillis();
}
} else if (nesting == 0) {
run();
}
}
#endif
const size_t full_length = (sizeof(BlynkHeader)) +
(data ? length : 0) +
(data2 ? length2 : 0);
#if defined(BLYNK_SEND_ATOMIC) || defined(ESP8266) || defined(ESP32) || defined(SPARK) || defined(PARTICLE) || defined(ENERGIA)
// Those have more RAM and like single write at a time...
uint8_t buff[full_length];
BlynkHeader* hdr = (BlynkHeader*)buff;
hdr->type = cmd;
hdr->msg_id = htons(id);
hdr->length = htons(length+length2);
size_t pos = sizeof(BlynkHeader);
if (data && length) {
memcpy(buff + pos, data, length);
pos += length;
}
if (data2 && length2) {
memcpy(buff + pos, data2, length2);
}
size_t wlen = 0;
while (wlen < full_length) {
const size_t chunk = BlynkMin(size_t(BLYNK_SEND_CHUNK), full_length - wlen);
BLYNK_DBG_DUMP("<", buff + wlen, chunk);
const size_t w = conn.write(buff + wlen, chunk);
BlynkDelay(BLYNK_SEND_THROTTLE);
if (w == 0) {
#ifdef BLYNK_DEBUG
BLYNK_LOG1(BLYNK_F("Cmd error"));
#endif
conn.disconnect();
state = CONNECTING;
BlynkOnDisconnected();
return;
}
wlen += w;
}
#else
BlynkHeader hdr;
hdr.type = cmd;
hdr.msg_id = htons(id);
hdr.length = htons(length+length2);
BLYNK_DBG_DUMP("<", &hdr, sizeof(hdr));
size_t wlen = conn.write(&hdr, sizeof(hdr));
BlynkDelay(BLYNK_SEND_THROTTLE);
if (cmd != BLYNK_CMD_RESPONSE) {
if (length) {
BLYNK_DBG_DUMP("<", data, length);
wlen += conn.write(data, length);
BlynkDelay(BLYNK_SEND_THROTTLE);
}
if (length2) {
BLYNK_DBG_DUMP("<", data2, length2);
wlen += conn.write(data2, length2);
BlynkDelay(BLYNK_SEND_THROTTLE);
}
}
#endif
if (wlen != full_length) {
#ifdef BLYNK_DEBUG
BLYNK_LOG4(BLYNK_F("Sent "), wlen, '/', full_length);
#endif
internalReconnect();
return;
}
lastActivityOut = BlynkMillis();
}
template <class Transp>
uint16_t BlynkProtocol<Transp>::getNextMsgId()
{
if (msgIdOutOverride != 0)
return msgIdOutOverride;
if (++msgIdOut == 0)
msgIdOut = 1;
return msgIdOut;
}
#endif

View File

@@ -0,0 +1,118 @@
/**
* @file BlynkProtocolDefs.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief Blynk protocol definitions
*
*/
#ifndef BlynkProtocolDefs_h
#define BlynkProtocolDefs_h
// Command definitions from:
// https://github.com/blynkkk/blynk-server/blob/master/server/core/src/main/java/cc/blynk/server/core/protocol/enums/Command.java
enum BlynkCmd
{
BLYNK_CMD_RESPONSE = 0,
BLYNK_CMD_LOGIN = 2,
BLYNK_CMD_PING = 6,
BLYNK_CMD_TWEET = 12,
BLYNK_CMD_EMAIL = 13,
BLYNK_CMD_NOTIFY = 14,
BLYNK_CMD_BRIDGE = 15,
BLYNK_CMD_HARDWARE_SYNC = 16,
BLYNK_CMD_INTERNAL = 17,
BLYNK_CMD_SMS = 18,
BLYNK_CMD_PROPERTY = 19,
BLYNK_CMD_HARDWARE = 20,
BLYNK_CMD_HW_LOGIN = 29,
BLYNK_CMD_REDIRECT = 41,
BLYNK_CMD_DEBUG_PRINT = 55,
BLYNK_CMD_EVENT_LOG = 64
};
enum BlynkStatus
{
BLYNK_SUCCESS = 200,
BLYNK_QUOTA_LIMIT_EXCEPTION = 1,
BLYNK_ILLEGAL_COMMAND = 2,
BLYNK_NOT_REGISTERED = 3,
BLYNK_ALREADY_REGISTERED = 4,
BLYNK_NOT_AUTHENTICATED = 5,
BLYNK_NOT_ALLOWED = 6,
BLYNK_DEVICE_NOT_IN_NETWORK = 7,
BLYNK_NO_ACTIVE_DASHBOARD = 8,
BLYNK_INVALID_TOKEN = 9,
BLYNK_ILLEGAL_COMMAND_BODY = 11,
BLYNK_GET_GRAPH_DATA_EXCEPTION = 12,
BLYNK_NO_DATA_EXCEPTION = 17,
BLYNK_DEVICE_WENT_OFFLINE = 18,
BLYNK_SERVER_EXCEPTION = 19,
BLYNK_NTF_INVALID_BODY = 13,
BLYNK_NTF_NOT_AUTHORIZED = 14,
BLYNK_NTF_ECXEPTION = 15,
BLYNK_TIMEOUT = 16,
BLYNK_NOT_SUPPORTED_VERSION = 20,
BLYNK_ENERGY_LIMIT = 21
};
struct BlynkHeader
{
uint8_t type;
uint16_t msg_id;
uint16_t length;
}
BLYNK_ATTR_PACKED;
#if !defined(htons) && (defined(ARDUINO) || defined(ESP8266) || defined(PARTICLE) || defined(__MBED__))
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define htons(x) ( ((x)<<8) | (((x)>>8)&0xFF) )
#define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \
((x)<< 8 & 0x00FF0000UL) | \
((x)>> 8 & 0x0000FF00UL) | \
((x)>>24 & 0x000000FFUL) )
#define ntohs(x) htons(x)
#define ntohl(x) htonl(x)
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define htons(x) (x)
#define htonl(x) (x)
#define ntohs(x) (x)
#define ntohl(x) (x)
#else
#error byte order problem
#endif
#endif
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define BLYNK_STR_16(a,b) ((uint16_t(a) << 0) | (uint16_t(b) << 8))
#define BLYNK_STR_32(a,b,c,d) ((uint32_t(a) << 0) | (uint32_t(b) << 8) | (uint32_t(c) << 16) | (uint32_t(d) << 24))
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define BLYNK_STR_16(a,b) ((uint16_t(b) << 0) | (uint16_t(a) << 8))
#define BLYNK_STR_32(a,b,c,d) ((uint32_t(d) << 0) | (uint32_t(c) << 8) | (uint32_t(b) << 16) | (uint32_t(a) << 24))
#else
#error byte order problem
#endif
#define BLYNK_HW_PM BLYNK_STR_16('p','m')
#define BLYNK_HW_DW BLYNK_STR_16('d','w')
#define BLYNK_HW_DR BLYNK_STR_16('d','r')
#define BLYNK_HW_AW BLYNK_STR_16('a','w')
#define BLYNK_HW_AR BLYNK_STR_16('a','r')
#define BLYNK_HW_VW BLYNK_STR_16('v','w')
#define BLYNK_HW_VR BLYNK_STR_16('v','r')
#define BLYNK_INT_RTC BLYNK_STR_32('r','t','c',0)
#define BLYNK_INT_OTA BLYNK_STR_32('o','t','a',0)
#define BLYNK_INT_ACON BLYNK_STR_32('a','c','o','n')
#define BLYNK_INT_ADIS BLYNK_STR_32('a','d','i','s')
#endif

View File

@@ -0,0 +1,47 @@
class BlynkStackOnly
{
protected:
BlynkStackOnly() {}
~BlynkStackOnly() {}
private:
/// @brief Declared as private to prevent usage of dynamic memory
void* operator new(size_t size);
/// @brief Declared as private to prevent usage of dynamic memory
void operator delete(void *p);
};
class BlynkNonCopyable
{
protected:
BlynkNonCopyable(){}
~BlynkNonCopyable(){}
private:
/// @brief Declared as private to prevent usage of copy constructor
BlynkNonCopyable(const BlynkNonCopyable&);
/// @brief Declared as private to prevent usage of assignment operator
BlynkNonCopyable& operator=(const BlynkNonCopyable&);
};
template<typename T>
class BlynkSingleton
: public BlynkNonCopyable
{
public:
/** @brief Returns the instance of the singleton type
When called for the first time, the singleton instance will be
created. All subsequent calls will return a reference to the
previously created instance.
@return The singleton instance
*/
static T* instance()
{
static T instance;
return &instance;
}
protected:
BlynkSingleton() {}
~BlynkSingleton() {}
};

View File

@@ -0,0 +1,155 @@
/*
* SimpleTimer.h
*
* SimpleTimer - A timer library for Arduino.
* Author: mromani@ottotecnica.com
* Copyright (c) 2010 OTTOTECNICA Italy
*
* Modifications by Bill Knight <billk@rosw.com> 18March2017
*
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser
* General Public License as published by the Free Software
* Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser
* General Public License along with this library; if not,
* write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef BLYNKTIMER_H
#define BLYNKTIMER_H
#include <Blynk/BlynkDebug.h>
// Replace SimpleTimer
#define SIMPLETIMER_H
#define SimpleTimer BlynkTimer
typedef void (*timer_callback)(void);
typedef void (*timer_callback_p)(void *);
class SimpleTimer {
public:
// maximum number of timers
const static int MAX_TIMERS = 16;
// setTimer() constants
const static int RUN_FOREVER = 0;
const static int RUN_ONCE = 1;
// constructor
SimpleTimer();
void init();
// this function must be called inside loop()
void run();
// Timer will call function 'f' every 'd' milliseconds forever
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setInterval(unsigned long d, timer_callback f);
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds forever
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setInterval(unsigned long d, timer_callback_p f, void* p);
// Timer will call function 'f' after 'd' milliseconds one time
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setTimeout(unsigned long d, timer_callback f);
// Timer will call function 'f' with parameter 'p' after 'd' milliseconds one time
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setTimeout(unsigned long d, timer_callback_p f, void* p);
// Timer will call function 'f' every 'd' milliseconds 'n' times
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setTimer(unsigned long d, timer_callback f, unsigned n);
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds 'n' times
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setTimer(unsigned long d, timer_callback_p f, void* p, unsigned n);
// updates interval of the specified timer
bool changeInterval(unsigned numTimer, unsigned long d);
// destroy the specified timer
void deleteTimer(unsigned numTimer);
// restart the specified timer
void restartTimer(unsigned numTimer);
// returns true if the specified timer is enabled
bool isEnabled(unsigned numTimer);
// enables the specified timer
void enable(unsigned numTimer);
// disables the specified timer
void disable(unsigned numTimer);
// enables all timers
void enableAll();
// disables all timers
void disableAll();
// enables the specified timer if it's currently disabled,
// and vice-versa
void toggle(unsigned numTimer);
// returns the number of used timers
unsigned getNumTimers();
// returns the number of available timers
unsigned getNumAvailableTimers() { return MAX_TIMERS - numTimers; };
private:
// deferred call constants
const static int DEFCALL_DONTRUN = 0; // don't call the callback function
const static int DEFCALL_RUNONLY = 1; // call the callback function but don't delete the timer
const static int DEFCALL_RUNANDDEL = 2; // call the callback function and delete the timer
// low level function to initialize and enable a new timer
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setupTimer(unsigned long d, void* f, void* p, bool h, unsigned n);
// find the first available slot
int findFirstFreeSlot();
typedef struct {
unsigned long prev_millis; // value returned by the millis() function in the previous run() call
void* callback; // pointer to the callback function
void* param; // function parameter
bool hasParam; // true if callback takes a parameter
unsigned long delay; // delay value
unsigned maxNumRuns; // number of runs to be executed
unsigned numRuns; // number of executed runs
bool enabled; // true if enabled
unsigned toBeCalled; // deferred function call (sort of) - N.B.: only used in run()
} timer_t;
timer_t timer[MAX_TIMERS];
// actual number of timers in use (-1 means uninitialized)
int numTimers;
};
#endif

View File

@@ -0,0 +1,62 @@
/**
* @file BlynkWidgetBase.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
* @date Nov 2016
* @brief
*/
#ifndef BlynkWidgetBase_h
#define BlynkWidgetBase_h
#include <Blynk/BlynkApi.h>
class BlynkWidgetBase
{
public:
BlynkWidgetBase(uint8_t vPin) : mPin(vPin) {}
void setVPin(uint8_t vPin) { mPin = vPin; }
void onWrite(BlynkReq BLYNK_UNUSED &request, const BlynkParam BLYNK_UNUSED &param) {
BLYNK_LOG1(BLYNK_F("BlynkWidgetBase::onWrite should not be called"));
}
template<typename... Args>
void setLabel(Args... args) {
Blynk.setProperty(mPin, "label", args...);
}
template<typename... Args>
void setColor(Args... args) {
Blynk.setProperty(mPin, "color", args...);
}
template<typename... Args>
void setMin(Args... args) {
Blynk.setProperty(mPin, "min", args...);
}
template<typename... Args>
void setMax(Args... args) {
Blynk.setProperty(mPin, "max", args...);
}
protected:
uint8_t mPin;
};
class BlynkAttachWidgetHelper {
public:
template<typename T>
explicit BlynkAttachWidgetHelper(T& widget, uint8_t vPin) {
widget.setVPin(vPin);
}
};
// Could use __attribute__ ((constructor)), but hope for better portability
#define BLYNK_ATTACH_WIDGET(widget, pin) \
BlynkAttachWidgetHelper BLYNK_CONCAT2(blnk_widget_helper_, __COUNTER__)((widget), (pin)); \
BLYNK_WRITE(pin) { (widget).onWrite(request, param); }
#endif

View File

@@ -0,0 +1,200 @@
/**
* @file BlynkApiArduino.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*
*/
#ifndef BlynkApiArduino_h
#define BlynkApiArduino_h
#include <Blynk/BlynkApi.h>
#include <Arduino.h>
#ifdef BLYNK_NO_INFO
template<class Proto>
BLYNK_FORCE_INLINE
void BlynkApi<Proto>::sendInfo() {}
#else
template<class Proto>
BLYNK_FORCE_INLINE
void BlynkApi<Proto>::sendInfo()
{
static const char profile[] BLYNK_PROGMEM = "blnkinf\0"
BLYNK_PARAM_KV("ver" , BLYNK_VERSION)
BLYNK_PARAM_KV("h-beat" , BLYNK_TOSTRING(BLYNK_HEARTBEAT))
BLYNK_PARAM_KV("buff-in", BLYNK_TOSTRING(BLYNK_MAX_READBYTES))
#ifdef BLYNK_INFO_DEVICE
BLYNK_PARAM_KV("dev" , BLYNK_INFO_DEVICE)
#endif
#ifdef BLYNK_INFO_CPU
BLYNK_PARAM_KV("cpu" , BLYNK_INFO_CPU)
#endif
#ifdef BLYNK_INFO_CONNECTION
BLYNK_PARAM_KV("con" , BLYNK_INFO_CONNECTION)
#endif
#ifdef BOARD_FIRMWARE_VERSION
BLYNK_PARAM_KV("fw" , BOARD_FIRMWARE_VERSION)
#endif
BLYNK_PARAM_KV("build" , __DATE__ " " __TIME__)
"\0"
;
const size_t profile_len = sizeof(profile)-8-2;
char mem_dyn[64];
BlynkParam profile_dyn(mem_dyn, 0, sizeof(mem_dyn));
#ifdef BOARD_TEMPLATE_ID
profile_dyn.add_key("tmpl", BOARD_TEMPLATE_ID);
#endif
#ifdef BLYNK_HAS_PROGMEM
char mem[profile_len];
memcpy_P(mem, profile+8, profile_len);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_INTERNAL, 0, mem, profile_len, profile_dyn.getBuffer(), profile_dyn.getLength());
#else
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_INTERNAL, 0, profile+8, profile_len, profile_dyn.getBuffer(), profile_dyn.getLength());
#endif
return;
}
#endif
// Check if analog pins can be referenced by name on this device
#if defined(analogInputToDigitalPin)
#define BLYNK_DECODE_PIN(it) (((it).asStr()[0] == 'A') ? analogInputToDigitalPin(atoi((it).asStr()+1)) : (it).asInt())
#else
#define BLYNK_DECODE_PIN(it) ((it).asInt())
#if defined(BLYNK_DEBUG_ALL)
#pragma message "analogInputToDigitalPin not defined"
#endif
#endif
template<class Proto>
BLYNK_FORCE_INLINE
void BlynkApi<Proto>::processCmd(const void* buff, size_t len)
{
BlynkParam param((void*)buff, len);
BlynkParam::iterator it = param.begin();
if (it >= param.end())
return;
const char* cmd = it.asStr();
uint16_t cmd16;
memcpy(&cmd16, cmd, sizeof(cmd16));
if (++it >= param.end())
return;
uint8_t pin = BLYNK_DECODE_PIN(it);
switch(cmd16) {
#ifndef BLYNK_NO_BUILTIN
case BLYNK_HW_PM: {
while (it < param.end()) {
pin = BLYNK_DECODE_PIN(it);
++it;
if (!strcmp(it.asStr(), "in")) {
pinMode(pin, INPUT);
} else if (!strcmp(it.asStr(), "out") || !strcmp(it.asStr(), "pwm")) {
pinMode(pin, OUTPUT);
#ifdef INPUT_PULLUP
} else if (!strcmp(it.asStr(), "pu")) {
pinMode(pin, INPUT_PULLUP);
#endif
#ifdef INPUT_PULLDOWN
} else if (!strcmp(it.asStr(), "pd")) {
pinMode(pin, INPUT_PULLDOWN);
#endif
} else {
#ifdef BLYNK_DEBUG
BLYNK_LOG4(BLYNK_F("Invalid pin "), pin, BLYNK_F(" mode "), it.asStr());
#endif
}
++it;
}
} break;
case BLYNK_HW_DR: {
char mem[16];
BlynkParam rsp(mem, 0, sizeof(mem));
rsp.add("dw");
rsp.add(pin);
rsp.add(digitalRead(pin));
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE, 0, rsp.getBuffer(), rsp.getLength()-1);
} break;
case BLYNK_HW_DW: {
// Should be 1 parameter (value)
if (++it >= param.end())
return;
#ifdef ESP8266
// Disable PWM...
analogWrite(pin, 0);
#endif
#ifndef BLYNK_MINIMIZE_PINMODE_USAGE
pinMode(pin, OUTPUT);
#endif
digitalWrite(pin, it.asInt() ? HIGH : LOW);
} break;
case BLYNK_HW_AR: {
char mem[16];
BlynkParam rsp(mem, 0, sizeof(mem));
rsp.add("aw");
rsp.add(pin);
rsp.add(analogRead(pin));
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE, 0, rsp.getBuffer(), rsp.getLength()-1);
} break;
// TODO: Remove workaround for ESP32
#if !defined(ESP32)
case BLYNK_HW_AW: {
// Should be 1 parameter (value)
if (++it >= param.end())
return;
#ifndef BLYNK_MINIMIZE_PINMODE_USAGE
pinMode(pin, OUTPUT);
#endif
analogWrite(pin, it.asInt());
} break;
#endif // TODO: Remove workaround for ESP32
#endif
case BLYNK_HW_VR: {
BlynkReq req = { pin };
WidgetReadHandler handler = GetReadHandler(pin);
if (handler && (handler != BlynkWidgetRead)) {
handler(req);
} else {
BlynkWidgetReadDefault(req);
}
} break;
case BLYNK_HW_VW: {
++it;
char* start = (char*)it.asStr();
BlynkParam param2(start, len - (start - (char*)buff));
BlynkReq req = { pin };
WidgetWriteHandler handler = GetWriteHandler(pin);
if (handler && (handler != BlynkWidgetWrite)) {
handler(req, param2);
} else {
BlynkWidgetWriteDefault(req, param2);
}
} break;
default:
BLYNK_LOG2(BLYNK_F("Invalid HW cmd: "), cmd);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_RESPONSE, static_cast<Proto*>(this)->msgIdOutOverride, NULL, BLYNK_ILLEGAL_COMMAND);
}
}
#endif

View File

@@ -0,0 +1,176 @@
/**
* @file BlynkApiMbed.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*
*/
#ifndef BlynkApiMbed_h
#define BlynkApiMbed_h
#include <Blynk/BlynkApi.h>
#include <mbed.h>
#ifdef BLYNK_NO_INFO
template<class Proto>
BLYNK_FORCE_INLINE
void BlynkApi<Proto>::sendInfo() {}
#else
template<class Proto>
BLYNK_FORCE_INLINE
void BlynkApi<Proto>::sendInfo()
{
static const char profile[] BLYNK_PROGMEM = "blnkinf\0"
BLYNK_PARAM_KV("ver" , BLYNK_VERSION)
BLYNK_PARAM_KV("h-beat" , BLYNK_TOSTRING(BLYNK_HEARTBEAT))
BLYNK_PARAM_KV("buff-in", BLYNK_TOSTRING(BLYNK_MAX_READBYTES))
#ifdef BLYNK_INFO_DEVICE
BLYNK_PARAM_KV("dev" , BLYNK_INFO_DEVICE)
#endif
#ifdef BLYNK_INFO_CPU
BLYNK_PARAM_KV("cpu" , BLYNK_INFO_CPU)
#endif
#ifdef BLYNK_INFO_CONNECTION
BLYNK_PARAM_KV("con" , BLYNK_INFO_CONNECTION)
#endif
#ifdef BOARD_FIRMWARE_VERSION
BLYNK_PARAM_KV("fw" , BOARD_FIRMWARE_VERSION)
#endif
BLYNK_PARAM_KV("build" , __DATE__ " " __TIME__)
"\0"
;
const size_t profile_len = sizeof(profile)-8-2;
char mem_dyn[64];
BlynkParam profile_dyn(mem_dyn, 0, sizeof(mem_dyn));
#ifdef BOARD_TEMPLATE_ID
profile_dyn.add_key("tmpl", BOARD_TEMPLATE_ID);
#endif
#ifdef BLYNK_HAS_PROGMEM
char mem[profile_len];
memcpy_P(mem, profile+8, profile_len);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_INTERNAL, 0, mem, profile_len, profile_dyn.getBuffer(), profile_dyn.getLength());
#else
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_INTERNAL, 0, profile+8, profile_len, profile_dyn.getBuffer(), profile_dyn.getLength());
#endif
return;
}
#endif
// Check if analog pins can be referenced by name on this device
#if defined(analogInputToDigitalPin)
#define BLYNK_DECODE_PIN(it) (((it).asStr()[0] == 'A') ? analogInputToDigitalPin(atoi((it).asStr()+1)) : (it).asInt())
#else
#define BLYNK_DECODE_PIN(it) ((it).asInt())
#if defined(BLYNK_DEBUG_ALL)
#pragma message "analogInputToDigitalPin not defined"
#endif
#endif
template<class Proto>
BLYNK_FORCE_INLINE
void BlynkApi<Proto>::processCmd(const void* buff, size_t len)
{
BlynkParam param((void*)buff, len);
BlynkParam::iterator it = param.begin();
if (it >= param.end())
return;
const char* cmd = it.asStr();
uint16_t cmd16;
memcpy(&cmd16, cmd, sizeof(cmd16));
if (++it >= param.end())
return;
uint8_t pin = BLYNK_DECODE_PIN(it);
switch(cmd16) {
#ifndef BLYNK_NO_BUILTIN
case BLYNK_HW_PM: {
while (it < param.end()) {
pin = BLYNK_DECODE_PIN(it);
++it;
if (!strcmp(it.asStr(), "in")) {
//pinMode(pin, INPUT);
} else if (!strcmp(it.asStr(), "out") || !strcmp(it.asStr(), "pwm")) {
//pinMode(pin, OUTPUT);
} else {
#ifdef BLYNK_DEBUG
BLYNK_LOG4(BLYNK_F("Invalid pin "), pin, BLYNK_F(" mode "), it.asStr());
#endif
}
++it;
}
} break;
case BLYNK_HW_DR: {
DigitalIn p((PinName)pin);
char mem[16];
BlynkParam rsp(mem, 0, sizeof(mem));
rsp.add("dw");
rsp.add(pin);
rsp.add(int(p));
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE, 0, rsp.getBuffer(), rsp.getLength()-1);
} break;
case BLYNK_HW_DW: {
// Should be 1 parameter (value)
if (++it >= param.end())
return;
//BLYNK_LOG("digitalWrite %d -> %d", pin, it.asInt());
DigitalOut p((PinName)pin);
p = it.asInt() ? 1 : 0;
} break;
case BLYNK_HW_AR: {
AnalogIn p((PinName)pin);
char mem[16];
BlynkParam rsp(mem, 0, sizeof(mem));
rsp.add("aw");
rsp.add(pin);
rsp.add(int(p.read() * 1024));
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE, 0, rsp.getBuffer(), rsp.getLength()-1);
} break;
case BLYNK_HW_AW: {
// TODO: Not supported yet
} break;
#endif
case BLYNK_HW_VR: {
BlynkReq req = { pin };
WidgetReadHandler handler = GetReadHandler(pin);
if (handler && (handler != BlynkWidgetRead)) {
handler(req);
} else {
BlynkWidgetReadDefault(req);
}
} break;
case BLYNK_HW_VW: {
++it;
char* start = (char*)it.asStr();
BlynkParam param2(start, len - (start - (char*)buff));
BlynkReq req = { pin };
WidgetWriteHandler handler = GetWriteHandler(pin);
if (handler && (handler != BlynkWidgetWrite)) {
handler(req, param2);
} else {
BlynkWidgetWriteDefault(req, param2);
}
} break;
default:
BLYNK_LOG2(BLYNK_F("Invalid HW cmd: "), cmd);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_RESPONSE, static_cast<Proto*>(this)->msgIdOutOverride, NULL, BLYNK_ILLEGAL_COMMAND);
}
}
#endif

View File

@@ -0,0 +1,194 @@
/**
* @file BlynkApiParticle.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*
*/
#ifndef BlynkApiParticle_h
#define BlynkApiParticle_h
#include "Blynk/BlynkApi.h"
#include "Particle.h"
#ifdef BLYNK_NO_INFO
template<class Proto>
BLYNK_FORCE_INLINE
void BlynkApi<Proto>::sendInfo() {}
#else
template<class Proto>
BLYNK_FORCE_INLINE
void BlynkApi<Proto>::sendInfo()
{
static const char profile[] BLYNK_PROGMEM = "blnkinf\0"
BLYNK_PARAM_KV("ver" , BLYNK_VERSION)
BLYNK_PARAM_KV("h-beat" , BLYNK_TOSTRING(BLYNK_HEARTBEAT))
BLYNK_PARAM_KV("buff-in", BLYNK_TOSTRING(BLYNK_MAX_READBYTES))
#ifdef BLYNK_INFO_DEVICE
BLYNK_PARAM_KV("dev" , BLYNK_INFO_DEVICE)
#endif
#ifdef BLYNK_INFO_CPU
BLYNK_PARAM_KV("cpu" , BLYNK_INFO_CPU)
#endif
#ifdef BLYNK_INFO_CONNECTION
BLYNK_PARAM_KV("con" , BLYNK_INFO_CONNECTION)
#endif
#ifdef BOARD_FIRMWARE_VERSION
BLYNK_PARAM_KV("fw" , BOARD_FIRMWARE_VERSION)
#endif
BLYNK_PARAM_KV("build" , __DATE__ " " __TIME__)
"\0"
;
const size_t profile_len = sizeof(profile)-8-2;
char mem_dyn[64];
BlynkParam profile_dyn(mem_dyn, 0, sizeof(mem_dyn));
#ifdef BOARD_TEMPLATE_ID
profile_dyn.add_key("tmpl", BOARD_TEMPLATE_ID);
#endif
#ifdef BLYNK_HAS_PROGMEM
char mem[profile_len];
memcpy_P(mem, profile+8, profile_len);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_INTERNAL, 0, mem, profile_len, profile_dyn.getBuffer(), profile_dyn.getLength());
#else
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_INTERNAL, 0, profile+8, profile_len, profile_dyn.getBuffer(), profile_dyn.getLength());
#endif
return;
}
#endif
// Check if analog pins can be referenced by name on this device
#if defined(analogInputToDigitalPin)
#define BLYNK_DECODE_PIN(it) (((it).asStr()[0] == 'A') ? analogInputToDigitalPin(atoi((it).asStr()+1)) : (it).asInt())
#else
#define BLYNK_DECODE_PIN(it) ((it).asInt())
#if defined(BLYNK_DEBUG_ALL)
#pragma message "analogInputToDigitalPin not defined"
#endif
#endif
template<class Proto>
BLYNK_FORCE_INLINE
void BlynkApi<Proto>::processCmd(const void* buff, size_t len)
{
BlynkParam param((void*)buff, len);
BlynkParam::iterator it = param.begin();
if (it >= param.end())
return;
const char* cmd = it.asStr();
uint16_t cmd16;
memcpy(&cmd16, cmd, sizeof(cmd16));
if (++it >= param.end())
return;
uint8_t pin = BLYNK_DECODE_PIN(it);
switch(cmd16) {
#ifndef BLYNK_NO_BUILTIN
case BLYNK_HW_PM: {
while (it < param.end()) {
pin = BLYNK_DECODE_PIN(it);
++it;
if (!strcmp(it.asStr(), "in")) {
pinMode(pin, INPUT);
} else if (!strcmp(it.asStr(), "out") || !strcmp(it.asStr(), "pwm")) {
pinMode(pin, OUTPUT);
#ifdef INPUT_PULLUP
} else if (!strcmp(it.asStr(), "pu")) {
pinMode(pin, INPUT_PULLUP);
#endif
#ifdef INPUT_PULLDOWN
} else if (!strcmp(it.asStr(), "pd")) {
pinMode(pin, INPUT_PULLDOWN);
#endif
} else {
#ifdef BLYNK_DEBUG
BLYNK_LOG4(BLYNK_F("Invalid pin "), pin, BLYNK_F(" mode "), it.asStr());
#endif
}
++it;
}
} break;
case BLYNK_HW_DR: {
char mem[16];
BlynkParam rsp(mem, 0, sizeof(mem));
rsp.add("dw");
rsp.add(pin);
rsp.add(digitalRead(pin));
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE, 0, rsp.getBuffer(), rsp.getLength()-1);
} break;
case BLYNK_HW_DW: {
// Should be 1 parameter (value)
if (++it >= param.end())
return;
#ifdef ESP8266
// Disable PWM...
analogWrite(pin, 0);
#endif
#ifndef BLYNK_MINIMIZE_PINMODE_USAGE
pinMode(pin, OUTPUT);
#endif
digitalWrite(pin, it.asInt() ? HIGH : LOW);
} break;
case BLYNK_HW_AR: {
char mem[16];
BlynkParam rsp(mem, 0, sizeof(mem));
rsp.add("aw");
rsp.add(pin);
rsp.add(analogRead(pin));
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE, 0, rsp.getBuffer(), rsp.getLength()-1);
} break;
case BLYNK_HW_AW: {
// Should be 1 parameter (value)
if (++it >= param.end())
return;
#ifndef BLYNK_MINIMIZE_PINMODE_USAGE
pinMode(pin, OUTPUT);
#endif
analogWrite(pin, it.asInt());
} break;
#endif
case BLYNK_HW_VR: {
BlynkReq req = { pin };
WidgetReadHandler handler = GetReadHandler(pin);
if (handler && (handler != BlynkWidgetRead)) {
handler(req);
} else {
BlynkWidgetReadDefault(req);
}
} break;
case BLYNK_HW_VW: {
++it;
char* start = (char*)it.asStr();
BlynkParam param2(start, len - (start - (char*)buff));
BlynkReq req = { pin };
WidgetWriteHandler handler = GetWriteHandler(pin);
if (handler && (handler != BlynkWidgetWrite)) {
handler(req, param2);
} else {
BlynkWidgetWriteDefault(req, param2);
}
} break;
default:
BLYNK_LOG2(BLYNK_F("Invalid HW cmd: "), cmd);
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_RESPONSE, static_cast<Proto*>(this)->msgIdOutOverride, NULL, BLYNK_ILLEGAL_COMMAND);
}
}
#endif

View File

@@ -0,0 +1,113 @@
/**
* @file BlynkParticle.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*
*/
#ifndef BlynkParticle_h
#define BlynkParticle_h
#include "BlynkApiParticle.h"
#include "Blynk/BlynkProtocol.h"
class BlynkTransportParticle
{
public:
BlynkTransportParticle()
: domain(NULL), port(0)
{}
void begin(IPAddress a, uint16_t p) {
domain = NULL;
port = p;
addr = a;
}
void begin(const char* d, uint16_t p) {
domain = d;
port = p;
}
bool connect() {
if (domain) {
BLYNK_LOG4(BLYNK_F("Connecting to "), domain, ':', port);
return (1 == client.connect(domain, port));
} else {
BLYNK_LOG_IP("Connecting to ", addr);
return (1 == client.connect(addr, port));
}
return 0;
}
void disconnect() { client.stop(); }
size_t read(void* buf, size_t len) {
return client.readBytes((char*)buf, len);
}
size_t write(const void* buf, size_t len) {
return client.write((const uint8_t*)buf, len);
}
void flush() { client.flush(); }
bool connected() { return client.connected(); }
int available() { return client.available(); }
private:
TCPClient client;
IPAddress addr;
const char* domain;
uint16_t port;
};
class BlynkParticle
: public BlynkProtocol<BlynkTransportParticle>
{
typedef BlynkProtocol<BlynkTransportParticle> Base;
public:
BlynkParticle(BlynkTransportParticle& transp)
: Base(transp)
{}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress addr,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(addr, port);
}
void begin( const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
BlynkDelay(3000); // Give the board time to settle
config(auth, domain, port);
while(this->connect() != true) {}
}
void begin( const char* auth,
IPAddress addr,
uint16_t port = BLYNK_DEFAULT_PORT)
{
BlynkDelay(3000); // Give the board time to settle
config(auth, addr, port);
while(this->connect() != true) {}
}
private:
};
#endif

View File

@@ -0,0 +1,21 @@
/**
* @file BlynkSimpleBLEPeripheral.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
* @date Mar 2016
* @brief
*
*/
#ifndef BlynkSimpleBLEPeripheral_h
#define BlynkSimpleBLEPeripheral_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "BLEPeripheral"
#endif
#include <BlynkSimpleSerialBLE.h>
#include <Adapters/BlynkBLEPeripheralSerial.h>
#endif

View File

@@ -0,0 +1,26 @@
/**
* @file BlynkSimpleCC3000.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*/
#ifndef BlynkSimpleCC3000_h
#define BlynkSimpleCC3000_h
#include <Adapters/BlynkCC3000.h>
#include <Adafruit_CC3000.h>
// Use hardware SPI for the remaining pins
// SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIVIDER); // you can change this clock speed
static BlynkTransportCC3000 _blynkTransport(cc3000);
BlynkCC3000 Blynk(cc3000, _blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,171 @@
/**
* @file BlynkSimpleCurieBLE.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date May 2016
* @brief
*
*/
#ifndef BlynkSimpleCurieBLE_h
#define BlynkSimpleCurieBLE_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "CurieBLE"
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 20
//#define BLYNK_SEND_THROTTLE 20
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <utility/BlynkFifo.h>
#include <CurieBLE.h>
class BlynkTransportCurieBLE
{
public:
BlynkTransportCurieBLE()
: mConn (false)
{}
// IP redirect not available
void begin(char BLYNK_UNUSED *h, uint16_t BLYNK_UNUSED p) {}
void begin(BLEPeripheral& per) {
instance = this;
blePeripheral = &per;
// Add service and characteristic
blePeripheral->setAdvertisedServiceUuid(bleService.uuid());
blePeripheral->addAttribute(bleService);
blePeripheral->addAttribute(rxChar);
blePeripheral->addAttribute(txChar);
unsigned char empty[0] = {};
rxChar.setValue(empty, 0);
txChar.setValue(empty, 0);
// Assign event handlers for connected, disconnected to peripheral
blePeripheral->setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
rxChar.setEventHandler(BLEWritten, rxCharWritten);
txChar.setEventHandler(BLESubscribed, txCharSubscribed);
}
bool connect() {
mBuffRX.clear();
return mConn = true;
}
void disconnect() {
mConn = false;
}
bool connected() {
return mConn;
}
size_t read(void* buf, size_t len) {
uint32_t start = millis();
while (millis() - start < BLYNK_TIMEOUT_MS) {
if (available() < len) {
blePeripheral->poll();
} else {
break;
}
}
uint32_t key = interrupt_lock();
size_t res = mBuffRX.get((uint8_t*)buf, len);
interrupt_unlock(key);
return res;
}
size_t write(const void* buf, size_t len) {
txChar.setValue((uint8_t*)buf, len);
return len;
}
size_t available() {
uint32_t key = interrupt_lock();
size_t rxSize = mBuffRX.size();
interrupt_unlock(key);
return rxSize;
}
private:
static BlynkTransportCurieBLE* instance;
static
void rxCharWritten(BLECentral& central, BLECharacteristic& ch) {
if (!instance)
return;
uint32_t key = interrupt_lock();
const uint8_t* data = ch.value();
uint32_t len = ch.valueLength();
//BLYNK_DBG_DUMP(">> ", data, len);
instance->mBuffRX.put(data, len);
interrupt_unlock(key);
}
static
void txCharSubscribed(BLECentral& central, BLECharacteristic& ch);
static
void blePeripheralDisconnectHandler(BLECentral& central);
private:
bool mConn;
BLEPeripheral* blePeripheral = NULL;
BLEService bleService = BLEService ("713D0000-503E-4C75-BA94-3148F18D941E");
BLECharacteristic rxChar = BLECharacteristic("713D0003-503E-4C75-BA94-3148F18D941E", BLEWrite | BLEWriteWithoutResponse, BLE_MAX_ATTR_DATA_LEN);
BLECharacteristic txChar = BLECharacteristic("713D0002-503E-4C75-BA94-3148F18D941E", BLERead | BLENotify, BLE_MAX_ATTR_DATA_LEN);
BlynkFifo<uint8_t, BLYNK_MAX_READBYTES*2> mBuffRX;
};
class BlynkCurieBLE
: public BlynkProtocol<BlynkTransportCurieBLE>
{
typedef BlynkProtocol<BlynkTransportCurieBLE> Base;
public:
BlynkCurieBLE(BlynkTransportCurieBLE& transp)
: Base(transp)
{}
void begin(BLEPeripheral& per, const char* auth)
{
Base::begin(auth);
state = DISCONNECTED;
conn.begin(per);
}
// Please use Blynk.begin(BLEPeripheral, "auth")
BLYNK_DEPRECATED
void begin(const char* auth, BLEPeripheral& per)
{
Base::begin(auth);
state = DISCONNECTED;
conn.begin(per);
}
};
BlynkTransportCurieBLE* BlynkTransportCurieBLE::instance = NULL;
static BlynkTransportCurieBLE _blynkTransport;
BlynkCurieBLE Blynk(_blynkTransport);
inline
void BlynkTransportCurieBLE::txCharSubscribed(BLECentral& central, BLECharacteristic& ch) {
Blynk.startSession();
}
inline
void BlynkTransportCurieBLE::blePeripheralDisconnectHandler(BLECentral& central) {
Blynk.disconnect();
}
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,24 @@
/**
* @file BlynkSimpleEnergiaEthernet.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Oct 2016
* @brief
*
*/
#ifndef BlynkSimpleEnergiaEthernet_h
#define BlynkSimpleEnergiaEthernet_h
#include <Ethernet.h>
#include <EthernetClient.h>
#include <Adapters/BlynkEthernet.h>
static EthernetClient _blynkEthernetClient;
static BlynkArduinoClient _blynkTransport(_blynkEthernetClient);
BlynkEthernet Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,23 @@
/**
* @file BlynkSimpleEnergiaWiFi.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkSimpleEnergiaWiFi_h
#define BlynkSimpleEnergiaWiFi_h
#include <WiFi.h>
#include <Adapters/BlynkWiFiCommon.h>
static WiFiClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkWifiCommon Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,98 @@
/**
* @file BlynkSimpleEsp32.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Oct 2016
* @brief
*
*/
#ifndef BlynkSimpleEsp32_h
#define BlynkSimpleEsp32_h
#ifndef ESP32
#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
#endif
#define BLYNK_SEND_ATOMIC
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <WiFi.h>
class BlynkWifi
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkWifi(BlynkArduinoClient& transp)
: Base(transp)
{}
void connectWiFi(const char* ssid, const char* pass)
{
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
WiFi.mode(WIFI_STA);
if (pass && strlen(pass)) {
WiFi.begin(ssid, pass);
} else {
WiFi.begin(ssid);
}
while (WiFi.status() != WL_CONNECTED) {
BlynkDelay(500);
}
BLYNK_LOG1(BLYNK_F("Connected to WiFi"));
IPAddress myip = WiFi.localIP();
BLYNK_LOG_IP("IP: ", myip);
}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(ip, port);
}
void begin(const char* auth,
const char* ssid,
const char* pass,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass);
config(auth, domain, port);
while(this->connect() != true) {}
}
void begin(const char* auth,
const char* ssid,
const char* pass,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass);
config(auth, ip, port);
while(this->connect() != true) {}
}
};
static WiFiClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkWifi Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,197 @@
/**
* @file BlynkSimpleEsp32_BLE.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Nov 2017
* @brief
*
*/
#ifndef BlynkSimpleEsp32_BLE_h
#define BlynkSimpleEsp32_BLE_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "Esp32_BLE"
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 20
//#define BLYNK_SEND_THROTTLE 20
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <utility/BlynkFifo.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#define SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E"
#define CHARACTERISTIC_UUID_RX "713D0003-503E-4C75-BA94-3148F18D941E"
#define CHARACTERISTIC_UUID_TX "713D0002-503E-4C75-BA94-3148F18D941E"
class BlynkTransportEsp32_BLE :
public BLEServerCallbacks,
public BLECharacteristicCallbacks
{
public:
BlynkTransportEsp32_BLE()
: mConn (false)
, mName ("Blynk")
{}
void setDeviceName(const char* name) {
mName = name;
}
// IP redirect not available
void begin(char BLYNK_UNUSED *h, uint16_t BLYNK_UNUSED p) {}
void begin() {
// Create the BLE Device
BLEDevice::init(mName);
// Create the BLE Server
pServer = BLEDevice::createServer();
pServer->setCallbacks(this);
// Create the BLE Service
pService = pServer->createService(SERVICE_UUID);
// Create a BLE Characteristic
pCharacteristicTX = pService->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_NOTIFY
);
pCharacteristicTX->addDescriptor(new BLE2902());
pCharacteristicRX = pService->createCharacteristic(
CHARACTERISTIC_UUID_RX,
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristicRX->setCallbacks(this);
// Start the service
pService->start();
// Start advertising
pServer->getAdvertising()->addServiceUUID(pService->getUUID());
pServer->getAdvertising()->start();
}
bool connect() {
mBuffRX.clear();
return mConn = true;
}
void disconnect() {
mConn = false;
}
bool connected() {
return mConn;
}
size_t read(void* buf, size_t len) {
millis_time_t start = BlynkMillis();
while (BlynkMillis() - start < BLYNK_TIMEOUT_MS) {
if (available() < len) {
delay(1);
} else {
break;
}
}
size_t res = mBuffRX.get((uint8_t*)buf, len);
return res;
}
size_t write(const void* buf, size_t len) {
pCharacteristicTX->setValue((uint8_t*)buf, len);
pCharacteristicTX->notify();
return len;
}
size_t available() {
size_t rxSize = mBuffRX.size();
return rxSize;
}
private:
void onConnect(BLEServer* pServer);
void onDisconnect(BLEServer* pServer);
void onWrite(BLECharacteristic *pCharacteristic) {
std::string rxValue = pCharacteristic->getValue();
if (rxValue.length() > 0) {
uint8_t* data = (uint8_t*)rxValue.data();
size_t len = rxValue.length();
BLYNK_DBG_DUMP(">> ", data, len);
mBuffRX.put(data, len);
}
}
private:
bool mConn;
const char* mName;
BLEServer *pServer;
BLEService *pService;
BLECharacteristic *pCharacteristicTX;
BLECharacteristic *pCharacteristicRX;
BlynkFifo<uint8_t, BLYNK_MAX_READBYTES*2> mBuffRX;
};
class BlynkEsp32_BLE
: public BlynkProtocol<BlynkTransportEsp32_BLE>
{
typedef BlynkProtocol<BlynkTransportEsp32_BLE> Base;
public:
BlynkEsp32_BLE(BlynkTransportEsp32_BLE& transp)
: Base(transp)
{}
void begin(const char* auth)
{
Base::begin(auth);
state = DISCONNECTED;
conn.begin();
}
void setDeviceName(const char* name) {
conn.setDeviceName(name);
}
};
static BlynkTransportEsp32_BLE _blynkTransportBLE;
BlynkEsp32_BLE Blynk(_blynkTransportBLE);
inline
void BlynkTransportEsp32_BLE::onConnect(BLEServer* pServer) {
BLYNK_LOG1(BLYNK_F("BLE connect"));
connect();
Blynk.startSession();
};
inline
void BlynkTransportEsp32_BLE::onDisconnect(BLEServer* pServer) {
BLYNK_LOG1(BLYNK_F("BLE disconnect"));
Blynk.disconnect();
disconnect();
}
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,231 @@
#ifndef BlynkSimpleEsp32_BT_h
#define BlynkSimpleEsp32_BT_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "ESP32_BT"
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 40
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED)
#ifdef ARDUINO_ARCH_ESP32
#include "esp32-hal-log.h"
#endif
#include "esp_bt.h"
#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "esp_bt_device.h"
#include "esp_spp_api.h"
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <utility/BlynkFifo.h>
class BlynkTransportEsp32_BT
{
public:
BlynkTransportEsp32_BT()
: mConn (false)
, mName ("Blynk")
{}
void setDeviceName(const char* name) {
mName = name;
}
// IP redirect not available
void begin(char BLYNK_UNUSED *h, uint16_t BLYNK_UNUSED p) {}
void begin() {
instance = this;
if (!btStarted() && !btStart()) {
BLYNK_LOG1(BLYNK_F("btStart failed"));
return;
}
esp_bluedroid_status_t bt_state = esp_bluedroid_get_status();
if (bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
if (esp_bluedroid_init()) {
BLYNK_LOG1(BLYNK_F("esp_bluedroid_init failed"));
return;
}
}
if (bt_state != ESP_BLUEDROID_STATUS_ENABLED) {
if (esp_bluedroid_enable()) {
BLYNK_LOG1(BLYNK_F("esp_bluedroid_enable failed"));
return;
}
}
if (esp_spp_register_callback(esp_spp_cb) != ESP_OK) {
BLYNK_LOG1(BLYNK_F("esp_spp_register_callback failed"));
return;
}
if (esp_spp_init(ESP_SPP_MODE_CB) != ESP_OK) {
BLYNK_LOG1(BLYNK_F("esp_spp_init failed"));
return;
}
if (esp_bredr_tx_power_set(ESP_PWR_LVL_N2, ESP_PWR_LVL_P7) != ESP_OK)
{
BLYNK_LOG1(BLYNK_F("esp_bredr_tx_power_set failed"));
};
if (esp_bt_dev_set_device_name(mName) != ESP_OK)
{
BLYNK_LOG1(BLYNK_F("esp_bt_dev_set_device_name failed"));
}
}
bool connect() {
mBuffRX.clear();
return mConn = true;
}
void disconnect() {
mConn = false;
}
bool connected() {
return mConn;
}
size_t read(void* buf, size_t len) {
millis_time_t start = BlynkMillis();
while (BlynkMillis() - start < BLYNK_TIMEOUT_MS) {
if (available() < len) {
delay(1);
} else {
break;
}
}
size_t res = mBuffRX.get((uint8_t*)buf, len);
return res;
}
size_t write(const void* buf, size_t len) {
if (!spp_handle) {
return 0;
}
esp_err_t err = esp_spp_write(spp_handle, len, (uint8_t *)buf);
return (err == ESP_OK) ? len : 0;
}
size_t available() {
size_t rxSize = mBuffRX.size();
return rxSize;
}
static
void putData(uint8_t* data, uint16_t len) {
if (instance)
{
// BLYNK_DBG_DUMP(">> ", data, len);
instance->mBuffRX.put(data, len);
}
}
private:
static BlynkTransportEsp32_BT* instance;
static uint32_t spp_handle;
static void onConnect();
static void onDisconnect();
bool mConn;
const char* mName;
BlynkFifo<uint8_t, BLYNK_MAX_READBYTES * 2> mBuffRX;
static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
switch (event)
{
case ESP_SPP_INIT_EVT: // Once the SPP callback has been registered, ESP_SPP_INIT_EVT is triggered
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
esp_spp_start_srv(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_SLAVE, 0, "SPP_SERVER");
break;
case ESP_SPP_CLOSE_EVT:// After the SPP disconnection, ESP_SPP_CLOSE_EVT is triggered.
spp_handle = 0;
onDisconnect();
break;
case ESP_SPP_DATA_IND_EVT:// Data received
if (param->data_ind.len > 0)
{
instance->putData((uint8_t*)param->data_ind.data, param->data_ind.len);
}
else
{
BLYNK_LOG1(BLYNK_F("ESP_SPP_DATA_IND_EVT ERROR"));
}
break;
case ESP_SPP_CONG_EVT: // SPP connection congestion status changed
BLYNK_LOG1(BLYNK_F("ESP_SPP_CONG_EVT"));
break;
case ESP_SPP_SRV_OPEN_EVT://Server connection open
spp_handle = param->open.handle;
onConnect();
break;
default:
break;
}
}
};
class BlynkEsp32_BT
: public BlynkProtocol<BlynkTransportEsp32_BT>
{
typedef BlynkProtocol<BlynkTransportEsp32_BT> Base;
public:
BlynkEsp32_BT(BlynkTransportEsp32_BT& transp)
: Base(transp)
{}
void begin(const char* auth)
{
Base::begin(auth);
state = DISCONNECTED;
conn.begin();
}
void setDeviceName(const char* name) {
conn.setDeviceName(name);
}
};
BlynkTransportEsp32_BT* BlynkTransportEsp32_BT::instance = NULL;
uint32_t BlynkTransportEsp32_BT::spp_handle = 0;
static BlynkTransportEsp32_BT _blynkTransport;
BlynkEsp32_BT Blynk(_blynkTransport);
void BlynkTransportEsp32_BT::onConnect() {
BLYNK_LOG1(BLYNK_F("BT connect"));
Blynk.startSession();
};
void BlynkTransportEsp32_BT::onDisconnect() {
BLYNK_LOG1(BLYNK_F("BT disconnect"));
Blynk.disconnect();
}
#include <BlynkWidgets.h>
#endif
#endif

View File

@@ -0,0 +1,138 @@
/**
* @file BlynkSimpleEsp32_SSL.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Dec 2017
* @brief
*
*/
#ifndef BlynkSimpleEsp32_SSL_h
#define BlynkSimpleEsp32_SSL_h
#ifndef ESP32
#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
#endif
#if defined(BLYNK_SSL_USE_LETSENCRYPT)
static const char BLYNK_DEFAULT_ROOT_CA[] =
#include <certs/letsencrypt_pem.h>
#else
static const char BLYNK_DEFAULT_ROOT_CA[] =
#include <certs/blynkcloud_pem.h>
#endif
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <WiFiClientSecure.h>
template <typename Client>
class BlynkArduinoClientSecure
: public BlynkArduinoClientGen<Client>
{
public:
BlynkArduinoClientSecure(Client& client)
: BlynkArduinoClientGen<Client>(client)
, caCert(NULL)
{}
void setRootCA(const char* fp) { caCert = fp; }
bool connect() {
this->client->setCACert(caCert);
if (BlynkArduinoClientGen<Client>::connect()) {
BLYNK_LOG1(BLYNK_F("Certificate OK"));
return true;
} else {
BLYNK_LOG1(BLYNK_F("Secure connection failed"));
}
return false;
}
private:
const char* caCert;
};
template <typename Transport>
class BlynkWifi
: public BlynkProtocol<Transport>
{
typedef BlynkProtocol<Transport> Base;
public:
BlynkWifi(Transport& transp)
: Base(transp)
{}
void connectWiFi(const char* ssid, const char* pass)
{
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
WiFi.mode(WIFI_STA);
if (pass && strlen(pass)) {
WiFi.begin(ssid, pass);
} else {
WiFi.begin(ssid);
}
while (WiFi.status() != WL_CONNECTED) {
BlynkDelay(500);
}
BLYNK_LOG1(BLYNK_F("Connected to WiFi"));
IPAddress myip = WiFi.localIP();
BLYNK_LOG_IP("IP: ", myip);
}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT_SSL,
const char* root_ca = BLYNK_DEFAULT_ROOT_CA)
{
Base::begin(auth);
this->conn.begin(domain, port);
this->conn.setRootCA(root_ca);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT_SSL,
const char* root_ca = BLYNK_DEFAULT_ROOT_CA)
{
Base::begin(auth);
this->conn.begin(ip, port);
this->conn.setRootCA(root_ca);
}
void begin(const char* auth,
const char* ssid,
const char* pass,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT_SSL,
const char* root_ca = BLYNK_DEFAULT_ROOT_CA)
{
connectWiFi(ssid, pass);
config(auth, domain, port, root_ca);
while(this->connect() != true) {}
}
void begin(const char* auth,
const char* ssid,
const char* pass,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT_SSL,
const char* root_ca = BLYNK_DEFAULT_ROOT_CA)
{
connectWiFi(ssid, pass);
config(auth, ip, port, root_ca);
while(this->connect() != true) {}
}
};
static WiFiClientSecure _blynkWifiClient;
static BlynkArduinoClientSecure<WiFiClientSecure> _blynkTransport(_blynkWifiClient);
BlynkWifi<BlynkArduinoClientSecure<WiFiClientSecure> > Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,104 @@
/**
* @file BlynkSimpleEsp8266.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkSimpleEsp8266_h
#define BlynkSimpleEsp8266_h
#ifndef ESP8266
#error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting.
#endif
#include <version.h>
#if ESP_SDK_VERSION_NUMBER < 0x020200
#error Please update your ESP8266 Arduino Core
#endif
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <ESP8266WiFi.h>
class BlynkWifi
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkWifi(BlynkArduinoClient& transp)
: Base(transp)
{}
void connectWiFi(const char* ssid, const char* pass)
{
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
WiFi.mode(WIFI_STA);
if (WiFi.status() != WL_CONNECTED) {
if (pass && strlen(pass)) {
WiFi.begin(ssid, pass);
} else {
WiFi.begin(ssid);
}
}
while (WiFi.status() != WL_CONNECTED) {
BlynkDelay(500);
}
BLYNK_LOG1(BLYNK_F("Connected to WiFi"));
IPAddress myip = WiFi.localIP();
BLYNK_LOG_IP("IP: ", myip);
}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(ip, port);
}
void begin(const char* auth,
const char* ssid,
const char* pass,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass);
config(auth, domain, port);
while(this->connect() != true) {}
}
void begin(const char* auth,
const char* ssid,
const char* pass,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass);
config(auth, ip, port);
while(this->connect() != true) {}
}
};
static WiFiClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkWifi Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,198 @@
/**
* @file BlynkSimpleEsp8266_SSL.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2016
* @brief
*
*/
#ifndef BlynkSimpleEsp8266_SSL_h
#define BlynkSimpleEsp8266_SSL_h
#ifndef ESP8266
#error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting.
#endif
#include <version.h>
#if ESP_SDK_VERSION_NUMBER < 0x020200
#error Please update your ESP8266 Arduino Core
#endif
// Fingerprint is not used by default
//#define BLYNK_DEFAULT_FINGERPRINT "FD C0 7D 8D 47 97 F7 E3 07 05 D3 4E E3 BB 8E 3D C0 EA BE 1C"
#if defined(BLYNK_SSL_USE_LETSENCRYPT)
static const unsigned char BLYNK_DEFAULT_CERT_DER[] PROGMEM =
#include <certs/dst_der.h> // TODO: using DST Root CA X3 for now
//#include <certs/isrgroot_der.h>
//#include <certs/letsencrypt_der.h>
#else
static const unsigned char BLYNK_DEFAULT_CERT_DER[] PROGMEM =
#include <certs/blynkcloud_der.h>
#endif
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <time.h>
template <typename Client>
class BlynkArduinoClientSecure
: public BlynkArduinoClientGen<Client>
{
public:
BlynkArduinoClientSecure(Client& client)
: BlynkArduinoClientGen<Client>(client)
, fingerprint(NULL)
{}
void setFingerprint(const char* fp) { fingerprint = fp; }
bool setCACert(const uint8_t* caCert, unsigned caCertLen) {
bool res = this->client->setCACert(caCert, caCertLen);
if (!res) {
BLYNK_LOG1("Failed to load root CA certificate!");
}
return res;
}
bool setCACert_P(const uint8_t* caCert, unsigned caCertLen) {
bool res = this->client->setCACert_P(caCert, caCertLen);
if (!res) {
BLYNK_LOG1("Failed to load root CA certificate!");
}
return res;
}
bool connect() {
// Synchronize time useing SNTP. This is necessary to verify that
// the TLS certificates offered by the server are currently valid.
configTime(0, 0, "pool.ntp.org", "time.nist.gov");
time_t now = time(nullptr);
while (now < 100000) {
delay(500);
now = time(nullptr);
}
struct tm timeinfo;
gmtime_r(&now, &timeinfo);
String ntpTime = asctime(&timeinfo);
ntpTime.trim();
BLYNK_LOG2("NTP time: ", ntpTime);
// Now try connecting
if (BlynkArduinoClientGen<Client>::connect()) {
if (fingerprint && this->client->verify(fingerprint, this->domain)) {
BLYNK_LOG1(BLYNK_F("Fingerprint OK"));
return true;
} else if (this->client->verifyCertChain(this->domain)) {
BLYNK_LOG1(BLYNK_F("Certificate OK"));
return true;
}
BLYNK_LOG1(BLYNK_F("Certificate not validated"));
return false;
}
return false;
}
private:
const char* fingerprint;
};
template <typename Transport>
class BlynkWifi
: public BlynkProtocol<Transport>
{
typedef BlynkProtocol<Transport> Base;
public:
BlynkWifi(Transport& transp)
: Base(transp)
{}
void connectWiFi(const char* ssid, const char* pass)
{
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
WiFi.mode(WIFI_STA);
if (WiFi.status() != WL_CONNECTED) {
if (pass && strlen(pass)) {
WiFi.begin(ssid, pass);
} else {
WiFi.begin(ssid);
}
}
while (WiFi.status() != WL_CONNECTED) {
BlynkDelay(500);
}
BLYNK_LOG1(BLYNK_F("Connected to WiFi"));
IPAddress myip = WiFi.localIP();
BLYNK_LOG_IP("IP: ", myip);
}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT_SSL,
const char* fingerprint = NULL)
{
Base::begin(auth);
this->conn.begin(domain, port);
if (fingerprint) {
this->conn.setFingerprint(fingerprint);
} else {
this->conn.setCACert_P(BLYNK_DEFAULT_CERT_DER, sizeof(BLYNK_DEFAULT_CERT_DER));
}
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT_SSL,
const char* fingerprint = NULL)
{
Base::begin(auth);
this->conn.begin(ip, port);
if (fingerprint) {
this->conn.setFingerprint(fingerprint);
} else {
this->conn.setCACert_P(BLYNK_DEFAULT_CERT_DER, sizeof(BLYNK_DEFAULT_CERT_DER));
}
}
void begin(const char* auth,
const char* ssid,
const char* pass,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT_SSL,
const char* fingerprint = NULL)
{
connectWiFi(ssid, pass);
config(auth, domain, port, fingerprint);
while(this->connect() != true) {}
}
void begin(const char* auth,
const char* ssid,
const char* pass,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT_SSL,
const char* fingerprint = NULL)
{
connectWiFi(ssid, pass);
config(auth, ip, port, fingerprint);
while(this->connect() != true) {}
}
};
static WiFiClientSecure _blynkWifiClient;
static BlynkArduinoClientSecure<WiFiClientSecure> _blynkTransport(_blynkWifiClient);
BlynkWifi<BlynkArduinoClientSecure<WiFiClientSecure> > Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,28 @@
/**
* @file BlynkSimpleEthernet.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkSimpleEthernet_h
#define BlynkSimpleEthernet_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "W5100"
#endif
#include <Ethernet.h>
#include <EthernetClient.h>
#include <Adapters/BlynkEthernet.h>
static EthernetClient _blynkEthernetClient;
static BlynkArduinoClient _blynkTransport(_blynkEthernetClient);
BlynkEthernet Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,28 @@
/**
* @file BlynkSimpleEthernet2.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2016
* @brief
*
*/
#ifndef BlynkSimpleEthernet2_h
#define BlynkSimpleEthernet2_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "W5500"
#endif
#include <Ethernet2.h>
#include <EthernetClient.h>
#include <Adapters/BlynkEthernet.h>
static EthernetClient _blynkEthernetClient;
static BlynkArduinoClient _blynkTransport(_blynkEthernetClient);
BlynkEthernet Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,103 @@
/**
* @file BlynkSimpleEthernetSSL.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2018 Volodymyr Shymanskyy
* @date Sep 2018
* @brief
*
*/
#ifndef BlynkSimpleEthernetSSL_h
#define BlynkSimpleEthernetSSL_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "W5000"
#endif
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetUdp.h>
#include <ArduinoECCX08.h>
#include <ArduinoBearSSL.h>
#define BLYNK_USE_SSL
#include <Adapters/BlynkEthernet.h>
static EthernetClient _blynkEthernetClient;
static BearSSLClient _blynkEthernetClientSSL(_blynkEthernetClient);
static BlynkArduinoClient _blynkTransport(_blynkEthernetClientSSL);
BlynkEthernet Blynk(_blynkTransport);
#include <BlynkWidgets.h>
unsigned long ntpGetTime() {
static const char timeServer[] = "time.nist.gov";
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[NTP_PACKET_SIZE];
EthernetUDP Udp;
Udp.begin(8888);
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
for (int i=0; i<10; i++)
{
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(timeServer, 123); // NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
millis_time_t started = BlynkMillis();
while (BlynkMillis() - started < 1000)
{
delay(100);
if (Udp.parsePacket()) {
// We've received a packet, read the data from it
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
// the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, extract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
//Serial.print("Seconds since Jan 1 1900 = ");
//Serial.println(secsSince1900);
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears;
// print Unix time:
Serial.print("Unix time = ");
Serial.println(epoch);
return epoch;
}
}
Serial.println("Retry NTP");
}
Serial.println("NTP failed");
return 0;
}
#endif

View File

@@ -0,0 +1,27 @@
/**
* @file BlynkSimpleEthernet.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkSimpleEthernetV2_0_h
#define BlynkSimpleEthernetV2_0_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "W5200"
#endif
#include <EthernetV2_0.h>
#include <Adapters/BlynkEthernet.h>
static EthernetClient _blynkEthernetClient;
static BlynkArduinoClient _blynkTransport(_blynkEthernetClient);
BlynkEthernet Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,115 @@
/**
* @file BlynkSimpleFishino.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jun 2016
* @brief
*
*/
#ifndef BlynkSimpleFishino_h
#define BlynkSimpleFishino_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "Fishino"
#endif
#ifdef ESP8266
#error This code is not intended to run on the ESP8266 platform! Please check your Tools->Board setting.
#endif
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <Fishino.h>
class BlynkFishino
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkFishino(BlynkArduinoClient& transp)
: Base(transp)
{}
void connectWiFi(const char* ssid, const char* pass)
{
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV2);
while(!Fishino.reset()) {
BLYNK_LOG1(BLYNK_F("Fishino RESET FAILED"));
}
Fishino.setMode(STATION_MODE);
if (pass && strlen(pass)) {
while (!Fishino.begin(ssid, pass)) {
BlynkDelay(500);
}
} else {
while (!Fishino.begin(ssid)) {
BlynkDelay(500);
}
}
BLYNK_LOG1(BLYNK_F("Connected to WiFi"));
Fishino.staStartDHCP();
while(Fishino.status() != STATION_GOT_IP)
{
BlynkDelay(500);
}
IPAddress myip = Fishino.localIP();
BLYNK_LOG_IP("IP: ", myip);
}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(ip, port);
}
void begin(const char* auth,
const char* ssid,
const char* pass,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass);
config(auth, domain, port);
while(this->connect() != true) {}
}
void begin(const char* auth,
const char* ssid,
const char* pass,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass);
config(auth, ip, port);
while(this->connect() != true) {}
}
};
static FishinoClient _blynkFishinoClient;
static BlynkArduinoClient _blynkTransport(_blynkFishinoClient);
BlynkFishino Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,22 @@
/**
* @file BlynkSimpleIntelEdisonWiFi.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkSimpleIntelEdisonWiFi_h
#define BlynkSimpleIntelEdisonWiFi_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "WiFi"
#endif
#define BLYNK_MINIMIZE_PINMODE_USAGE
#include <BlynkSimpleWifi.h>
#endif

View File

@@ -0,0 +1,94 @@
/**
* @file BlynkSimpleLinkItONE.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jul 2015
* @brief
*
*/
#ifndef BlynkSimpleLinkItONE_h
#define BlynkSimpleLinkItONE_h
#ifndef BLYNK_INFO_DEVICE
#define BLYNK_INFO_DEVICE "LinkIt ONE"
#endif
// cause this causes crashes...
#define BLYNK_NO_YIELD
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <LWiFi.h>
#include <LWiFiClient.h>
class BlynkLinkItOneWifi
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkLinkItOneWifi(BlynkArduinoClient& transp)
: Base(transp)
{}
void connectWiFi(const char* ssid, const char* pass, int wifi_auth)
{
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
LWiFi.begin();
while(!LWiFi.connect(ssid, LWiFiLoginInfo((LWiFiEncryption)wifi_auth, pass))){
BlynkDelay(1000);
}
}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(ip, port);
}
void begin(const char* auth,
const char* ssid,
const char* pass,
int wifi_auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass, wifi_auth);
config(auth, domain, port);
while(this->connect() != true) {}
}
void begin(const char* auth,
const char* ssid,
const char* pass,
int wifi_auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
connectWiFi(ssid, pass, wifi_auth);
config(auth, ip, port);
while(this->connect() != true) {}
}
};
static LWiFiClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkLinkItOneWifi Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,20 @@
/**
* @file BlynkSimpleMKR1000.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2016
* @brief
*
*/
#ifndef BlynkSimpleMKR1000_h
#define BlynkSimpleMKR1000_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "WiFi"
#endif
#include <BlynkSimpleWiFiShield101.h>
#endif

View File

@@ -0,0 +1,25 @@
/**
* @file BlynkSimpleMKRGSM.h
* @author Riccardo Rizzo
* @license This project is released under the MIT License (MIT)
* @date Dec 2018
* @brief
*
*/
#ifndef BlynkSimpleMKRGSM_h
#define BlynkSimpleMKRGSM_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "MKRGSM"
#endif
#include <MKRGSM.h>
#include <Adapters/BlynkArduinoGSM.h>
static BlynkArduinoClient _blynkTransport;
BlynkSIM Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,25 @@
/**
* @file BlynkSimpleMKRNB.h
* @author Riccardo Rizzo
* @license This project is released under the MIT License (MIT)
* @date Dec 2018
* @brief
*
*/
#ifndef BlynkSimpleMKRNB_h
#define BlynkSimpleMKRNB_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "MKRNB"
#endif
#include <MKRNB.h>
#include <Adapters/BlynkArduinoNB.h>
static BlynkArduinoClient _blynkTransport;
BlynkSIM Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,21 @@
/**
* @file BlynkSimpleParticle.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*
*/
#ifndef BlynkSimpleParticle_h
#define BlynkSimpleParticle_h
#include "BlynkParticle.h"
static BlynkTransportParticle _blynkTransport;
BlynkParticle Blynk(_blynkTransport);
#include "BlynkWidgets.h"
#endif

View File

@@ -0,0 +1,143 @@
/**
* @file BlynkSimpleRFduinoBLE.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date May 2016
* @brief
*
*/
#ifndef BlynkSimpleRFduinoBLE_h
#define BlynkSimpleRFduinoBLE_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "RFduinoBLE"
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 20
//#define BLYNK_SEND_THROTTLE 20
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <utility/BlynkFifo.h>
#include <RFduinoBLE.h>
class BlynkTransportRFduinoBLE
{
public:
BlynkTransportRFduinoBLE()
: mConn (false)
{}
// IP redirect not available
void begin(char BLYNK_UNUSED *h, uint16_t BLYNK_UNUSED p) {}
void begin() {
instance = this;
}
bool connect() {
mBuffRX.clear();
return mConn = true;
}
void disconnect() {
mConn = false;
}
bool connected() {
return mConn;
}
size_t read(void* buf, size_t len) {
millis_time_t start = BlynkMillis();
while (BlynkMillis() - start < BLYNK_TIMEOUT_MS) {
if (available() < len) {
BlynkDelay(1);
} else {
break;
}
}
noInterrupts();
size_t res = mBuffRX.get((uint8_t*)buf, len);
interrupts();
return res;
}
size_t write(const void* buf, size_t len) {
RFduinoBLE.send((const char*)buf, len);
return len;
}
size_t available() {
noInterrupts();
size_t rxSize = mBuffRX.size();
interrupts();
return rxSize;
}
static
int putData(uint8_t* data, uint16_t len) {
if (!instance)
return 0;
noInterrupts();
//BLYNK_DBG_DUMP(">> ", data, len);
instance->mBuffRX.put(data, len);
interrupts();
return 0;
}
private:
static BlynkTransportRFduinoBLE* instance;
private:
bool mConn;
BlynkFifo<uint8_t, BLYNK_MAX_READBYTES*2> mBuffRX;
};
class BlynkSimpleRFduinoBLE
: public BlynkProtocol<BlynkTransportRFduinoBLE>
{
typedef BlynkProtocol<BlynkTransportRFduinoBLE> Base;
public:
BlynkSimpleRFduinoBLE(BlynkTransportRFduinoBLE& transp)
: Base(transp)
{}
void begin(const char* auth)
{
Base::begin(auth);
state = DISCONNECTED;
conn.begin();
}
};
BlynkTransportRFduinoBLE* BlynkTransportRFduinoBLE::instance = NULL;
static BlynkTransportRFduinoBLE _blynkTransport;
BlynkSimpleRFduinoBLE Blynk(_blynkTransport);
void RFduinoBLE_onConnect()
{
BLYNK_LOG1("Device connected");
Blynk.startSession();
}
void RFduinoBLE_onDisconnect()
{
BLYNK_LOG1("Device disconnected");
Blynk.disconnect();
}
void RFduinoBLE_onReceive(char* data, int len)
{
_blynkTransport.putData((uint8_t*)data, len);
}
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,191 @@
/**
* @file BlynkSimpleRedBearLab_BLE_Nano.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date May 2016
* @brief
*
*/
#ifndef BlynkSimpleRedBearLab_BLE_Nano_h
#define BlynkSimpleRedBearLab_BLE_Nano_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "RBL_BLE_Nano"
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 20
#define BLYNK_SEND_THROTTLE 20
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <utility/BlynkFifo.h>
#include <BLE_API.h>
/*
* The Nordic UART Service
*/
static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71};
static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
static const uint8_t uart_dev_name[] = "Blynk";
#define TXRX_BUF_LEN 20
uint8_t txPayload[TXRX_BUF_LEN] = {0,};
uint8_t rxPayload[TXRX_BUF_LEN] = {0,};
GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE |
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic};
GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic*));
BLE ble;
class BlynkTransportRedBearLab_BLE_Nano
{
public:
BlynkTransportRedBearLab_BLE_Nano()
: mConn (false)
{}
// IP redirect not available
void begin(char* h, uint16_t p) {}
void begin() {
instance = this;
ble.gap().onConnection(connectCallback);
ble.gap().onDisconnection(disconnectCallback);
ble.gattServer().addService(uartService);
ble.gattServer().onDataWritten(writeCallback);
ble.gattServer().onDataSent(sentCallback);
// Setup advertising
ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
uart_base_uuid_rev, sizeof(uart_base_uuid));
}
bool connect() {
mBuffRX.clear();
return mConn = true;
}
void disconnect() {
mConn = false;
}
bool connected() {
return mConn;
}
size_t read(void* buf, size_t len) {
millis_time_t start = BlynkMillis();
while (BlynkMillis() - start < BLYNK_TIMEOUT_MS) {
if (available() < len) {
ble.waitForEvent();
} else {
break;
}
}
noInterrupts();
size_t res = mBuffRX.get((uint8_t*)buf, len);
interrupts();
return res;
}
size_t write(const void* buf, size_t len) {
ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), (uint8_t*)buf, len);
return len;
}
size_t available() {
noInterrupts();
size_t rxSize = mBuffRX.size();
interrupts();
return rxSize;
}
private:
static BlynkTransportRedBearLab_BLE_Nano* instance;
static
void writeCallback(const GattWriteCallbackParams *params)
{
if (!instance)
return;
noInterrupts();
//BLYNK_DBG_DUMP(">> ", params->data, params->len);
instance->mBuffRX.put(params->data, params->len);
interrupts();
}
static
void sentCallback(unsigned count)
{
//Serial.print("SENT: ");
//Serial.println(count);
}
static
void connectCallback(const Gap::ConnectionCallbackParams_t *params);
static
void disconnectCallback(const Gap::DisconnectionCallbackParams_t *params);
private:
bool mConn;
BlynkFifo<uint8_t, BLYNK_MAX_READBYTES*2> mBuffRX;
};
class BlynkRedBearLab_BLE_Nano
: public BlynkProtocol<BlynkTransportRedBearLab_BLE_Nano>
{
typedef BlynkProtocol<BlynkTransportRedBearLab_BLE_Nano> Base;
public:
BlynkRedBearLab_BLE_Nano(BlynkTransportRedBearLab_BLE_Nano& transp)
: Base(transp)
{}
void begin(const char* auth)
{
Base::begin(auth);
state = DISCONNECTED;
conn.begin();
}
};
BlynkTransportRedBearLab_BLE_Nano* BlynkTransportRedBearLab_BLE_Nano::instance = NULL;
static BlynkTransportRedBearLab_BLE_Nano _blynkTransport;
BlynkRedBearLab_BLE_Nano Blynk(_blynkTransport);
void BlynkTransportRedBearLab_BLE_Nano::connectCallback(const Gap::ConnectionCallbackParams_t *params)
{
BLYNK_LOG1("Device connected");
Blynk.startSession();
}
void BlynkTransportRedBearLab_BLE_Nano::disconnectCallback(const Gap::DisconnectionCallbackParams_t *params)
{
BLYNK_LOG1("Device disconnected");
//__disable_irq();
Blynk.disconnect();
//__enable_irq();
ble.startAdvertising();
}
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,21 @@
/**
* @file BlynkSimpleRedBear_Duo.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Dec 2015
* @brief
*
*/
#ifndef BlynkSimpleRedBear_Duo_h
#define BlynkSimpleRedBear_Duo_h
#include "BlynkParticle.h"
static BlynkTransportParticle _blynkTransport;
BlynkParticle Blynk(_blynkTransport);
#include "BlynkWidgets.h"
#endif

View File

@@ -0,0 +1,285 @@
/**
* @file BlynkSimpleRedBear_Duo_BLE.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date May 2016
* @brief
*
*/
#ifndef BlynkSimpleRedBear_Duo_BLE_h
#define BlynkSimpleRedBear_Duo_BLE_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "RB_Duo_BLE"
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 20
//#define BLYNK_SEND_THROTTLE 20
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <utility/BlynkFifo.h>
/*
* BLE peripheral preferred connection parameters:
* - Minimum connection interval = MIN_CONN_INTERVAL * 1.25 ms, where MIN_CONN_INTERVAL ranges from 0x0006 to 0x0C80
* - Maximum connection interval = MAX_CONN_INTERVAL * 1.25 ms, where MAX_CONN_INTERVAL ranges from 0x0006 to 0x0C80
* - The SLAVE_LATENCY ranges from 0x0000 to 0x03E8
* - Connection supervision timeout = CONN_SUPERVISION_TIMEOUT * 10 ms, where CONN_SUPERVISION_TIMEOUT ranges from 0x000A to 0x0C80
*/
#define MIN_CONN_INTERVAL 0x0028 // 50ms.
#define MAX_CONN_INTERVAL 0x0190 // 500ms.
#define SLAVE_LATENCY 0x0000 // No slave latency.
#define CONN_SUPERVISION_TIMEOUT 0x03E8 // 10s.
// Learn about appearance: http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
#define BLE_PERIPHERAL_APPEARANCE BLE_APPEARANCE_UNKNOWN
#define BLE_DEVICE_NAME "Blynk"
#define CHARACTERISTIC1_MAX_LEN 20
#define CHARACTERISTIC2_MAX_LEN 20
/******************************************************
* Variable Definitions
******************************************************/
static uint8_t service1_uuid[16] = { 0x71,0x3d,0x00,0x00,0x50,0x3e,0x4c,0x75,0xba,0x94,0x31,0x48,0xf1,0x8d,0x94,0x1e };
static uint8_t service1_tx_uuid[16] = { 0x71,0x3d,0x00,0x03,0x50,0x3e,0x4c,0x75,0xba,0x94,0x31,0x48,0xf1,0x8d,0x94,0x1e };
static uint8_t service1_rx_uuid[16] = { 0x71,0x3d,0x00,0x02,0x50,0x3e,0x4c,0x75,0xba,0x94,0x31,0x48,0xf1,0x8d,0x94,0x1e };
// GAP and GATT characteristics value
static uint8_t appearance[2] = {
LOW_BYTE(BLE_PERIPHERAL_APPEARANCE),
HIGH_BYTE(BLE_PERIPHERAL_APPEARANCE)
};
static uint8_t change[4] = {
0x00, 0x00, 0xFF, 0xFF
};
static uint8_t conn_param[8] = {
LOW_BYTE(MIN_CONN_INTERVAL), HIGH_BYTE(MIN_CONN_INTERVAL),
LOW_BYTE(MAX_CONN_INTERVAL), HIGH_BYTE(MAX_CONN_INTERVAL),
LOW_BYTE(SLAVE_LATENCY), HIGH_BYTE(SLAVE_LATENCY),
LOW_BYTE(CONN_SUPERVISION_TIMEOUT), HIGH_BYTE(CONN_SUPERVISION_TIMEOUT)
};
/*
* BLE peripheral advertising parameters:
* - advertising_interval_min: [0x0020, 0x4000], default: 0x0800, unit: 0.625 msec
* - advertising_interval_max: [0x0020, 0x4000], default: 0x0800, unit: 0.625 msec
* - advertising_type:
* BLE_GAP_ADV_TYPE_ADV_IND
* BLE_GAP_ADV_TYPE_ADV_DIRECT_IND
* BLE_GAP_ADV_TYPE_ADV_SCAN_IND
* BLE_GAP_ADV_TYPE_ADV_NONCONN_IND
* - own_address_type:
* BLE_GAP_ADDR_TYPE_PUBLIC
* BLE_GAP_ADDR_TYPE_RANDOM
* - advertising_channel_map:
* BLE_GAP_ADV_CHANNEL_MAP_37
* BLE_GAP_ADV_CHANNEL_MAP_38
* BLE_GAP_ADV_CHANNEL_MAP_39
* BLE_GAP_ADV_CHANNEL_MAP_ALL
* - filter policies:
* BLE_GAP_ADV_FP_ANY
* BLE_GAP_ADV_FP_FILTER_SCANREQ
* BLE_GAP_ADV_FP_FILTER_CONNREQ
* BLE_GAP_ADV_FP_FILTER_BOTH
*
* Note: If the advertising_type is set to BLE_GAP_ADV_TYPE_ADV_SCAN_IND or BLE_GAP_ADV_TYPE_ADV_NONCONN_IND,
* the advertising_interval_min and advertising_interval_max should not be set to less than 0x00A0.
*/
static advParams_t adv_params = {
.adv_int_min = 0x0030,
.adv_int_max = 0x0030,
.adv_type = BLE_GAP_ADV_TYPE_ADV_IND,
.dir_addr_type = BLE_GAP_ADDR_TYPE_PUBLIC,
.dir_addr = {0,0,0,0,0,0},
.channel_map = BLE_GAP_ADV_CHANNEL_MAP_ALL,
.filter_policy = BLE_GAP_ADV_FP_ANY
};
static uint8_t adv_data[] = {
0x02,
BLE_GAP_AD_TYPE_FLAGS,
BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE,
0x08,
BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME,
'B','i','s','c','u','i','t',
0x11,
BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE,
0x1e,0x94,0x8d,0xf1,0x48,0x31,0x94,0xba,0x75,0x4c,0x3e,0x50,0x00,0x00,0x3d,0x71
};
static uint16_t character1_handle = 0x0000;
static uint16_t character2_handle = 0x0000;
static uint16_t character3_handle = 0x0000;
static uint8_t characteristic1_data[CHARACTERISTIC1_MAX_LEN] = { 0x01 };
static uint8_t characteristic2_data[CHARACTERISTIC2_MAX_LEN] = { 0x00 };
class BlynkTransportRedBearDuoBLE
{
public:
BlynkTransportRedBearDuoBLE()
: mConn (false)
{}
// IP redirect not available
void begin(char BLYNK_UNUSED *h, uint16_t BLYNK_UNUSED p) {}
void begin() {
instance = this;
//ble.debugLogger(true);
// Initialize ble_stack.
ble.init();
// Register BLE callback functions
ble.onConnectedCallback(deviceConnectedCallback);
ble.onDisconnectedCallback(deviceDisconnectedCallback);
ble.onDataWriteCallback(gattWriteCallback);
// Add GAP service and characteristics
ble.addService(BLE_UUID_GAP);
ble.addCharacteristic(BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME, ATT_PROPERTY_READ|ATT_PROPERTY_WRITE, (uint8_t*)BLE_DEVICE_NAME, sizeof(BLE_DEVICE_NAME));
ble.addCharacteristic(BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE, ATT_PROPERTY_READ, appearance, sizeof(appearance));
ble.addCharacteristic(BLE_UUID_GAP_CHARACTERISTIC_PPCP, ATT_PROPERTY_READ, conn_param, sizeof(conn_param));
// Add GATT service and characteristics
ble.addService(BLE_UUID_GATT);
ble.addCharacteristic(BLE_UUID_GATT_CHARACTERISTIC_SERVICE_CHANGED, ATT_PROPERTY_INDICATE, change, sizeof(change));
// Add user defined service and characteristics
ble.addService(service1_uuid);
character1_handle = ble.addCharacteristicDynamic(service1_tx_uuid, ATT_PROPERTY_WRITE|ATT_PROPERTY_WRITE_WITHOUT_RESPONSE, characteristic1_data, CHARACTERISTIC1_MAX_LEN);
character2_handle = ble.addCharacteristicDynamic(service1_rx_uuid, ATT_PROPERTY_NOTIFY, characteristic2_data, CHARACTERISTIC2_MAX_LEN);
// Set BLE advertising parameters
ble.setAdvertisementParams(&adv_params);
// // Set BLE advertising data
ble.setAdvertisementData(sizeof(adv_data), adv_data);
// BLE peripheral starts advertising now.
ble.startAdvertising();
}
bool connect() {
mBuffRX.clear();
return mConn = true;
}
void disconnect() {
mConn = false;
}
bool connected() {
return mConn;
}
size_t read(void* buf, size_t len) {
millis_time_t start = BlynkMillis();
while (BlynkMillis() - start < BLYNK_TIMEOUT_MS) {
if (available() < len) {
BlynkDelay(1);
//blePeripheral->poll();
} else {
break;
}
}
noInterrupts();
size_t res = mBuffRX.get((uint8_t*)buf, len);
interrupts();
return res;
}
size_t write(const void* buf, size_t len) {
ble.sendNotify(character2_handle, (uint8_t*)buf, len);
return len;
}
size_t available() {
noInterrupts();
size_t rxSize = mBuffRX.size();
interrupts();
return rxSize;
}
private:
static BlynkTransportRedBearDuoBLE* instance;
static
int gattWriteCallback(uint16_t value_handle, uint8_t* data, uint16_t len) {
if (!instance)
return 0;
noInterrupts();
//BLYNK_DBG_DUMP(">> ", data, len);
instance->mBuffRX.put(data, len);
interrupts();
return 0;
}
static
void deviceConnectedCallback(BLEStatus_t status, uint16_t handle);
static
void deviceDisconnectedCallback(uint16_t handle);
private:
bool mConn;
BlynkFifo<uint8_t, BLYNK_MAX_READBYTES*2> mBuffRX;
};
class BlynkRedBearDuoBLE
: public BlynkProtocol<BlynkTransportRedBearDuoBLE>
{
typedef BlynkProtocol<BlynkTransportRedBearDuoBLE> Base;
public:
BlynkRedBearDuoBLE(BlynkTransportRedBearDuoBLE& transp)
: Base(transp)
{}
void begin(const char* auth)
{
Base::begin(auth);
state = DISCONNECTED;
conn.begin();
}
};
BlynkTransportRedBearDuoBLE* BlynkTransportRedBearDuoBLE::instance = NULL;
static BlynkTransportRedBearDuoBLE _blynkTransport;
BlynkRedBearDuoBLE Blynk(_blynkTransport);
void BlynkTransportRedBearDuoBLE::deviceConnectedCallback(BLEStatus_t status, uint16_t handle) {
switch (status) {
case BLE_STATUS_OK:
BLYNK_LOG1("Device connected");
Blynk.startSession();
break;
default:
break;
}
}
void BlynkTransportRedBearDuoBLE::deviceDisconnectedCallback(uint16_t handle){
BLYNK_LOG1("Device disconnected");
Blynk.disconnect();
}
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,18 @@
/**
* @file BlynkSimpleSIM800.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Nov 2016
* @brief
*
*/
#ifndef BlynkSimpleSIM800_h
#define BlynkSimpleSIM800_h
#warning "BlynkSimpleSIM800.h is deprecated. Please use BlynkSimpleTinyGSM.h"
#include <BlynkSimpleTinyGSM.h>
#endif

View File

@@ -0,0 +1,30 @@
/**
* @file BlynkSerialBLE.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
* @date Mar 2016
* @brief
*
*/
#ifndef BlynkSerialBLE_h
#define BlynkSerialBLE_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "SerialBLE"
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 20
#define BLYNK_SEND_THROTTLE 40
#define BLYNK_NO_INFO
#include <Adapters/BlynkSerial.h>
BlynkTransportStream _blynkTransport;
BlynkStream Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,201 @@
/**
* @file BlynkSimpleShieldEsp8266.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jun 2015
* @brief
*
*/
#ifndef BlynkSimpleShieldEsp8266_h
#define BlynkSimpleShieldEsp8266_h
#ifdef ESP8266
#error This code is not intended to run on the ESP8266 platform! Please check your Tools->Board setting.
#endif
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "ESP8266"
#endif
#ifndef BLYNK_ESP8266_MUX
#define BLYNK_ESP8266_MUX 1
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 40
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <utility/BlynkFifo.h>
#include <ESP8266_Lib.h>
class BlynkTransportShieldEsp8266
{
static void onData(uint8_t mux_id, uint32_t len, void* ptr) {
((BlynkTransportShieldEsp8266*)ptr)->onData(mux_id, len);
}
void onData(uint8_t mux_id, uint32_t len) {
if (mux_id != BLYNK_ESP8266_MUX) {
return;
}
//BLYNK_LOG4("Got: ", len, ", Free: ", buffer.free());
if (buffer.free() < len) {
BLYNK_LOG1(BLYNK_F("Buffer overflow"));
return;
}
while (len) {
if (client->getUart()->available()) {
uint8_t b = client->getUart()->read();
buffer.put(b);
len--;
}
}
}
public:
BlynkTransportShieldEsp8266()
: client(NULL)
, status(false)
, domain(NULL)
, port(0)
{}
void setEsp8266(ESP8266* esp8266) {
client = esp8266;
client->setOnData(onData, this);
}
//TODO: IPAddress
void begin(const char* d, uint16_t p) {
domain = d;
port = p;
}
bool connect() {
if (!domain || !port)
return false;
status = client->createTCP(BLYNK_ESP8266_MUX, domain, port);
return status;
}
void disconnect() {
status = false;
buffer.clear();
client->releaseTCP(BLYNK_ESP8266_MUX);
}
size_t read(void* buf, size_t len) {
millis_time_t start = BlynkMillis();
//BLYNK_LOG4("Waiting: ", len, " Buffer: ", buffer.size());
while ((buffer.size() < len) && (BlynkMillis() - start < 1500)) {
client->run();
}
return buffer.get((uint8_t*)buf, len);
}
size_t write(const void* buf, size_t len) {
if (client->send(BLYNK_ESP8266_MUX, (const uint8_t*)buf, len)) {
return len;
}
return 0;
}
bool connected() { return status; }
int available() {
client->run();
//BLYNK_LOG2("Still: ", buffer.size());
return buffer.size();
}
private:
ESP8266* client;
bool status;
BlynkFifo<uint8_t,256> buffer;
const char* domain;
uint16_t port;
};
class BlynkWifi
: public BlynkProtocol<BlynkTransportShieldEsp8266>
{
typedef BlynkProtocol<BlynkTransportShieldEsp8266> Base;
public:
BlynkWifi(BlynkTransportShieldEsp8266& transp)
: Base(transp)
, wifi(NULL)
{}
bool connectWiFi(const char* ssid, const char* pass)
{
BlynkDelay(500);
BLYNK_LOG2(BLYNK_F("Connecting to "), ssid);
/*if (!wifi->restart()) {
BLYNK_LOG1(BLYNK_F("Failed to restart"));
return false;
}*/
if (!wifi->kick()) {
BLYNK_LOG1(BLYNK_F("ESP is not responding"));
//TODO: BLYNK_LOG_TROUBLE(BLYNK_F("esp8266-not-responding"));
return false;
}
if (!wifi->setEcho(0)) {
BLYNK_LOG1(BLYNK_F("Failed to disable Echo"));
return false;
}
String ver = wifi->ESP8266::getVersion();
BLYNK_LOG1(ver);
if (!wifi->enableMUX()) {
BLYNK_LOG1(BLYNK_F("Failed to enable MUX"));
}
if (!wifi->setOprToStation()) {
BLYNK_LOG1(BLYNK_F("Failed to set STA mode"));
return false;
}
if (wifi->joinAP(ssid, pass)) {
String my_ip = wifi->getLocalIP();
BLYNK_LOG1(my_ip);
} else {
BLYNK_LOG1(BLYNK_F("Failed to connect WiFi"));
return false;
}
BLYNK_LOG1(BLYNK_F("Connected to WiFi"));
return true;
}
void config(ESP8266& esp8266,
const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
wifi = &esp8266;
this->conn.setEsp8266(wifi);
this->conn.begin(domain, port);
}
void begin(const char* auth,
ESP8266& esp8266,
const char* ssid,
const char* pass,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
config(esp8266, auth, domain, port);
connectWiFi(ssid, pass);
while(this->connect() != true) {}
}
private:
ESP8266* wifi;
};
static BlynkTransportShieldEsp8266 _blynkTransport;
BlynkWifi Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,143 @@
/**
* @file BlynkSimpleSimbleeBLE.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date May 2016
* @brief
*
*/
#ifndef BlynkSimpleSimbleeBLE_h
#define BlynkSimpleSimbleeBLE_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "SimbleeBLE"
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 20
//#define BLYNK_SEND_THROTTLE 20
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
#include <utility/BlynkFifo.h>
#include <SimbleeBLE.h>
class BlynkTransportSimbleeBLE
{
public:
BlynkTransportSimbleeBLE()
: mConn (false)
{}
// IP redirect not available
void begin(char BLYNK_UNUSED *h, uint16_t BLYNK_UNUSED p) {}
void begin() {
instance = this;
}
bool connect() {
mBuffRX.clear();
return mConn = true;
}
void disconnect() {
mConn = false;
}
bool connected() {
return mConn;
}
size_t read(void* buf, size_t len) {
millis_time_t start = BlynkMillis();
while (BlynkMillis() - start < BLYNK_TIMEOUT_MS) {
if (available() < len) {
BlynkDelay(1);
} else {
break;
}
}
noInterrupts();
size_t res = mBuffRX.get((uint8_t*)buf, len);
interrupts();
return res;
}
size_t write(const void* buf, size_t len) {
SimbleeBLE.send((const char*)buf, len);
return len;
}
size_t available() {
noInterrupts();
size_t rxSize = mBuffRX.size();
interrupts();
return rxSize;
}
static
int putData(uint8_t* data, uint16_t len) {
if (!instance)
return 0;
noInterrupts();
//BLYNK_DBG_DUMP(">> ", data, len);
instance->mBuffRX.put(data, len);
interrupts();
return 0;
}
private:
static BlynkTransportSimbleeBLE* instance;
private:
bool mConn;
BlynkFifo<uint8_t, BLYNK_MAX_READBYTES*2> mBuffRX;
};
class BlynkSimpleSimbleeBLE
: public BlynkProtocol<BlynkTransportSimbleeBLE>
{
typedef BlynkProtocol<BlynkTransportSimbleeBLE> Base;
public:
BlynkSimpleSimbleeBLE(BlynkTransportSimbleeBLE& transp)
: Base(transp)
{}
void begin(const char* auth)
{
Base::begin(auth);
state = DISCONNECTED;
conn.begin();
}
};
BlynkTransportSimbleeBLE* BlynkTransportSimbleeBLE::instance = NULL;
static BlynkTransportSimbleeBLE _blynkTransport;
BlynkSimpleSimbleeBLE Blynk(_blynkTransport);
void SimbleeBLE_onConnect()
{
BLYNK_LOG1("Device connected");
Blynk.startSession();
}
void SimbleeBLE_onDisconnect()
{
BLYNK_LOG1("Device disconnected");
Blynk.disconnect();
}
void SimbleeBLE_onReceive(char* data, int len)
{
_blynkTransport.putData((uint8_t*)data, len);
}
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,25 @@
/**
* @file BlynkSimpleStream.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
* @date Mar 2016
* @brief
*
*/
#ifndef BlynkSimpleStream_h
#define BlynkSimpleStream_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "Stream"
#endif
#include <Adapters/BlynkSerial.h>
BlynkTransportStream _blynkTransport;
BlynkStream Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,33 @@
/**
* @file BlynkSimpleTinyDuino.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*/
#ifndef BlynkSimpleTinyDuino_h
#define BlynkSimpleTinyDuino_h
#ifndef BLYNK_INFO_DEVICE
#define BLYNK_INFO_DEVICE "TinyDuino"
#endif
#include <Adapters/BlynkCC3000.h>
#include <Adafruit_CC3000.h>
// Pin definitions for the TinyCircuits WiFi TinyShield
#define ADAFRUIT_CC3000_IRQ 2
#define ADAFRUIT_CC3000_VBAT A3
#define ADAFRUIT_CC3000_CS 8
// Use hardware SPI for the remaining pins (on an UNO, SCK = 13, MISO = 12, and MOSI = 11)
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIVIDER);
static BlynkTransportCC3000 _blynkTransport(cc3000);
BlynkCC3000 Blynk(cc3000, _blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,21 @@
/**
* @file BlynkSimpleTinyGSM.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Nov 2016
* @brief
*
*/
#ifndef BlynkSimpleTinyGSM_h
#define BlynkSimpleTinyGSM_h
#include <Adapters/BlynkGsmClient.h>
static BlynkArduinoClient _blynkTransport;
BlynkSIM Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,28 @@
/**
* @file BlynkSimpleUipEthernet.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkSimpleUipEthernet_h
#define BlynkSimpleUipEthernet_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "ENC28J60"
#endif
#define BLYNK_ENC28J60_FIX
#include <UIPEthernet.h>
#include <Adapters/BlynkEthernet.h>
static EthernetClient _blynkEthernetClient;
static BlynkArduinoClient _blynkTransport(_blynkEthernetClient);
BlynkEthernet Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,85 @@
/**
* @file BlynkSimpleUserManaged.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jun 2015
* @brief
*
*/
#ifndef BlynkSimpleUserManaged_h
#define BlynkSimpleUserManaged_h
#warning "This user-defined connection is now deprecated."
#warning "Please use https://github.com/blynkkk/blynk-library/tree/master/examples/More/ArduinoClient examples"
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "custom"
#endif
#include <BlynkApiArduino.h>
#include <Blynk/BlynkProtocol.h>
extern size_t BlynkStreamRead(void* buf, size_t len);
extern size_t BlynkStreamWrite(const void* buf, size_t len);
class BlynkTransportUserDefined
{
public:
BlynkTransportUserDefined()
: mConn (false)
{}
// IP redirect not available
void begin(char BLYNK_UNUSED *h, uint16_t BLYNK_UNUSED p) {}
bool connect() {
return mConn = true;
}
void disconnect() { mConn = false; }
bool connected() {
return mConn;
}
size_t read(void* buf, size_t len) {
return BlynkStreamRead(buf, len);
}
size_t write(const void* buf, size_t len) {
return BlynkStreamWrite(buf, len);
}
size_t available() {
return 0;
}
private:
bool mConn;
};
class BlynkUserDefined
: public BlynkProtocol<BlynkTransportUserDefined>
{
typedef BlynkProtocol<BlynkTransportUserDefined> Base;
public:
BlynkUserDefined(BlynkTransportUserDefined& transp)
: Base(transp)
{}
void begin(const char* auth)
{
Base::begin(auth);
}
private:
};
static BlynkTransportUserDefined _blynkTransport;
BlynkUserDefined Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,29 @@
/**
* @file BlynkSimpleWifiLink.h
* @
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2017
* @brief
*
*/
#ifndef BlynkSimpleWiFiLink_h
#define BlynkSimpleWiFiLink_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "WiFiLink"
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 64
#include <WiFiLink.h>
#include <Adapters/BlynkWiFiCommon.h>
static WiFiClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkWifiCommon Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,32 @@
/**
* @file BlynkSimpleWiFiNINA.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2018 Volodymyr Shymanskyy
* @date Sep 2018
* @brief
*
*/
#ifndef BlynkSimpleWiFiNINA_h
#define BlynkSimpleWiFiNINA_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "WiFiNINA"
#endif
#define BLYNK_SEND_ATOMIC
//#define BLYNK_USE_SSL
#include <WiFiNINA.h>
#include <Adapters/BlynkWiFiCommon.h>
//static WiFiSSLClient _blynkWifiClient;
static WiFiClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkWifiCommon Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,27 @@
/**
* @file BlynkSimpleWiFiShield101.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2016
* @brief
*
*/
#ifndef BlynkSimpleWiFiShield101_h
#define BlynkSimpleWiFiShield101_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "WiFi101"
#endif
#include <WiFi101.h>
#include <Adapters/BlynkWiFiCommon.h>
static WiFiClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkWifiCommon Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,27 @@
/**
* @file BlynkSimpleWiFiShield101.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2016
* @brief
*
*/
#ifndef BlynkSimpleWiFiShield101_h
#define BlynkSimpleWiFiShield101_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "WiFi101"
#endif
#include <WiFi101.h>
#include <Adapters/BlynkWiFiCommon.h>
static WiFiSSLClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkWifiCommon Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,21 @@
/**
* @file BlynkSimpleWiFly.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkSimpleWiFly_h
#define BlynkSimpleWiFly_h
#include <Adapters/BlynkWiFly.h>
static BlynkTransportWiFly _blynkTransport;
BlynkWiFly Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,32 @@
/**
* @file BlynkSimpleWifi.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*
*/
#ifndef BlynkSimpleWifi_h
#define BlynkSimpleWifi_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "HDG204"
#endif
// Fix for WiFi shield (it has a crazy ping duration)
#define BLYNK_TIMEOUT_MS 6000UL
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 64
#include <WiFi.h>
#include <Adapters/BlynkWiFiCommon.h>
static WiFiClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkWifiCommon Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,22 @@
/**
* @file BlynkSimpleWildFire.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*
*/
#ifndef BlynkSimpleWildFire_h
#define BlynkSimpleWildFire_h
#include <Adapters/BlynkWildFire.h>
WildFire_CC3000 cc3000;
static BlynkTransportWildFire _blynkTransport(cc3000);
BlynkWildFire Blynk(cc3000, _blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,29 @@
/**
* @file BlynkSimpleWizFi310.h
* @
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Oct 2017
* @brief
*
*/
#ifndef BlynkSimpleWizFi310_h
#define BlynkSimpleWizFi310_h
#ifndef BLYNK_INFO_CONNECTION
#define BLYNK_INFO_CONNECTION "WizFi310"
#endif
#define BLYNK_SEND_ATOMIC
#define BLYNK_SEND_CHUNK 64
#include <WizFi310.h>
#include <Adapters/BlynkWiFiCommon.h>
static WiFiClient _blynkWifiClient;
static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkWifiCommon Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,73 @@
/**
* @file BlynkSimpleYun.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*
*/
#ifndef BlynkSimpleYun_h
#define BlynkSimpleYun_h
#include <Blynk/BlynkProtocol.h>
#include <Adapters/BlynkArduinoClient.h>
#include <BridgeClient.h>
typedef BlynkArduinoClient BlynkArduinoClientYun;
class BlynkYun
: public BlynkProtocol< BlynkArduinoClientYun >
{
typedef BlynkProtocol< BlynkArduinoClientYun > Base;
public:
BlynkYun(BlynkArduinoClientYun& transp)
: Base(transp)
{}
void config(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(domain, port);
}
void config(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
Base::begin(auth);
this->conn.begin(ip, port);
}
void begin(const char* auth,
const char* domain = BLYNK_DEFAULT_DOMAIN,
uint16_t port = BLYNK_DEFAULT_PORT)
{
BLYNK_LOG1(BLYNK_F("Bridge init..."));
Bridge.begin();
config(auth, domain, port);
while(this->connect() != true) {}
}
void begin(const char* auth,
IPAddress ip,
uint16_t port = BLYNK_DEFAULT_PORT)
{
BLYNK_LOG1(BLYNK_F("Bridge init..."));
Bridge.begin();
config(auth, ip, port);
while(this->connect() != true) {}
}
};
static BridgeClient _blynkYunClient;
static BlynkArduinoClient _blynkTransport(_blynkYunClient);
BlynkYun Blynk(_blynkTransport);
#include <BlynkWidgets.h>
#endif

View File

@@ -0,0 +1,21 @@
/**
* @file BlynkWidgets.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*/
#include <WidgetLED.h>
#include <WidgetLCD.h>
#include <WidgetTerminal.h>
#include <WidgetBridge.h>
#include <WidgetTimeInput.h>
#include <WidgetTable.h>
#include <WidgetGPS.h>
#include <WidgetMap.h>
// Cannot auto-include as these have library dependencies
//#include <WidgetRTC.h>
//#include <WidgetSD.h>

View File

@@ -0,0 +1,81 @@
/**
* @file WidgetBridge.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Apr 2015
* @brief
*
*/
#ifndef WidgetBridge_h
#define WidgetBridge_h
#include <Blynk/BlynkWidgetBase.h>
class WidgetBridge
: private BlynkWidgetBase
{
public:
WidgetBridge(uint8_t vPin)
: BlynkWidgetBase(vPin)
{}
void setAuthToken(const char* token) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("i");
cmd.add(token);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename T>
void digitalWrite(const T& pin, int val) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("dw");
cmd.add(pin);
cmd.add(val);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename T>
void analogWrite(const T& pin, int val) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("aw");
cmd.add(pin);
cmd.add(val);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
template <typename... Args>
void virtualWrite(int pin, Args... values) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("vw");
cmd.add(pin);
cmd.add_multi(values...);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength()-1);
}
void virtualWriteBinary(int pin, const void* buff, size_t len) {
char mem[8];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add(mPin);
cmd.add("vw");
cmd.add(pin);
Blynk.sendCmd(BLYNK_CMD_BRIDGE, 0, cmd.getBuffer(), cmd.getLength(), buff, len);
}
void virtualWrite(int pin, const BlynkParam& param) {
virtualWriteBinary(pin, param.getBuffer(), param.getLength()-1);
}
};
#endif

View File

@@ -0,0 +1,65 @@
/**
* @file WidgetGPS.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Oct 2016
* @brief
*
*/
#ifndef WidgetGPS_h
#define WidgetGPS_h
#ifndef BLYNK_NO_FLOAT
#include <Blynk/BlynkWidgetBase.h>
class GpsParam
{
public:
GpsParam(const BlynkParam& param)
: mLat (0)
, mLon (0)
, mAlt (0)
, mSpeed (0)
{
BlynkParam::iterator it = param.begin();
if (it >= param.end())
return;
mLat = it.asDouble();
if (++it >= param.end())
return;
mLon = it.asDouble();
if (++it >= param.end())
return;
mAlt = it.asDouble();
if (++it >= param.end())
return;
mSpeed = it.asDouble();
}
double getLat() const { return mLat; }
double getLon() const { return mLon; }
double getAltitude() const { return mAlt; }
double getSpeed() const { return mSpeed; }
private:
double mLat;
double mLon;
double mAlt;
double mSpeed;
};
#endif
#endif

View File

@@ -0,0 +1,38 @@
/**
* @file WidgetLCD.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*/
#ifndef WidgetLCD_h
#define WidgetLCD_h
#include <Blynk/BlynkWidgetBase.h>
class WidgetLCD
: public BlynkWidgetBase
{
public:
WidgetLCD(uint8_t vPin) : BlynkWidgetBase(vPin) {}
void clear() {
Blynk.virtualWrite(mPin, "clr");
}
template<typename T>
void print(int x, int y, const T& str) {
char mem[BLYNK_MAX_SENDBYTES];
BlynkParam cmd(mem, 0, sizeof(mem));
cmd.add("p");
cmd.add(x);
cmd.add(y);
cmd.add(str);
Blynk.virtualWrite(mPin, cmd);
}
};
#endif

View File

@@ -0,0 +1,45 @@
/**
* @file WidgetLED.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Apr 2015
* @brief
*/
#ifndef WidgetLED_h
#define WidgetLED_h
#include <Blynk/BlynkWidgetBase.h>
class WidgetLED
: public BlynkWidgetBase
{
public:
WidgetLED(uint8_t vPin)
: BlynkWidgetBase(vPin)
, mValue(0)
{}
uint8_t getValue() const {
return mValue;
}
void setValue(uint8_t value) {
mValue = value;
Blynk.virtualWrite(mPin, value);
}
void on() {
setValue(255);
}
void off() {
setValue(0);
}
private:
uint8_t mValue;
};
#endif

View File

@@ -0,0 +1,32 @@
/**
* @file WidgetMap.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
* @date Nov 2016
* @brief
*/
#ifndef WidgetMap_h
#define WidgetMap_h
#include <Blynk/BlynkWidgetBase.h>
class WidgetMap
: public BlynkWidgetBase
{
public:
WidgetMap(uint8_t vPin) : BlynkWidgetBase(vPin) {}
void clear() {
Blynk.virtualWrite(mPin, "clr");
}
template<typename T1, typename T2, typename T3, typename T4>
void location(const T1& index, const T2& lat, const T3& lon, const T4& value) {
Blynk.virtualWrite(mPin, index, lat, lon, value);
}
};
#endif

View File

@@ -0,0 +1,58 @@
/**
* @file WidgetRTC.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2016
* @brief
*
*/
#ifndef WidgetRTC_h
#define WidgetRTC_h
#if !defined(ARDUINO)
#error WidgetRTC is not available on this platform!
#endif
#include <Blynk/BlynkWidgetBase.h>
#include <Blynk/BlynkTemplates.h>
#include <TimeLib.h>
class WidgetRTC
: public BlynkSingleton<WidgetRTC>
{
public:
WidgetRTC() {}
void begin();
private:
static time_t requestTimeSync();
};
// This is called by Time library when it needs time sync
time_t WidgetRTC::requestTimeSync()
{
// Request RTC widget update from the server
Blynk.sendInternal("rtc", "sync");
// Tell the Time library that we'll set it later
return 0;
}
inline
void WidgetRTC::begin()
{
setSyncProvider(requestTimeSync);
}
BLYNK_WRITE(InternalPinRTC) {
const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013
unsigned long blynkTime = param.asLong();
if (blynkTime >= DEFAULT_TIME) { // Check the integer is a valid time (greater than Jan 1 2013)
setTime(blynkTime); // Sync Time library clock to the value received from Blynk
BLYNK_LOG1(BLYNK_F("Time sync: OK"));
}
}
#endif

View File

@@ -0,0 +1,75 @@
/**
* @file WidgetSD.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*
*/
#ifndef WidgetSD_h
#define WidgetSD_h
#if !defined(ARDUINO)
#error WidgetSD is not available on this platform!
#endif
#include <Blynk/BlynkWidgetBase.h>
class WidgetSD
: public BlynkWidgetBase
{
public:
WidgetSD(uint8_t vPin = -1) : BlynkWidgetBase(vPin) {}
void onWrite(BlynkReq& request, const BlynkParam& param);
};
#include <SD.h>
void WidgetSD::onWrite(BlynkReq BLYNK_UNUSED &request, const BlynkParam& param)
{
const char* cmd = param[0].asStr();
if (!strcmp(cmd, "ls")) {
if (File dir = SD.open(param[1].asStr())) {
while (File entry = dir.openNextFile()) {
char mem[32];
BlynkParam result(mem, 0, sizeof(mem));
result.add(entry.name());
if (entry.isDirectory()) {
result.add("/");
} else {
result.add(entry.size());
}
Blynk.virtualWrite(request.pin, result);
entry.close();
}
dir.close();
}
} else if (!strcmp(cmd, "get")) { // dc dc dc dc d[l|e]
if (File f = SD.open(param[1].asStr())) {
if (!f.isDirectory()) {
char mem[32] = "dc";
const int maxlen = sizeof(mem)-3;
int len;
do {
len = f.read(mem+3, maxlen);
if (len < 0) {
mem[1] = 'e'; // Error!
len = 0;
} else if (len < maxlen) {
mem[1] = 'l'; // Last chunk
}
Blynk.virtualWriteBinary(request.pin, mem, len + 3);
} while (len == maxlen);
} else {
}
f.close();
}
} else {
//BLYNK_LOG2(BLYNK_F("Invalid SD command: "), cmd);
}
}
#endif

View File

@@ -0,0 +1,67 @@
/**
* @file WidgetTable.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Sep 2016
* @brief
*
*/
#ifndef WidgetTable_h
#define WidgetTable_h
#include <Blynk/BlynkWidgetBase.h>
class WidgetTable
: public BlynkWidgetBase
{
public:
typedef void (*ItemSelectChange)(int index, bool selected);
typedef void (*ItemOrderChange)(int indexFrom, int indexTo);
public:
WidgetTable(uint8_t vPin = -1)
: BlynkWidgetBase(vPin)
, mOnOrderChange(NULL)
, mOnSelectChange(NULL)
{}
void onWrite(BlynkReq BLYNK_UNUSED &request, const BlynkParam& param) {
if (mOnOrderChange && 0 == strcmp(param[0].asStr(), "order")) {
mOnOrderChange(param[1].asInt(), param[2].asInt());
} else if (mOnSelectChange && 0 == strcmp(param[0].asStr(), "select")) {
mOnSelectChange(param[1].asInt(), true);
} else if (mOnSelectChange && 0 == strcmp(param[0].asStr(), "deselect")) {
mOnSelectChange(param[1].asInt(), false);
}
}
void onOrderChange(ItemOrderChange cbk) { mOnOrderChange = cbk; }
void onSelectChange(ItemSelectChange cbk) { mOnSelectChange = cbk; }
void clear() {
Blynk.virtualWrite(mPin, "clr");
}
template <typename T1, typename T2>
void addRow(int index, const T1& name, const T2& value) {
Blynk.virtualWrite(mPin, "add", index, name, value);
}
template <typename T1, typename T2>
void updateRow(int index, const T1& name, const T2& value) {
Blynk.virtualWrite(mPin, "update", index, name, value);
}
void pickRow(int index) {
Blynk.virtualWrite(mPin, "pick", index);
}
private:
ItemOrderChange mOnOrderChange;
ItemSelectChange mOnSelectChange;
};
#endif

View File

@@ -0,0 +1,92 @@
/**
* @file WidgetTerminal.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief
*/
#ifndef WidgetTerminal_h
#define WidgetTerminal_h
#if defined(ARDUINO) && !(defined(LINUX) || defined(__MBED__))
#define BLYNK_USE_PRINT_CLASS
#elif defined(SPARK) || defined(PARTICLE)
#define BLYNK_USE_PRINT_CLASS
#endif
#include <Blynk/BlynkWidgetBase.h>
#ifdef BLYNK_USE_PRINT_CLASS
#if !(defined(SPARK) || defined(PARTICLE) || (PLATFORM_ID==88) || defined(ARDUINO_RedBear_Duo)) // 88 -> RBL Duo
// On Particle this is auto-included
#include <Print.h>
#endif
#endif
class WidgetTerminal
: public BlynkWidgetBase
#ifdef BLYNK_USE_PRINT_CLASS
, public Print
#endif
{
public:
WidgetTerminal(uint8_t vPin)
: BlynkWidgetBase(vPin)
, mOutQty(0)
{}
//virtual ~WidgetTerminal() {}
virtual size_t write(uint8_t byte) {
mOutBuf[mOutQty++] = byte;
if (mOutQty >= sizeof(mOutBuf)) {
flush();
}
return 1;
}
virtual void flush() {
if (mOutQty) {
Blynk.virtualWriteBinary(mPin, mOutBuf, mOutQty);
mOutQty = 0;
}
}
void clear() {
flush();
Blynk.virtualWrite(mPin, "clr");
}
#ifdef BLYNK_USE_PRINT_CLASS
using Print::write;
virtual size_t write(const void* buff, size_t len) {
return write((char*)buff, len);
}
#else
virtual size_t write(const void* buff, size_t len) {
uint8_t* buf = (uint8_t*)buff;
size_t left = len;
while (left--) {
write(*buf++);
}
return len;
}
virtual size_t write(const char* str) {
return write(str, strlen(str));
}
#endif
private:
uint8_t mOutBuf[64];
uint8_t mOutQty;
};
#endif

View File

@@ -0,0 +1,129 @@
/**
* @file WidgetTimeInput.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Aug 2016
* @brief
*
*/
#ifndef WidgetTimeInput_h
#define WidgetTimeInput_h
#include <Blynk/BlynkApi.h>
#include <utility/BlynkDateTime.h>
#include <utility/BlynkUtility.h>
class TimeInputParam
{
public:
enum TimeMode {
TIME_UNDEFINED,
TIME_SUNSET,
TIME_SUNRISE,
TIME_SPECIFIED
};
TimeInputParam(const BlynkParam& param)
{
mStartMode = TIME_UNDEFINED;
mStopMode = TIME_UNDEFINED;
mTZ[0] = '\0';
mWeekdays = -1; // All set
mTZ_Offset = 0;
BlynkParam::iterator it = param.begin();
if (it >= param.end())
return;
if (0 == strcmp(it.asStr(), "sr")) {
mStartMode = TIME_SUNRISE;
} else if (0 == strcmp(it.asStr(), "ss")) {
mStartMode = TIME_SUNSET;
} else if (!it.isEmpty()) {
mStart = BlynkTime(it.asLong());
if (mStart.isValid()) {
mStartMode = TIME_SPECIFIED;
}
}
if (++it >= param.end())
return;
if (0 == strcmp(it.asStr(), "sr")) {
mStopMode = TIME_SUNRISE;
} else if (0 == strcmp(it.asStr(), "ss")) {
mStopMode = TIME_SUNSET;
} else if (!it.isEmpty()) {
mStop = BlynkTime(it.asLong());
if (mStop.isValid()) {
mStopMode = TIME_SPECIFIED;
}
}
if (++it >= param.end())
return;
strncpy(mTZ, it.asStr(), sizeof(mTZ));
if (++it >= param.end())
return;
if (!it.isEmpty()) {
mWeekdays = 0;
const char* p = it.asStr();
while (int c = *p++) {
if (c >= '1' && c <= '7') {
BlynkBitSet(mWeekdays, c - '1');
}
}
}
if (++it >= param.end())
return;
mTZ_Offset = it.asLong();
}
BlynkTime& getStart() { return mStart; }
BlynkTime& getStop() { return mStop; }
TimeMode getStartMode() const { return mStartMode; }
TimeMode getStopMode() const { return mStopMode; }
bool hasStartTime() const { return mStartMode == TIME_SPECIFIED; }
bool isStartSunrise() const { return mStartMode == TIME_SUNRISE; }
bool isStartSunset() const { return mStartMode == TIME_SUNSET; }
int getStartHour() const { return mStart.hour(); }
int getStartMinute() const { return mStart.minute(); }
int getStartSecond() const { return mStart.second(); }
bool hasStopTime() const { return mStopMode == TIME_SPECIFIED; }
bool isStopSunrise() const { return mStopMode == TIME_SUNRISE; }
bool isStopSunset() const { return mStopMode == TIME_SUNSET; }
int getStopHour() const { return mStop.hour(); }
int getStopMinute() const { return mStop.minute(); }
int getStopSecond() const { return mStop.second(); }
const char* getTZ() const { return mTZ; }
int32_t getTZ_Offset() const { return mTZ_Offset; }
bool isWeekdaySelected(int day) const {
return BlynkBitRead(mWeekdays, (day - 1) % 7);
}
private:
BlynkTime mStart;
BlynkTime mStop;
char mTZ[32];
int32_t mTZ_Offset;
TimeMode mStopMode;
TimeMode mStartMode;
uint8_t mWeekdays;
};
#endif

Binary file not shown.

View File

@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/
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ICATE-----

View File

@@ -0,0 +1,87 @@
/* Generated by xxd -i cert.der > cert_der.h */
{
0x30, 0x82, 0x03, 0xe5, 0x30, 0x82, 0x02, 0xcd, 0xa0, 0x03, 0x02, 0x01,
0x02, 0x02, 0x09, 0x00, 0x81, 0xd2, 0x9d, 0xbf, 0x9c, 0xbf, 0x81, 0x02,
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
0x0b, 0x05, 0x00, 0x30, 0x81, 0x88, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x41, 0x31, 0x0d, 0x30, 0x0b, 0x06,
0x03, 0x55, 0x04, 0x08, 0x0c, 0x04, 0x4b, 0x79, 0x69, 0x76, 0x31, 0x0d,
0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x04, 0x4b, 0x79, 0x69,
0x76, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02,
0x49, 0x54, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c,
0x0a, 0x42, 0x6c, 0x79, 0x6e, 0x6b, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x31,
0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x62, 0x6c,
0x79, 0x6e, 0x6b, 0x2d, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2e, 0x63, 0x6f,
0x6d, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x64, 0x6d, 0x69, 0x74, 0x72, 0x69,
0x79, 0x40, 0x62, 0x6c, 0x79, 0x6e, 0x6b, 0x2e, 0x63, 0x63, 0x30, 0x1e,
0x17, 0x0d, 0x31, 0x36, 0x30, 0x33, 0x31, 0x37, 0x31, 0x31, 0x35, 0x38,
0x30, 0x37, 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, 0x33, 0x31, 0x36, 0x31,
0x31, 0x35, 0x38, 0x30, 0x37, 0x5a, 0x30, 0x81, 0x88, 0x31, 0x0b, 0x30,
0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x41, 0x31, 0x0d,
0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x04, 0x4b, 0x79, 0x69,
0x76, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x04,
0x4b, 0x79, 0x69, 0x76, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
0x0a, 0x0c, 0x02, 0x49, 0x54, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55,
0x04, 0x0b, 0x0c, 0x0a, 0x42, 0x6c, 0x79, 0x6e, 0x6b, 0x20, 0x49, 0x6e,
0x63, 0x2e, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
0x0f, 0x62, 0x6c, 0x79, 0x6e, 0x6b, 0x2d, 0x63, 0x6c, 0x6f, 0x75, 0x64,
0x2e, 0x63, 0x6f, 0x6d, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86,
0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x64, 0x6d, 0x69,
0x74, 0x72, 0x69, 0x79, 0x40, 0x62, 0x6c, 0x79, 0x6e, 0x6b, 0x2e, 0x63,
0x63, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f,
0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0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d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3f,
0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, 0x44,
0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61,
0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x43,
0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41,
0x20, 0x58, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x30, 0x30, 0x39, 0x33,
0x30, 0x32, 0x31, 0x31, 0x32, 0x31, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x31,
0x30, 0x39, 0x33, 0x30, 0x31, 0x34, 0x30, 0x31, 0x31, 0x35, 0x5a, 0x30,
0x3f, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b,
0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e,
0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20,
0x43, 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03,
0x13, 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43,
0x41, 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09,
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03,
0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 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 0xb3, 0x8c, 0xc6, 0xdf, 0xbf, 0xc9, 0x41, 0x70,
0xec, 0x16, 0x72, 0xd5, 0x26, 0xec, 0x38, 0x55, 0x39, 0x43, 0xd0, 0xfc,
0xfd, 0x18, 0x5c, 0x40, 0xf1, 0x97, 0xeb, 0xd5, 0x9a, 0x9b, 0x8d, 0x1d,
0xba, 0xda, 0x25, 0xb9, 0xc6, 0xd8, 0xdf, 0xc1, 0x15, 0x02, 0x3a, 0xab,
0xda, 0x6e, 0xf1, 0x3e, 0x2e, 0xf5, 0x5c, 0x08, 0x9c, 0x3c, 0xd6, 0x83,
0x69, 0xe4, 0x10, 0x9b, 0x19, 0x2a, 0xb6, 0x29, 0x57, 0xe3, 0xe5, 0x3d,
0x9b, 0x9f, 0xf0, 0x02, 0x5d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42,
0x30, 0x40, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff,
0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55,
0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30,
0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xc4, 0xa7,
0xb1, 0xa4, 0x7b, 0x2c, 0x71, 0xfa, 0xdb, 0xe1, 0x4b, 0x90, 0x75, 0xff,
0xc4, 0x15, 0x60, 0x85, 0x89, 0x10, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01,
0x01, 0x00, 0xa3, 0x1a, 0x2c, 0x9b, 0x17, 0x00, 0x5c, 0xa9, 0x1e, 0xee,
0x28, 0x66, 0x37, 0x3a, 0xbf, 0x83, 0xc7, 0x3f, 0x4b, 0xc3, 0x09, 0xa0,
0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6, 0xd2, 0x7d, 0x91, 0x8b, 0xf9, 0x3d, 0x32,
0x8d, 0x65, 0xb4, 0xe9, 0x7c, 0xb1, 0x57, 0x76, 0xea, 0xc5, 0xb6, 0x28,
0x39, 0xbf, 0x15, 0x65, 0x1c, 0xc8, 0xf6, 0x77, 0x96, 0x6a, 0x0a, 0x8d,
0x77, 0x0b, 0xd8, 0x91, 0x0b, 0x04, 0x8e, 0x07, 0xdb, 0x29, 0xb6, 0x0a,
0xee, 0x9d, 0x82, 0x35, 0x35, 0x10
};

View File

@@ -0,0 +1,118 @@
{
0x30, 0x82, 0x05, 0x6b, 0x30, 0x82, 0x03, 0x53, 0xa0, 0x03, 0x02, 0x01,
0x02, 0x02, 0x11, 0x00, 0x82, 0x10, 0xcf, 0xb0, 0xd2, 0x40, 0xe3, 0x59,
0x44, 0x63, 0xe0, 0xbb, 0x63, 0x82, 0x8b, 0x00, 0x30, 0x0d, 0x06, 0x09,
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
0x4f, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
0x55, 0x53, 0x31, 0x29, 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13,
0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x53, 0x65,
0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61,
0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x31, 0x15, 0x30,
0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0c, 0x49, 0x53, 0x52, 0x47,
0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x58, 0x31, 0x30, 0x1e, 0x17, 0x0d,
0x31, 0x35, 0x30, 0x36, 0x30, 0x34, 0x31, 0x31, 0x30, 0x34, 0x33, 0x38,
0x5a, 0x17, 0x0d, 0x33, 0x35, 0x30, 0x36, 0x30, 0x34, 0x31, 0x31, 0x30,
0x34, 0x33, 0x38, 0x5a, 0x30, 0x4f, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x29, 0x30, 0x27, 0x06,
0x03, 0x55, 0x04, 0x0a, 0x13, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e,
0x65, 0x74, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20,
0x52, 0x65, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6f,
0x75, 0x70, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
0x0c, 0x49, 0x53, 0x52, 0x47, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x58,
0x31, 0x30, 0x82, 0x02, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0f,
0x00, 0x30, 0x82, 0x02, 0x0a, 0x02, 0x82, 0x02, 0x01, 0x00, 0xad, 0xe8,
0x24, 0x73, 0xf4, 0x14, 0x37, 0xf3, 0x9b, 0x9e, 0x2b, 0x57, 0x28, 0x1c,
0x87, 0xbe, 0xdc, 0xb7, 0xdf, 0x38, 0x90, 0x8c, 0x6e, 0x3c, 0xe6, 0x57,
0xa0, 0x78, 0xf7, 0x75, 0xc2, 0xa2, 0xfe, 0xf5, 0x6a, 0x6e, 0xf6, 0x00,
0x4f, 0x28, 0xdb, 0xde, 0x68, 0x86, 0x6c, 0x44, 0x93, 0xb6, 0xb1, 0x63,
0xfd, 0x14, 0x12, 0x6b, 0xbf, 0x1f, 0xd2, 0xea, 0x31, 0x9b, 0x21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83, 0x04, 0x1b,
0xa2, 0x83, 0x03, 0x41, 0xa1, 0xd6, 0x05, 0xf1, 0x1b, 0xc2, 0xb6, 0xf0,
0xa8, 0x7c, 0x86, 0x3b, 0x46, 0xa8, 0x48, 0x2a, 0x88, 0xdc, 0x76, 0x9a,
0x76, 0xbf, 0x1f, 0x6a, 0xa5, 0x3d, 0x19, 0x8f, 0xeb, 0x38, 0xf3, 0x64,
0xde, 0xc8, 0x2b, 0x0d, 0x0a, 0x28, 0xff, 0xf7, 0xdb, 0xe2, 0x15, 0x42,
0xd4, 0x22, 0xd0, 0x27, 0x5d, 0xe1, 0x79, 0xfe, 0x18, 0xe7, 0x70, 0x88,
0xad, 0x4e, 0xe6, 0xd9, 0x8b, 0x3a, 0xc6, 0xdd, 0x27, 0x51, 0x6e, 0xff,
0xbc, 0x64, 0xf5, 0x33, 0x43, 0x4f, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3,
0x42, 0x30, 0x40, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01,
0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x0f, 0x06, 0x03, 0x55,
0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff,
0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x79,
0xb4, 0x59, 0xe6, 0x7b, 0xb6, 0xe5, 0xe4, 0x01, 0x73, 0x80, 0x08, 0x88,
0xc8, 0x1a, 0x58, 0xf6, 0xe9, 0x9b, 0x6e, 0x30, 0x0d, 0x06, 0x09, 0x2a,
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
0x02, 0x01, 0x00, 0x55, 0x1f, 0x58, 0xa9, 0xbc, 0xb2, 0xa8, 0x50, 0xd0,
0x0c, 0xb1, 0xd8, 0x1a, 0x69, 0x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0x76, 0xf2, 0x2d, 0xe8, 0x8d, 0x75, 0xdf, 0x17, 0x33, 0x6c, 0x3d,
0x53, 0xfb, 0x7b, 0xcb, 0x41, 0x5f, 0xff, 0xdc, 0xa2, 0xd0, 0x61, 0x38,
0xe1, 0x96, 0xb8, 0xac, 0x5d, 0x8b, 0x37, 0xd7, 0x75, 0xd5, 0x33, 0xc0,
0x99, 0x11, 0xae, 0x9d, 0x41, 0xc1, 0x72, 0x75, 0x84, 0xbe, 0x02, 0x41,
0x42, 0x5f, 0x67, 0x24, 0x48, 0x94, 0xd1, 0x9b, 0x27, 0xbe, 0x07, 0x3f,
0xb9, 0xb8, 0x4f, 0x81, 0x74, 0x51, 0xe1, 0x7a, 0xb7, 0xed, 0x9d, 0x23,
0xe2, 0xbe, 0xe0, 0xd5, 0x28, 0x04, 0x13, 0x3c, 0x31, 0x03, 0x9e, 0xdd,
0x7a, 0x6c, 0x8f, 0xc6, 0x07, 0x18, 0xc6, 0x7f, 0xde, 0x47, 0x8e, 0x3f,
0x28, 0x9e, 0x04, 0x06, 0xcf, 0xa5, 0x54, 0x34, 0x77, 0xbd, 0xec, 0x89,
0x9b, 0xe9, 0x17, 0x43, 0xdf, 0x5b, 0xdb, 0x5f, 0xfe, 0x8e, 0x1e, 0x57,
0xa2, 0xcd, 0x40, 0x9d, 0x7e, 0x62, 0x22, 0xda, 0xde, 0x18, 0x27
};

View File

@@ -0,0 +1,122 @@
/* Generated by xxd -i cert.der > cert_der.h */
{
0x30, 0x82, 0x05, 0x8d, 0x30, 0x82, 0x03, 0x75, 0xa0, 0x03, 0x02, 0x01,
0x02, 0x02, 0x11, 0x00, 0xd3, 0xb1, 0x72, 0x26, 0x34, 0x23, 0x32, 0xdc,
0xf4, 0x05, 0x28, 0x51, 0x2a, 0xec, 0x9c, 0x6a, 0x30, 0x0d, 0x06, 0x09,
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
0x4f, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
0x55, 0x53, 0x31, 0x29, 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13,
0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x53, 0x65,
0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61,
0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x31, 0x15, 0x30,
0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0c, 0x49, 0x53, 0x52, 0x47,
0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x58, 0x31, 0x30, 0x1e, 0x17, 0x0d,
0x31, 0x36, 0x31, 0x30, 0x30, 0x36, 0x31, 0x35, 0x34, 0x33, 0x35, 0x35,
0x5a, 0x17, 0x0d, 0x32, 0x31, 0x31, 0x30, 0x30, 0x36, 0x31, 0x35, 0x34,
0x33, 0x35, 0x35, 0x5a, 0x30, 0x4a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x16, 0x30, 0x14, 0x06,
0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20,
0x45, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x31, 0x23, 0x30, 0x21, 0x06,
0x03, 0x55, 0x04, 0x03, 0x13, 0x1a, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20,
0x45, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x20, 0x41, 0x75, 0x74, 0x68,
0x6f, 0x72, 0x69, 0x74, 0x79, 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22,
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7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x0d, 0x95, 0x16, 0x7d, 0xc4, 0x2b, 0xa0, 0x65, 0xb2,
0x99, 0x04, 0x36, 0x75, 0x80, 0x6b, 0xac, 0x4a, 0xf3, 0x1b, 0x90, 0x49,
0x78, 0x2f, 0xa2, 0x96, 0x4f, 0x2a, 0x20, 0x25, 0x29, 0x04, 0xc6, 0x74,
0xc0, 0xd0, 0x31, 0xcd, 0x8f, 0x31, 0x38, 0x95, 0x16, 0xba, 0xa8, 0x33,
0xb8, 0x43, 0xf1, 0xb1, 0x1f, 0xc3, 0x30, 0x7f, 0xa2, 0x79, 0x31, 0x13,
0x3d, 0x2d, 0x36, 0xf8, 0xe3, 0xfc, 0xf2, 0x33, 0x6a, 0xb9, 0x39, 0x31,
0xc5, 0xaf, 0xc4, 0x8d, 0x0d, 0x1d, 0x64, 0x16, 0x33, 0xaa, 0xfa, 0x84,
0x29, 0xb6, 0xd4, 0x0b, 0xc0, 0xd8, 0x7d, 0xc3, 0x93, 0x02, 0x03, 0x01,
0x00, 0x01, 0xa3, 0x82, 0x01, 0x67, 0x30, 0x82, 0x01, 0x63, 0x30, 0x0e,
0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02,
0x01, 0x86, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff,
0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x00, 0x30, 0x54,
0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x4d, 0x30, 0x4b, 0x30, 0x08, 0x06,
0x06, 0x67, 0x81, 0x0c, 0x01, 0x02, 0x01, 0x30, 0x3f, 0x06, 0x0b, 0x2b,
0x06, 0x01, 0x04, 0x01, 0x82, 0xdf, 0x13, 0x01, 0x01, 0x01, 0x30, 0x30,
0x30, 0x2e, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, 0x01,
0x16, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x70, 0x73,
0x2e, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x78, 0x31, 0x2e, 0x6c, 0x65, 0x74,
0x73, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x2e, 0x6f, 0x72, 0x67,
0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xa8,
0x4a, 0x6a, 0x63, 0x04, 0x7d, 0xdd, 0xba, 0xe6, 0xd1, 0x39, 0xb7, 0xa6,
0x45, 0x65, 0xef, 0xf3, 0xa8, 0xec, 0xa1, 0x30, 0x33, 0x06, 0x03, 0x55,
0x1d, 0x1f, 0x04, 0x2c, 0x30, 0x2a, 0x30, 0x28, 0xa0, 0x26, 0xa0, 0x24,
0x86, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x72, 0x6c,
0x2e, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x78, 0x31, 0x2e, 0x6c, 0x65, 0x74,
0x73, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x2e, 0x6f, 0x72, 0x67,
0x30, 0x72, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x01,
0x04, 0x66, 0x30, 0x64, 0x30, 0x30, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05,
0x05, 0x07, 0x30, 0x01, 0x86, 0x24, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f,
0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2e, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x78,
0x31, 0x2e, 0x6c, 0x65, 0x74, 0x73, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70,
0x74, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x30, 0x30, 0x06, 0x08, 0x2b, 0x06,
0x01, 0x05, 0x05, 0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Ys1JKY\n" \
"2PGDuWx8M6DlS6qQkvHaRUo0FMd8TsSlbF0/v965qGFKhSDeQoMpYnwcmQilRh/0\n" \
"ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKR\n" \
"PB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b\n" \
"rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt\n" \
"-----END CERTIFICATE-----\n" ;

View File

@@ -0,0 +1,173 @@
/**
* @file BlynkDateTime.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
* @date Aug 2016
* @brief DateTime implementation
*
*/
#ifndef BlynkDateTime_h
#define BlynkDateTime_h
typedef long blynk_time_t;
struct blynk_tm *blynk_gmtime_r(const blynk_time_t *time, struct blynk_tm *tm);
blynk_time_t blynk_mk_gmtime(struct blynk_tm *tm);
struct blynk_tm {
int8_t tm_sec;
int8_t tm_min;
int8_t tm_hour;
int8_t tm_mday;
int8_t tm_wday;
int8_t tm_mon;
int16_t tm_year;
int16_t tm_yday;
int16_t tm_isdst;
};
class BlynkTime {
public:
static const uint32_t MAX_TIME = 86400L;
BlynkTime() : mTime(-1) {}
BlynkTime(const BlynkTime& t) : mTime(t.mTime) {}
BlynkTime(long seconds) : mTime(seconds % MAX_TIME) {}
BlynkTime(int hour, int minute, int second)
{
mTime = (hour * 3600 + minute * 60 + second) % MAX_TIME;
}
int second() const { return mTime % 60; }
int minute() const { return (mTime / 60) % 60; }
int hour() const { return mTime / 3600; }
int hour12() const {
int h = hour();
if (h == 0)
return 12; // 12 midnight
else if (h > 12)
return h - 12;
return h;
}
bool isAM() const { return !isPM(); }
bool isPM() const { return (hour() >= 12); }
void adjustSeconds(int sec) {
if (isValid()) {
mTime = (mTime + sec) % MAX_TIME;
}
}
blynk_time_t getUnixOffset() const { return mTime; }
bool isValid() const { return mTime < MAX_TIME; }
operator bool() const { return isValid(); }
bool operator == (const BlynkTime& t) const { return mTime == t.mTime; }
bool operator >= (const BlynkTime& t) const { return mTime >= t.mTime; }
bool operator <= (const BlynkTime& t) const { return mTime <= t.mTime; }
bool operator > (const BlynkTime& t) const { return mTime > t.mTime; }
bool operator < (const BlynkTime& t) const { return mTime < t.mTime; }
private:
uint32_t mTime;
};
class BlynkDateTime {
public:
BlynkDateTime() : mTime(0) {}
BlynkDateTime(const BlynkDateTime& t)
{
mTime = t.mTime;
blynk_gmtime_r(&mTime, &mTm);
}
BlynkDateTime(blynk_time_t t)
{
mTime = t;
blynk_gmtime_r(&mTime, &mTm);
}
BlynkDateTime(int hour, int minute, int second, int day, int month, int year)
{
mTm.tm_hour = hour;
mTm.tm_min = minute;
mTm.tm_sec = second;
mTm.tm_mday = day;
mTm.tm_mon = month - 1;
mTm.tm_year = year - 1900;
mTm.tm_isdst = 0;
mTime = blynk_mk_gmtime(&mTm);
}
int second() const { return mTm.tm_sec; }
int minute() const { return mTm.tm_min; }
int hour() const { return mTm.tm_hour; }
int day() const { return mTm.tm_mday; }
int month() const { return 1 + mTm.tm_mon; }
int year() const { return 1900 + mTm.tm_year; }
int day_of_year() const { return 1 + mTm.tm_yday; }
int day_of_week() const { return mTm.tm_wday == 0 ? 7 : mTm.tm_wday; }
/*int weak_of_year() const {
int julian = day_of_year();
int dow = day_of_week();
int dowJan1 = BlynkDateTime(0,0,0, 1,1,year()).day_of_week();
int weekNum = ((julian + 6) / 7);
if (dow < dowJan1)
++weekNum;
return (weekNum);
}*/
int hour12() const {
int h = hour();
if (h == 0)
return 12; // 12 midnight
else if (h > 12)
return h - 12;
return h;
}
bool isAM() const { return !isPM(); }
bool isPM() const { return (hour() >= 12); }
void adjustSeconds(int sec) {
if (isValid()) {
mTime += sec;
blynk_gmtime_r(&mTime, &mTm);
}
}
//tm& getTm() { return mTm; }
blynk_time_t getUnix() const { return mTime; }
bool isValid() const { return mTime != 0; }
operator bool() const { return isValid(); }
bool operator == (const BlynkDateTime& t) const { return mTime == t.mTime; }
bool operator >= (const BlynkDateTime& t) const { return mTime >= t.mTime; }
bool operator <= (const BlynkDateTime& t) const { return mTime <= t.mTime; }
bool operator > (const BlynkDateTime& t) const { return mTime > t.mTime; }
bool operator < (const BlynkDateTime& t) const { return mTime < t.mTime; }
private:
blynk_tm mTm;
blynk_time_t mTime;
};
#endif

View File

@@ -0,0 +1,314 @@
/**
* @file BlynkDebug.cpp
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief Debug utilities for Arduino
*/
#include <Blynk/BlynkDebug.h>
#if defined(ARDUINO) && defined(__AVR__) && defined(BLYNK_USE_AVR_WDT)
#include <Arduino.h>
#include <avr/wdt.h>
BLYNK_CONSTRUCTOR
static void BlynkSystemInit()
{
MCUSR = 0;
wdt_disable();
}
void BlynkReset()
{
wdt_enable(WDTO_15MS);
delay(50);
void(*resetFunc)(void) = 0;
resetFunc();
for(;;) {} // To make compiler happy
}
size_t BlynkFreeRam()
{
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(ARDUINO) && defined(__AVR__)
#include <Arduino.h>
void BlynkReset()
{
void(*resetFunc)(void) = 0;
resetFunc();
for(;;) {}
}
size_t BlynkFreeRam()
{
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(ARDUINO) && defined(ESP8266)
#include <Arduino.h>
size_t BlynkFreeRam()
{
return ESP.getFreeHeap();
}
void BlynkReset()
{
ESP.restart();
for(;;) {}
}
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
#include <Arduino.h>
extern "C" char *sbrk(int i);
size_t BlynkFreeRam()
{
char stack_dummy = 0;
return &stack_dummy - sbrk(0);
}
void BlynkReset()
{
NVIC_SystemReset();
for(;;) {}
}
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined (ARDUINO_ARCH_ARC32)
millis_time_t BlynkMillis()
{
// TODO: Remove workaround for Intel Curie
// https://forum.arduino.cc/index.php?topic=391836.0
noInterrupts();
uint64_t t = millis();
interrupts();
return t;
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_RESET
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(ARDUINO) && (defined(__STM32F1__) || defined(__STM32F3__))
#include <Arduino.h>
#include <libmaple/nvic.h>
void BlynkReset()
{
nvic_sys_reset();
for(;;) {}
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined (PARTICLE) || defined(SPARK)
#include "application.h"
void BlynkReset()
{
System.reset();
for(;;) {} // To make compiler happy
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(__MBED__)
#include "mbed.h"
static Timer blynk_millis_timer;
static Ticker blynk_waker;
static
void blynk_wake() {
//pc.puts("(...)");
}
BLYNK_CONSTRUCTOR
static void BlynkSystemInit()
{
blynk_waker.attach(&blynk_wake, 2.0);
blynk_millis_timer.start();
}
void BlynkDelay(millis_time_t ms)
{
wait_ms(ms);
}
millis_time_t BlynkMillis()
{
return blynk_millis_timer.read_ms();
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_RESET
#elif defined(LINUX) && defined(RASPBERRY)
#include <stdlib.h>
#include <wiringPi.h>
BLYNK_CONSTRUCTOR
static void BlynkSystemInit()
{
wiringPiSetupGpio();
}
void BlynkReset()
{
exit(1);
for(;;) {} // To make compiler happy
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(LINUX)
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
static millis_time_t blynk_startup_time = 0;
BLYNK_CONSTRUCTOR
static void BlynkSystemInit()
{
blynk_startup_time = BlynkMillis();
}
void BlynkReset()
{
exit(1);
for(;;) {} // To make compiler happy
}
void BlynkDelay(millis_time_t ms)
{
usleep(ms * 1000);
}
millis_time_t BlynkMillis()
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts );
return ( ts.tv_sec * 1000 + ts.tv_nsec / 1000000L ) - blynk_startup_time;
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#elif defined(TI_CC3220)
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <ti/devices/cc32xx/inc/hw_types.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/drivers/net/wifi/device.h>
#include <ti/devices/cc32xx/driverlib/prcm.h>
void BlynkReset()
{
sl_Stop(200);
for(;;) {
PRCMHibernateCycleTrigger();
}
}
void BlynkDelay(millis_time_t ms)
{
usleep(ms * 1000);
}
millis_time_t BlynkMillis()
{
return Clock_getTicks();
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#else
#if defined(BLYNK_DEBUG_ALL)
#warning "Need to implement board-specific utilities"
#endif
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_RESET
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#endif
#ifdef _BLYNK_USE_DEFAULT_DELAY
void BlynkDelay(millis_time_t ms)
{
return delay(ms);
}
#endif
#ifdef _BLYNK_USE_DEFAULT_MILLIS
millis_time_t BlynkMillis()
{
return millis();
}
#endif
#ifdef _BLYNK_USE_DEFAULT_FREE_RAM
size_t BlynkFreeRam()
{
return 0;
}
#endif
#ifdef _BLYNK_USE_DEFAULT_RESET
void BlynkReset()
{
for(;;) {} // To make compiler happy
}
#endif
void BlynkFatal()
{
BlynkDelay(10000L);
BlynkReset();
}

View File

@@ -0,0 +1,158 @@
/**
* @file BlynkFifo.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Feb 2015
* @brief FIFO implementation
*
*/
#ifndef BlynkFifo_h
#define BlynkFifo_h
#include <utility/BlynkUtility.h>
template <class T, unsigned N>
class BlynkFifo
{
public:
BlynkFifo()
{
clear();
}
void clear()
{
_r = 0;
_w = 0;
}
~BlynkFifo(void)
{}
// writing thread/context API
//-------------------------------------------------------------
bool writeable(void)
{
return free() > 0;
}
int free(void)
{
int s = _r - _w;
if (s <= 0)
s += N;
return s - 1;
}
T put(const T& c)
{
int i = _w;
int j = i;
i = _inc(i);
while (i == _r) // = !writeable()
/* nothing / just wait */;
_b[j] = c;
_w = i;
return c;
}
int put(const T* p, int n, bool blocking = false)
{
int c = n;
while (c)
{
int f;
while ((f = free()) == 0) // wait for space
{
if (!blocking) return n - c; // no more space and not blocking
/* nothing / just wait */;
}
// check free space
if (c < f) f = c;
int w = _w;
int m = N - w;
// check wrap
if (f > m) f = m;
memcpy(&_b[w], p, f);
_w = _inc(w, f);
c -= f;
p += f;
}
return n - c;
}
// reading thread/context API
// --------------------------------------------------------
bool readable(void)
{
return (_r != _w);
}
size_t size(void)
{
int s = _w - _r;
if (s < 0)
s += N;
return s;
}
T get(void)
{
int r = _r;
while (r == _w) // = !readable()
/* nothing / just wait */;
T t = _b[r];
_r = _inc(r);
return t;
}
T peek(void)
{
int r = _r;
while (r == _w);
return _b[r];
}
int get(T* p, int n, bool blocking = false)
{
int c = n;
while (c)
{
int f;
for (;;) // wait for data
{
f = size();
if (f) break; // free space
if (!blocking) return n - c; // no space and not blocking
/* nothing / just wait */;
}
// check available data
if (c < f) f = c;
int r = _r;
int m = N - r;
// check wrap
if (f > m) f = m;
memcpy(p, &_b[r], f);
_r = _inc(r, f);
c -= f;
p += f;
}
return n - c;
}
private:
int _inc(int i, int n = 1)
{
return (i + n) % N;
}
T _b[N];
volatile int _w;
volatile int _r;
};
#endif

Some files were not shown because too many files have changed in this diff Show More