Skip to content

Commit 542985f

Browse files
committed
first commit
0 parents  commit 542985f

30 files changed

+2100
-0
lines changed

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2015 Volodymyr Shymanskyy
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# README #
2+
3+
Blynk is a platform with iOS and Android apps to control Arduino, Raspberry Pi and the likes over the Internet.
4+
You can easily build graphic interfaces for all your projects by simply dragging and dropping widgets.
5+
* [Blynk downloads, docs and tutorials](http://www.blynk.cc). Currently in progress
6+
* [Blynk community](http://community.blynk.cc)
7+
* [Facebook](http://www.fb.com/blynkapp)
8+
* [Twitter](http://twitter.com/blynk_app)
9+
10+
Please find examples on how to use different types of connections (transports),
11+
and also how to do make something great with Blynk.
12+
You can easily apply any type of board/connection to all examples.
13+
14+
### Quickstart: Arduino + Ethernet shield ###
15+
16+
* Download Blynk app (soon in the App Store and Google Play)
17+
* Get the Auth Token from the app
18+
* Import this library to Arduino IDE. Guide [here](http://arduino.cc/en/guide/libraries)
19+
* In Arduino IDE, select File -> Examples -> Blynk -> Transports -> Ethernet
20+
* Update Auth Token in the sketch and upload it to Arduino
21+
* Connect your Arduino with Ethernet shield to the internet
22+
23+
### Supported hardware ###
24+
25+
[The list of supported hardware](http://community.blynk.cc/t/hardware-supported-by-blynk)
26+
27+
### Troubleshooting ###
28+
29+
To enable debug prints on default Serial, add on the top of your sketch (should be the first line):
30+
31+
#define BLYNK_DEBUG // Optional, this enables lots of prints
32+
#define BLYNK_PRINT Serial
33+
34+
And enable serial in setup():
35+
36+
Serial.begin(9600);
37+
38+
### License ###
39+
40+
This project is released under The MIT License (MIT)

firmware/Adapters/BlynkSparkCore.h

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* @file BlynkCC3000.h
3+
* @author Volodymyr Shymanskyy
4+
* @license This project is released under the MIT License (MIT)
5+
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
6+
* @date Mar 2015
7+
* @brief
8+
*
9+
*/
10+
11+
#ifndef BlynkCC3000_h
12+
#define BlynkCC3000_h
13+
14+
#define BLYNK_INFO_CONNECTION "CC3000"
15+
16+
#include <BlynkApiArduino.h>
17+
#include <Blynk/BlynkProtocol.h>
18+
#include <Adafruit_CC3000.h>
19+
20+
class BlynkTransportCC3000
21+
{
22+
public:
23+
BlynkTransportCC3000(Adafruit_CC3000& cc3000)
24+
: cc3000(cc3000), addr(0), port(0)
25+
{}
26+
27+
void begin(uint32_t a, uint16_t p) {
28+
port = p;
29+
addr = a;
30+
}
31+
32+
bool connect() {
33+
uint8_t* a = (uint8_t*)&addr;
34+
BLYNK_LOG("Connecting to %d.%d.%d.%d:%d", a[3], a[2], a[1], a[0], port);
35+
client = cc3000.connectTCP(addr, port);
36+
return client.connected();
37+
}
38+
39+
void disconnect() { client.stop(); }
40+
41+
size_t read(void* buf, size_t len) {
42+
return client.readBytes((char*)buf, len);
43+
}
44+
size_t write(const void* buf, size_t len) {
45+
return client.write((const uint8_t*)buf, len);
46+
}
47+
48+
void flush() { client.flush(); }
49+
bool connected() { return client.connected(); }
50+
int available() { return client.available(); }
51+
52+
private:
53+
Adafruit_CC3000& cc3000;
54+
Adafruit_CC3000_Client client;
55+
uint32_t addr;
56+
uint16_t port;
57+
};
58+
59+
class BlynkCC3000
60+
: public BlynkProtocol<BlynkTransportCC3000>
61+
{
62+
typedef BlynkProtocol<BlynkTransportCC3000> Base;
63+
public:
64+
BlynkCC3000(Adafruit_CC3000& cc3000, BlynkTransportCC3000& transp)
65+
: Base(transp), cc3000(cc3000)
66+
{}
67+
68+
void wifi_begin (const char* ssid,
69+
const char* pass,
70+
uint8_t secmode)
71+
{
72+
if (!cc3000.begin())
73+
{
74+
BLYNK_FATAL("Couldn't begin()! Check your wiring?");
75+
}
76+
/*if (!cc3000.deleteProfiles())
77+
{
78+
BLYNK_FATAL("Fail deleting old profiles");
79+
}*/
80+
BLYNK_LOG("Connecting to %s...", ssid);
81+
if (!cc3000.connectToAP(ssid, pass, secmode))
82+
{
83+
BLYNK_FATAL("Failed to connect to AP");
84+
}
85+
BLYNK_LOG("Getting IP address...");
86+
while (!cc3000.checkDHCP())
87+
{
88+
delay(100);
89+
}
90+
#ifdef BLYNK_PRINT
91+
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
92+
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
93+
{
94+
BLYNK_FATAL("Unable to get the IP Address");
95+
}
96+
uint8_t* addr = (uint8_t*)&ipAddress;
97+
BLYNK_LOG("IP: %d.%d.%d.%d", addr[3], addr[2], addr[1], addr[0]);
98+
addr = (uint8_t*)&gateway;
99+
BLYNK_LOG("GW: %d.%d.%d.%d", addr[3], addr[2], addr[1], addr[0]);
100+
addr = (uint8_t*)&dnsserv;
101+
BLYNK_LOG("DNS: %d.%d.%d.%d", addr[3], addr[2], addr[1], addr[0]);
102+
#endif
103+
}
104+
105+
void begin( const char* auth,
106+
const char* ssid,
107+
const char* pass,
108+
uint8_t secmode,
109+
const char* domain = BLYNK_DEFAULT_DOMAIN,
110+
uint16_t port = BLYNK_DEFAULT_PORT)
111+
{
112+
Base::begin(auth);
113+
wifi_begin(ssid, pass, secmode);
114+
uint32_t ip = 0;
115+
BLYNK_LOG("Looking for %s", domain);
116+
while (ip == 0) {
117+
if (!cc3000.getHostByName((char*)domain, &ip)) {
118+
BLYNK_LOG("Couldn't locate server");
119+
delay(500);
120+
}
121+
}
122+
123+
this->conn.begin(ip, port);
124+
}
125+
126+
void begin( const char* auth,
127+
const char* ssid,
128+
const char* pass,
129+
uint8_t secmode,
130+
IPAddress addr,
131+
uint16_t port)
132+
{
133+
Base::begin(auth);
134+
wifi_begin(ssid, pass, secmode);
135+
this->conn.begin(cc3000.IP2U32(addr[0],addr[1],addr[2],addr[3]), port);
136+
}
137+
private:
138+
Adafruit_CC3000& cc3000;
139+
};
140+
141+
#endif

firmware/Blynk/BlynkApi.h

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* @file BlynkApi.h
3+
* @author Volodymyr Shymanskyy
4+
* @license This project is released under the MIT License (MIT)
5+
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
6+
* @date Jan 2015
7+
* @brief High-level functions
8+
*
9+
*/
10+
11+
#ifndef BlynkApi_h
12+
#define BlynkApi_h
13+
14+
#include <Blynk/BlynkConfig.h>
15+
#include <Blynk/BlynkDebug.h>
16+
#include <Blynk/BlynkParam.h>
17+
#include <Blynk/BlynkHandlers.h>
18+
#include <Blynk/BlynkProtocolDefs.h>
19+
20+
/**
21+
* A test class. A more elaborate class description.
22+
*/
23+
template <class Proto>
24+
class BlynkApi
25+
{
26+
public:
27+
BlynkApi() {
28+
Init();
29+
}
30+
31+
template <typename T>
32+
void virtualWrite(int pin, const T& data) {
33+
char mem[64];
34+
BlynkParam cmd(mem, 0, sizeof(mem));
35+
cmd.add("vw");
36+
cmd.add(pin);
37+
cmd.add(data);
38+
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength());
39+
}
40+
41+
void virtualWrite(int pin, const void* buff, size_t len) {
42+
char mem[8];
43+
BlynkParam cmd(mem, 0, sizeof(mem));
44+
cmd.add("vw");
45+
cmd.add(pin);
46+
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_HARDWARE, 0, cmd.getBuffer(), cmd.getLength(), buff, len);
47+
}
48+
49+
void virtualWrite(int pin, const BlynkParam& param) {
50+
virtualWrite(pin, param.getBuffer(), param.getLength());
51+
}
52+
53+
void tweet(const char* msg) {
54+
size_t len = strlen(msg);
55+
if (len < 140) {
56+
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_TWEET, 0, msg, len);
57+
}
58+
}
59+
60+
#if defined(BLYNK_HAS_DELAY)
61+
62+
void delay(unsigned long ms) {
63+
uint16_t start = (uint16_t)micros();
64+
while (ms > 0) {
65+
static_cast<Proto*>(this)->run();
66+
if (((uint16_t)micros() - start) >= 1000) {
67+
ms--;
68+
start += 1000;
69+
}
70+
}
71+
}
72+
73+
#endif
74+
75+
protected:
76+
void Init();
77+
void processCmd(const void* buff, size_t len);
78+
79+
};
80+
81+
82+
#endif

firmware/Blynk/BlynkConfig.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @file BlynkConfig.h
3+
* @author Volodymyr Shymanskyy
4+
* @license This project is released under the MIT License (MIT)
5+
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
6+
* @date Jan 2015
7+
* @brief Configuration of different aspects of library
8+
*
9+
*/
10+
11+
#ifndef BlynkConfig_h
12+
#define BlynkConfig_h
13+
14+
// TODO: Document each setting
15+
16+
// Change these settings to match your need
17+
#define BLYNK_DEFAULT_DOMAIN "blynk-test-east.cloudapp.net"
18+
#define BLYNK_DEFAULT_PORT 8442
19+
#define BLYNK_MAX_READBYTES 255
20+
21+
// Professional settings
22+
#define BLYNK_VERSION "0.1.6"
23+
#define BLYNK_HEARTBEAT 10
24+
#define BLYNK_TIMEOUT_MS 1500
25+
//#define BLYNK_DEBUG
26+
27+
#endif

0 commit comments

Comments
 (0)