Skip to content
Snippets Groups Projects
Commit 16711d73 authored by Joe Revans's avatar Joe Revans
Browse files

Annouce Capabilities

parent 9fa037e0
No related branches found
No related tags found
3 merge requests!4Joe merge,!2Docs,!1Pactman/VizBlocks Merge
...@@ -34,6 +34,8 @@ class WallVis { ...@@ -34,6 +34,8 @@ class WallVis {
WiFiClient* _client; WiFiClient* _client;
boolean _wifi; boolean _wifi;
String capabilitiesJSON[50];
public: public:
WallVis(char* id, char* ssid="WallVisNet", char* wifi_pass="wallvisAP", WallVis(char* id, char* ssid="WallVisNet", char* wifi_pass="wallvisAP",
char* server="172.20.10.8",int port=1883) : _id(id), _server(server), _port(port), _ssid(ssid), _wifi_pass(wifi_pass) {} ; char* server="172.20.10.8",int port=1883) : _id(id), _server(server), _port(port), _ssid(ssid), _wifi_pass(wifi_pass) {} ;
...@@ -95,6 +97,7 @@ public: ...@@ -95,6 +97,7 @@ public:
MQTT_connect(); MQTT_connect();
} }
generateCapabilitiesJSON();
announce_capabilities(); announce_capabilities();
Serial.println("Init finished"); Serial.println("Init finished");
...@@ -223,15 +226,24 @@ public: ...@@ -223,15 +226,24 @@ public:
Serial.println("MQTT Connected!"); Serial.println("MQTT Connected!");
} }
void generateCapabilitiesJSON() {
String head = "{\"name\":\"" + String(_id) + "\",\"behaviour\":{";
for (int i = 0; i < _behaviours.get_num_behaviours(); i++) {
Behaviour* b = _behaviours.get_by_num(i);
String args = b->args();
String body = "\"index\":\"" + String(i) + "\",\"name\":\"" + b->name() + "\",\"args\":\"" + args + "\"}}";
String str = head + body;
capabilitiesJSON[i] = str;
}
}
void announce_capabilities() { void announce_capabilities() {
Serial.print("Node "); String doc;
Serial.println(_id);
if( _wifi ) { if( _wifi ) {
if( ! _announce->publish(_id) ) { Serial.println("Couldn't make announcement"); } if( ! _announce->publish(_id) ) { Serial.println("Couldn't make announcement"); }
} }
for( int i = 0; i < _behaviours.get_num_behaviours(); i++ ) { for( int i = 0; i < _behaviours.get_num_behaviours(); i++ ) {
Behaviour* b = _behaviours.get_by_num(i); doc = capabilitiesJSON[i];
String doc = b->name() + ": " + b->args();
if( _wifi ) { _my_announce->publish(doc.c_str()); } if( _wifi ) { _my_announce->publish(doc.c_str()); }
Serial.print("-->"); Serial.print("-->");
Serial.println(doc); Serial.println(doc);
...@@ -247,22 +259,31 @@ public: ...@@ -247,22 +259,31 @@ public:
Serial.println(doc); Serial.println(doc);
} }
void input_greeting() {
if( _wifi ) {
if( ! _input->publish(_id) ) { Serial.println("Couldn't publish input greeting"); }
}
String doc = String("This is ") + String(_id) + String("'s input channel. Hello!'");
if( _wifi ) { _my_input->publish(doc.c_str()); }
Serial.print("-->");
Serial.println(doc);
}
void setID(char* id) { void setID(char* id) {
_id = id; _id = id;
} }
}; };
class SendCapabilities : public Behaviour {
/*
* Class that defines a behaviour that publishes a
* ButtonPressed message to the input topic of the
* MQQT broker
*/
WallVis* _node;
public:
SendCapabilities(WallVis* node, String name = "SendCapabilities") :
Behaviour(name), _node(node){ }
String start(String args) {
//This is where you do your stuff for a simple behaviour
_node->announce_capabilities();
return "SendCapabilities behaviour " + _name;
}
};
/* /*
* Button Behaviours depend on WallVis class so they must be included after * Button Behaviours depend on WallVis class so they must be included after
* it has been defined. * it has been defined.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment