chore: rename ClusterContext to NodeContext
This commit is contained in:
22
README.md
22
README.md
@@ -14,14 +14,28 @@ SProcket ORchestration Engine
|
|||||||
|
|
||||||
- ESP8266
|
- ESP8266
|
||||||
|
|
||||||
## Configuration
|
## Architecture
|
||||||
|
|
||||||
|
### Auto Discovery
|
||||||
|
|
||||||
|
A node periodically executes 2 tasks responsible for auto discovers:
|
||||||
|
|
||||||
|
- send discovery: send UDP packet on broadcast address to discover nodes
|
||||||
|
- listen for discovery: receive UDP packets and send response back to the node who initiated discovery
|
||||||
|
|
||||||
|
Discovered nodes are added to the so cluster memberlist.
|
||||||
|
Another periodic task will then call the `/api/node/status` endpoint over HTTP on each node in the memberlist to get detailed informations about the node (e.g. freeHeap, available API endpoints).
|
||||||
|
|
||||||
|
## Develop
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
Choose one of your nodes as the API node to interact with the cluster and configure it in `.env`:
|
Choose one of your nodes as the API node to interact with the cluster and configure it in `.env`:
|
||||||
```sh
|
```sh
|
||||||
export API_NODE=10.0.1.x
|
export API_NODE=10.0.1.x
|
||||||
```
|
```
|
||||||
|
|
||||||
## Build
|
### Build
|
||||||
|
|
||||||
Build the firmware:
|
Build the firmware:
|
||||||
|
|
||||||
@@ -29,14 +43,14 @@ Build the firmware:
|
|||||||
./ctl.sh build
|
./ctl.sh build
|
||||||
```
|
```
|
||||||
|
|
||||||
## Flash
|
### Flash
|
||||||
|
|
||||||
Flash firmware to a connected device:
|
Flash firmware to a connected device:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./ctl.sh flash
|
./ctl.sh flash
|
||||||
```
|
```
|
||||||
## OTA
|
### OTA
|
||||||
|
|
||||||
Update one nodes:
|
Update one nodes:
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "ClusterManager.h"
|
#include "ClusterManager.h"
|
||||||
|
|
||||||
ClusterManager::ClusterManager(ClusterContext& ctx) : ctx(ctx) {
|
ClusterManager::ClusterManager(NodeContext& ctx) : ctx(ctx) {
|
||||||
// Register callback for node_discovered event
|
// Register callback for node_discovered event
|
||||||
ctx.registerEvent("node_discovered", [this](void* data) {
|
ctx.registerEvent("node_discovered", [this](void* data) {
|
||||||
NodeInfo* node = static_cast<NodeInfo*>(data);
|
NodeInfo* node = static_cast<NodeInfo*>(data);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "ClusterContext.h"
|
#include "NodeContext.h"
|
||||||
#include "NodeInfo.h"
|
#include "NodeInfo.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
class ClusterManager {
|
class ClusterManager {
|
||||||
public:
|
public:
|
||||||
ClusterManager(ClusterContext& ctx);
|
ClusterManager(NodeContext& ctx);
|
||||||
void sendDiscovery();
|
void sendDiscovery();
|
||||||
void listenForDiscovery();
|
void listenForDiscovery();
|
||||||
void addOrUpdateNode(const String& nodeHost, IPAddress nodeIP);
|
void addOrUpdateNode(const String& nodeHost, IPAddress nodeIP);
|
||||||
@@ -22,5 +22,5 @@ public:
|
|||||||
void heartbeatTaskCallback();
|
void heartbeatTaskCallback();
|
||||||
void updateAllMembersInfoTaskCallback();
|
void updateAllMembersInfoTaskCallback();
|
||||||
private:
|
private:
|
||||||
ClusterContext& ctx;
|
NodeContext& ctx;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
const char* STA_SSID = "shroud";
|
const char* STA_SSID = "shroud";
|
||||||
const char* STA_PASS = "th3r31sn0sp00n";
|
const char* STA_PASS = "th3r31sn0sp00n";
|
||||||
|
|
||||||
NetworkManager::NetworkManager(ClusterContext& ctx) : ctx(ctx) {}
|
NetworkManager::NetworkManager(NodeContext& ctx) : ctx(ctx) {}
|
||||||
|
|
||||||
void NetworkManager::setHostnameFromMac() {
|
void NetworkManager::setHostnameFromMac() {
|
||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ClusterContext.h"
|
#include "NodeContext.h"
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
|
||||||
class NetworkManager {
|
class NetworkManager {
|
||||||
public:
|
public:
|
||||||
NetworkManager(ClusterContext& ctx);
|
NetworkManager(NodeContext& ctx);
|
||||||
void setupWiFi();
|
void setupWiFi();
|
||||||
void setHostnameFromMac();
|
void setHostnameFromMac();
|
||||||
private:
|
private:
|
||||||
ClusterContext& ctx;
|
NodeContext& ctx;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
#include "ClusterContext.h"
|
#include "NodeContext.h"
|
||||||
|
|
||||||
ClusterContext::ClusterContext() {
|
NodeContext::NodeContext() {
|
||||||
scheduler = new Scheduler();
|
scheduler = new Scheduler();
|
||||||
udp = new WiFiUDP();
|
udp = new WiFiUDP();
|
||||||
memberList = new std::vector<NodeInfo>();
|
memberList = new std::vector<NodeInfo>();
|
||||||
hostname = "";
|
hostname = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
ClusterContext::~ClusterContext() {
|
NodeContext::~NodeContext() {
|
||||||
delete scheduler;
|
delete scheduler;
|
||||||
delete udp;
|
delete udp;
|
||||||
delete memberList;
|
delete memberList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClusterContext::registerEvent(const std::string& event, EventCallback cb) {
|
void NodeContext::registerEvent(const std::string& event, EventCallback cb) {
|
||||||
eventRegistry[event].push_back(cb);
|
eventRegistry[event].push_back(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClusterContext::triggerEvent(const std::string& event, void* data) {
|
void NodeContext::triggerEvent(const std::string& event, void* data) {
|
||||||
for (auto& cb : eventRegistry[event]) {
|
for (auto& cb : eventRegistry[event]) {
|
||||||
cb(data);
|
cb(data);
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,10 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class ClusterContext {
|
class NodeContext {
|
||||||
public:
|
public:
|
||||||
ClusterContext();
|
NodeContext();
|
||||||
~ClusterContext();
|
~NodeContext();
|
||||||
Scheduler* scheduler;
|
Scheduler* scheduler;
|
||||||
WiFiUDP* udp;
|
WiFiUDP* udp;
|
||||||
String hostname;
|
String hostname;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "RestApiServer.h"
|
#include "RestApiServer.h"
|
||||||
|
|
||||||
RestApiServer::RestApiServer(ClusterContext& ctx, uint16_t port) : server(port), ctx(ctx) {}
|
RestApiServer::RestApiServer(NodeContext& ctx, uint16_t port) : server(port), ctx(ctx) {}
|
||||||
|
|
||||||
void RestApiServer::addEndpoint(const String& uri, int method, std::function<void(AsyncWebServerRequest*)> requestHandler) {
|
void RestApiServer::addEndpoint(const String& uri, int method, std::function<void(AsyncWebServerRequest*)> requestHandler) {
|
||||||
serviceRegistry.push_back(std::make_tuple(uri, method));
|
serviceRegistry.push_back(std::make_tuple(uri, method));
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
#include "ClusterContext.h"
|
#include "NodeContext.h"
|
||||||
#include "NodeInfo.h"
|
#include "NodeInfo.h"
|
||||||
|
|
||||||
#define DEBUG_UPDATER 1
|
#define DEBUG_UPDATER 1
|
||||||
@@ -17,14 +17,14 @@ using namespace std::placeholders;
|
|||||||
|
|
||||||
class RestApiServer {
|
class RestApiServer {
|
||||||
public:
|
public:
|
||||||
RestApiServer(ClusterContext& ctx, uint16_t port = 80);
|
RestApiServer(NodeContext& ctx, uint16_t port = 80);
|
||||||
void begin();
|
void begin();
|
||||||
void addEndpoint(const String& uri, int method, std::function<void(AsyncWebServerRequest*)> requestHandler);
|
void addEndpoint(const String& uri, int method, std::function<void(AsyncWebServerRequest*)> requestHandler);
|
||||||
void addEndpoint(const String& uri, int method, std::function<void(AsyncWebServerRequest*)> requestHandler,
|
void addEndpoint(const String& uri, int method, std::function<void(AsyncWebServerRequest*)> requestHandler,
|
||||||
std::function<void(AsyncWebServerRequest*, const String&, size_t, uint8_t*, size_t, bool)> uploadHandler);
|
std::function<void(AsyncWebServerRequest*, const String&, size_t, uint8_t*, size_t, bool)> uploadHandler);
|
||||||
private:
|
private:
|
||||||
AsyncWebServer server;
|
AsyncWebServer server;
|
||||||
ClusterContext& ctx;
|
NodeContext& ctx;
|
||||||
std::vector<std::tuple<String, int>> serviceRegistry;
|
std::vector<std::tuple<String, int>> serviceRegistry;
|
||||||
void getClusterMembersJson(AsyncWebServerRequest *request);
|
void getClusterMembersJson(AsyncWebServerRequest *request);
|
||||||
void methodToStr(const std::tuple<String, int> &endpoint, ArduinoJson::V742PB22::JsonObject &apiObj);
|
void methodToStr(const std::tuple<String, int> &endpoint, ArduinoJson::V742PB22::JsonObject &apiObj);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "ClusterContext.h"
|
#include "NodeContext.h"
|
||||||
#include "NetworkManager.h"
|
#include "NetworkManager.h"
|
||||||
#include "ClusterManager.h"
|
#include "ClusterManager.h"
|
||||||
#include "RestApiServer.h"
|
#include "RestApiServer.h"
|
||||||
|
|
||||||
ClusterContext ctx;
|
NodeContext ctx;
|
||||||
NetworkManager network(ctx);
|
NetworkManager network(ctx);
|
||||||
ClusterManager cluster(ctx);
|
ClusterManager cluster(ctx);
|
||||||
RestApiServer apiServer(ctx);
|
RestApiServer apiServer(ctx);
|
||||||
|
|||||||
Reference in New Issue
Block a user