1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Spacebrew update

This commit is contained in:
Federico Fissore
2014-04-01 09:35:56 +02:00
parent 2f7e712fb9
commit 88ed5d53a6
8 changed files with 679 additions and 683 deletions

View File

@ -40,9 +40,7 @@ void setup() {
// for debugging, wait until a serial console is connected
delay(4000);
while (!Serial) {
;
}
while (!Serial) { ; }
// start-up the bridge
Bridge.begin();
@ -68,7 +66,8 @@ void setup() {
// connect to cloud spacebrew server at "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

View File

@ -40,9 +40,7 @@ void setup() {
// for debugging, wait until a serial console is connected
delay(4000);
while (!Serial) {
;
}
while (!Serial) { ; }
// start-up the bridge
Bridge.begin();

View File

@ -41,9 +41,7 @@ void setup() {
// for debugging, wait until a serial console is connected
delay(4000);
while (!Serial) {
;
}
while (!Serial) { ; }
// start-up the bridge
Bridge.begin();

View File

@ -38,9 +38,7 @@ void setup() {
// for debugging, wait until a serial console is connected
delay(4000);
while (!Serial) {
;
}
while (!Serial) { ; }
// start-up the bridge
Bridge.begin();

View File

@ -1,4 +1,4 @@
SpacebrewYun KEYWORD3
SpacebrewYun KEYWORD1
addPublish KEYWORD2
addSubscribe KEYWORD2
connect KEYWORD2

View File

@ -1,8 +1,10 @@
name=SpacebrewYun
version=1.0
author=Julio Terra
maintainer=Julio Terra <julioterra@gmail.com>
email=julioterra@gmail.com
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
url=https://github.com/julioterra/yunSpacebrew
architectures=*
architectures=avr
version=1.0
dependencies=Bridge
core-dependencies=arduino (>=1.5.0)

View File

@ -10,6 +10,7 @@ SpacebrewYun::SpacebrewYun(const String& _name, const String& _description) {
server = "sandbox.spacebrew.cc";
port = 9000;
_started = false;
_connected = false;
_verbose = false;
_error_msg = false;
@ -21,6 +22,9 @@ SpacebrewYun::SpacebrewYun(const String& _name, const String& _description) {
read_name = false;
read_msg = false;
connect_attempt = 0;
connect_attempt_inter = 10000;
for ( int i = 0; i < pidLength; i++ ) {
pid [i] = '\0';
}
@ -123,8 +127,11 @@ void SpacebrewYun::addSubscribe(const String& name, const String& type) {
}
void SpacebrewYun::connect(String _server, int _port) {
Serial.print(F("NEW LIB"));
_started = true;
server = _server;
port = _port;
connect_attempt = millis();
killPids();
@ -189,16 +196,23 @@ void SpacebrewYun::connect(String _server, int _port) {
if (_verbose) {
Serial.println(F("Brew started "));
}
while (!Console) {
;
}
while (!Console) { ; }
}
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) {
char c = Console.read();
if (c == char(CONNECTION_START) && !_connected) {
if (c == char(CONNECTION_START) && _started && !_connected) {
if (_verbose) {
Serial.print(F("Connected to spacebrew server at: "));
Serial.println(server);
@ -210,6 +224,7 @@ void SpacebrewYun::monitor() {
}
_connected = true;
}
else if (c == char(CONNECTION_END) && _connected) {
_connected = false;
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;
while((curr != NULL)){
@ -292,10 +308,6 @@ void SpacebrewYun::onConfirm() {
while((curr != NULL)){
if (sub_name.equals(curr->name) == true) {
curr->confirmed = true;
// if (_verbose) {
// Serial.print(F("confirmed "));
// Serial.println(curr->name);
// }
break;
}
curr = curr->next;

View File

@ -44,12 +44,8 @@ class SpacebrewYun {
void addSubscribe(const String&, const String&);
void connect(String, int);
void connect() {
connect(server, port);
};
void connect(String _server) {
connect(String(_server), port);
};
void connect() { connect(server, port); };
void connect(String _server) { connect(String(_server), port); };
void monitor();
void onMessage();
@ -58,21 +54,11 @@ class SpacebrewYun {
boolean connected();
void send(const String&, const String&);
void send(const String& name, char * 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, long value) {
send(name, String(value));
};
void send(const String& name, float value) {
send(name, String(value));
};
void send(const String& name, char * 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, long value) { send(name, String(value)); };
void send(const String& name, float value) { send(name, String(value)); };
void verbose(boolean);
@ -98,6 +84,7 @@ class SpacebrewYun {
String name;
String server;
String description;
boolean _started;
boolean _connected;
boolean _error_msg;
boolean _verbose;
@ -125,8 +112,9 @@ class SpacebrewYun {
static int sub_msg_str_max;
static int sub_msg_int_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;
char pid [6];