mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
use mediator to distribute messages via dispatch method
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user