mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-05 13:16:13 +03:00
Spacebrew update
This commit is contained in:
@@ -40,9 +40,7 @@ void setup() {
|
|||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial) {
|
while (!Serial) { ; }
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
// start-up the bridge
|
// start-up the bridge
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
@@ -68,7 +66,8 @@ void setup() {
|
|||||||
|
|
||||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||||
sb.connect("sandbox.spacebrew.cc");
|
sb.connect("sandbox.spacebrew.cc");
|
||||||
|
// we give some time to arduino to connect to sandbox, otherwise the first sb.monitor(); call will give an error
|
||||||
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -94,6 +93,7 @@ void loop() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// define handler methods, all standard data type handlers take two appropriate arguments
|
// define handler methods, all standard data type handlers take two appropriate arguments
|
||||||
|
@@ -40,9 +40,7 @@ void setup() {
|
|||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial) {
|
while (!Serial) { ; }
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
// start-up the bridge
|
// start-up the bridge
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
|
@@ -41,9 +41,7 @@ void setup() {
|
|||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial) {
|
while (!Serial) { ; }
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
// start-up the bridge
|
// start-up the bridge
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
|
@@ -38,9 +38,7 @@ void setup() {
|
|||||||
|
|
||||||
// for debugging, wait until a serial console is connected
|
// for debugging, wait until a serial console is connected
|
||||||
delay(4000);
|
delay(4000);
|
||||||
while (!Serial) {
|
while (!Serial) { ; }
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
// start-up the bridge
|
// start-up the bridge
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
SpacebrewYun KEYWORD3
|
SpacebrewYun KEYWORD1
|
||||||
addPublish KEYWORD2
|
addPublish KEYWORD2
|
||||||
addSubscribe KEYWORD2
|
addSubscribe KEYWORD2
|
||||||
connect KEYWORD2
|
connect KEYWORD2
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
name=SpacebrewYun
|
name=SpacebrewYun
|
||||||
version=1.0
|
|
||||||
author=Julio Terra
|
author=Julio Terra
|
||||||
maintainer=Julio Terra <julioterra@gmail.com>
|
email=julioterra@gmail.com
|
||||||
sentence=Easily connect the Arduino Yun to Spacebrew
|
sentence=Easily connect the Arduino Yun to Spacebrew
|
||||||
paragraph=This library was developed to enable you to easily connect the Arduino Yun to Spacebrew. To learn more about Spacebrew visit Spacebrew.cc
|
paragraph=This library was developed to enable you to easily connect the Arduino Yun to Spacebrew. To learn more about Spacebrew visit Spacebrew.cc
|
||||||
url=https://github.com/julioterra/yunSpacebrew
|
url=https://github.com/julioterra/yunSpacebrew
|
||||||
architectures=*
|
architectures=avr
|
||||||
|
version=1.0
|
||||||
|
dependencies=Bridge
|
||||||
|
core-dependencies=arduino (>=1.5.0)
|
@@ -10,6 +10,7 @@ SpacebrewYun::SpacebrewYun(const String& _name, const String& _description) {
|
|||||||
server = "sandbox.spacebrew.cc";
|
server = "sandbox.spacebrew.cc";
|
||||||
port = 9000;
|
port = 9000;
|
||||||
|
|
||||||
|
_started = false;
|
||||||
_connected = false;
|
_connected = false;
|
||||||
_verbose = false;
|
_verbose = false;
|
||||||
_error_msg = false;
|
_error_msg = false;
|
||||||
@@ -21,6 +22,9 @@ SpacebrewYun::SpacebrewYun(const String& _name, const String& _description) {
|
|||||||
read_name = false;
|
read_name = false;
|
||||||
read_msg = false;
|
read_msg = false;
|
||||||
|
|
||||||
|
connect_attempt = 0;
|
||||||
|
connect_attempt_inter = 10000;
|
||||||
|
|
||||||
for ( int i = 0; i < pidLength; i++ ) {
|
for ( int i = 0; i < pidLength; i++ ) {
|
||||||
pid [i] = '\0';
|
pid [i] = '\0';
|
||||||
}
|
}
|
||||||
@@ -123,8 +127,11 @@ void SpacebrewYun::addSubscribe(const String& name, const String& type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpacebrewYun::connect(String _server, int _port) {
|
void SpacebrewYun::connect(String _server, int _port) {
|
||||||
|
Serial.print(F("NEW LIB"));
|
||||||
|
_started = true;
|
||||||
server = _server;
|
server = _server;
|
||||||
port = _port;
|
port = _port;
|
||||||
|
connect_attempt = millis();
|
||||||
|
|
||||||
killPids();
|
killPids();
|
||||||
|
|
||||||
@@ -189,16 +196,23 @@ void SpacebrewYun::connect(String _server, int _port) {
|
|||||||
if (_verbose) {
|
if (_verbose) {
|
||||||
Serial.println(F("Brew started "));
|
Serial.println(F("Brew started "));
|
||||||
}
|
}
|
||||||
while (!Console) {
|
while (!Console) { ; }
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpacebrewYun::monitor() {
|
void SpacebrewYun::monitor() {
|
||||||
|
|
||||||
|
// if not connected try to reconnect after appropriate interval
|
||||||
|
if (_started && !_connected) {
|
||||||
|
if ((millis() - connect_attempt) > connect_attempt_inter) {
|
||||||
|
connect(server, port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if message received from console, then process it
|
||||||
while (Console.available() > 0) {
|
while (Console.available() > 0) {
|
||||||
char c = Console.read();
|
char c = Console.read();
|
||||||
|
|
||||||
if (c == char(CONNECTION_START) && !_connected) {
|
if (c == char(CONNECTION_START) && _started && !_connected) {
|
||||||
if (_verbose) {
|
if (_verbose) {
|
||||||
Serial.print(F("Connected to spacebrew server at: "));
|
Serial.print(F("Connected to spacebrew server at: "));
|
||||||
Serial.println(server);
|
Serial.println(server);
|
||||||
@@ -210,6 +224,7 @@ void SpacebrewYun::monitor() {
|
|||||||
}
|
}
|
||||||
_connected = true;
|
_connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (c == char(CONNECTION_END) && _connected) {
|
else if (c == char(CONNECTION_END) && _connected) {
|
||||||
_connected = false;
|
_connected = false;
|
||||||
if (_verbose) {
|
if (_verbose) {
|
||||||
@@ -269,7 +284,8 @@ void SpacebrewYun::monitor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (publishers != NULL) {
|
// check if received confirmation that linino received messages
|
||||||
|
if (publishers != NULL && _connected) {
|
||||||
struct Publisher *curr = publishers;
|
struct Publisher *curr = publishers;
|
||||||
while((curr != NULL)){
|
while((curr != NULL)){
|
||||||
|
|
||||||
@@ -292,10 +308,6 @@ void SpacebrewYun::onConfirm() {
|
|||||||
while((curr != NULL)){
|
while((curr != NULL)){
|
||||||
if (sub_name.equals(curr->name) == true) {
|
if (sub_name.equals(curr->name) == true) {
|
||||||
curr->confirmed = true;
|
curr->confirmed = true;
|
||||||
// if (_verbose) {
|
|
||||||
// Serial.print(F("confirmed "));
|
|
||||||
// Serial.println(curr->name);
|
|
||||||
// }
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
|
@@ -44,12 +44,8 @@ class SpacebrewYun {
|
|||||||
void addSubscribe(const String&, const String&);
|
void addSubscribe(const String&, const String&);
|
||||||
|
|
||||||
void connect(String, int);
|
void connect(String, int);
|
||||||
void connect() {
|
void connect() { connect(server, port); };
|
||||||
connect(server, port);
|
void connect(String _server) { connect(String(_server), port); };
|
||||||
};
|
|
||||||
void connect(String _server) {
|
|
||||||
connect(String(_server), port);
|
|
||||||
};
|
|
||||||
|
|
||||||
void monitor();
|
void monitor();
|
||||||
void onMessage();
|
void onMessage();
|
||||||
@@ -58,21 +54,11 @@ class SpacebrewYun {
|
|||||||
boolean connected();
|
boolean connected();
|
||||||
|
|
||||||
void send(const String&, const String&);
|
void send(const String&, const String&);
|
||||||
void send(const String& name, char * value) {
|
void send(const String& name, char * value) { send(name, String(value)); }
|
||||||
send(name, String(value));
|
void send(const String& name, bool value){ send(name, (value ? String("true") : String("false"))); };
|
||||||
}
|
void send(const String& name, int value) { send(name, String(value)); };
|
||||||
void send(const String& name, bool value) {
|
void send(const String& name, long value) { send(name, String(value)); };
|
||||||
send(name, (value ? String("true") : String("false")));
|
void send(const String& name, float value) { send(name, String(value)); };
|
||||||
};
|
|
||||||
void send(const String& name, int value) {
|
|
||||||
send(name, String(value));
|
|
||||||
};
|
|
||||||
void send(const String& name, long value) {
|
|
||||||
send(name, String(value));
|
|
||||||
};
|
|
||||||
void send(const String& name, float value) {
|
|
||||||
send(name, String(value));
|
|
||||||
};
|
|
||||||
|
|
||||||
void verbose(boolean);
|
void verbose(boolean);
|
||||||
|
|
||||||
@@ -98,6 +84,7 @@ class SpacebrewYun {
|
|||||||
String name;
|
String name;
|
||||||
String server;
|
String server;
|
||||||
String description;
|
String description;
|
||||||
|
boolean _started;
|
||||||
boolean _connected;
|
boolean _connected;
|
||||||
boolean _error_msg;
|
boolean _error_msg;
|
||||||
boolean _verbose;
|
boolean _verbose;
|
||||||
@@ -125,8 +112,9 @@ class SpacebrewYun {
|
|||||||
static int sub_msg_str_max;
|
static int sub_msg_str_max;
|
||||||
static int sub_msg_int_max;
|
static int sub_msg_int_max;
|
||||||
static int sub_msg_bool_max;
|
static int sub_msg_bool_max;
|
||||||
// int sub_name_max;
|
|
||||||
// int sub_msg_str_max;
|
long connect_attempt;
|
||||||
|
int connect_attempt_inter;
|
||||||
|
|
||||||
Process pids;
|
Process pids;
|
||||||
char pid [6];
|
char pid [6];
|
||||||
|
Reference in New Issue
Block a user