use mediator to distribute messages via dispatch method

This commit is contained in:
2018-11-05 16:47:52 +01:00
parent 5415a0345e
commit bb81391d00
4 changed files with 47 additions and 16 deletions

View File

@@ -44,10 +44,10 @@ void Sprocket::loop(){
}
void Sprocket::dispatch( uint32_t from, String &msg ) {
SprocketMessage mMsg;
mMsg.fromJsonString(msg);
if(mMsg.valid){
dispatchMessageToPlugins(mMsg);
currentMessage.fromJsonString(msg);
if(currentMessage.valid){
currentMessage.from = from;
publish(currentMessage.topic, currentMessage.payload);
}
}
@@ -61,14 +61,4 @@ void Sprocket::activatePlugins(Scheduler* scheduler, Network* network){
for(Plugin* p : plugins){
p->activate(scheduler, network);
}
}
// TODO remove plugin dispatching and onMessage in favor of mediator pub/sub
void Sprocket::dispatchMessageToPlugins(SprocketMessage msg){
if(msg.type != SprocketMessage::NONE){ // baaaa
for(Plugin* p : plugins){
//Serial.println("dispatch to plugins");
p->onMessage(msg);
}
}
}

View File

@@ -25,6 +25,8 @@ class Sprocket : public Mediator {
// => see difference between standalone and mesh sprochet usage of scheduler
Scheduler scheduler;
Network network;
private:
SprocketMessage currentMessage;
public:
SprocketConfig config;
std::vector<Plugin*> plugins;

View File

@@ -59,8 +59,8 @@ int WiFiNet::createAccessPoint(){
WiFi.disconnect();
WiFi.mode(WIFI_AP);
WiFi.softAP(config.apSSID.c_str(), config.apPassword.c_str());
Serial.println("SoftAP IP address: ");
Serial.println(WiFi.softAPIP().toString());
String softApPrt = "SoftAP IP: " + WiFi.softAPIP().toString();
Serial.println(softApPrt.c_str());
return 1;
}