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
No related merge requests found
......@@ -34,6 +34,8 @@ class WallVis {
WiFiClient* _client;
boolean _wifi;
String capabilitiesJSON[50];
public:
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) {} ;
......@@ -95,6 +97,7 @@ public:
MQTT_connect();
}
generateCapabilitiesJSON();
announce_capabilities();
Serial.println("Init finished");
......@@ -223,15 +226,24 @@ public:
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() {
Serial.print("Node ");
Serial.println(_id);
String doc;
if( _wifi ) {
if( ! _announce->publish(_id) ) { Serial.println("Couldn't make announcement"); }
}
for( int i = 0; i < _behaviours.get_num_behaviours(); i++ ) {
Behaviour* b = _behaviours.get_by_num(i);
String doc = b->name() + ": " + b->args();
doc = capabilitiesJSON[i];
if( _wifi ) { _my_announce->publish(doc.c_str()); }
Serial.print("-->");
Serial.println(doc);
......@@ -247,22 +259,31 @@ public:
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) {
_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
* 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