Generic firmware proof of concept
parent
318b378c54
commit
6ee1650381
|
@ -0,0 +1 @@
|
|||
../Makefile
|
|
@ -0,0 +1,2 @@
|
|||
SPIFF_SIZE = 196600
|
||||
DISABLE_SPIFFS = 0
|
|
@ -0,0 +1,13 @@
|
|||
#include <SpejsNode.h>
|
||||
#include <endpoints/OutputEndpoint.h>
|
||||
#include <endpoints/DHTEndpoint.h>
|
||||
|
||||
SpejsNode node("unconfigured-generic-device");
|
||||
|
||||
void init() {
|
||||
node.init();
|
||||
node.loadJSON({
|
||||
&OutputEndpoint::fromJSON,
|
||||
&DHTEndpoint::fromJSON,
|
||||
});
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "testdev",
|
||||
|
||||
"extras": {
|
||||
"owner": "informatic",
|
||||
"description": "This is just a testing device"
|
||||
},
|
||||
|
||||
"endpoints": {
|
||||
"out": {"type": "output", "gpio": 2},
|
||||
"testInput": {"type": "input", "gpio": 3},
|
||||
"testtemp": {"type": "dht"}
|
||||
}
|
||||
}
|
|
@ -34,6 +34,10 @@ public:
|
|||
}
|
||||
|
||||
virtual void onConnected();
|
||||
|
||||
static Endpoint* fromJSON(JsonObject& obj) {
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T> class ValueEndpoint : public Endpoint {
|
||||
|
@ -45,27 +49,6 @@ public:
|
|||
ValueEndpoint(String _type) : Endpoint(_type) {}
|
||||
};
|
||||
|
||||
struct endpoint_def {
|
||||
char* name;
|
||||
Endpoint* (*constructor)(void);
|
||||
};
|
||||
|
||||
//extern int __papiez_pedofil;
|
||||
|
||||
extern struct endpoint_def* __stop_endpoints[];
|
||||
extern struct endpoint_def* __start_endpoints[];
|
||||
|
||||
|
||||
#define DECLARE_ENDPOINT(name, constructor) \
|
||||
struct endpoint_def name ## _def __attribute__ ((section (".endpoints"))) = {\
|
||||
(char*) #name, constructor \
|
||||
};
|
||||
|
||||
// static struct endpoint_def name ## _def = { \
|
||||
// (char*) #name, constructor \
|
||||
// }; \
|
||||
//& name##_def
|
||||
|
||||
#define ENDPOINTS_COUNT (((uint8_t*) __stop_endpoints - (uint8_t*) __start_endpoints) / sizeof(struct endpoint_def))
|
||||
typedef Endpoint* (*EndpointInitializer) (JsonObject&);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <endpoints/ImplementationEndpoint.h>
|
||||
|
||||
#define CONFIG_FILE "config.json"
|
||||
|
||||
void SpejsNode::init() {
|
||||
deviceID = WifiStation.getMAC().substring(6, 12);
|
||||
|
||||
|
@ -29,26 +31,51 @@ void SpejsNode::init() {
|
|||
// Keepalive Timer initialization
|
||||
keepaliveTimer.initializeMs(10000, TimerDelegate(&SpejsNode::keepAliveHandler, this)).start();
|
||||
|
||||
loadJSON();
|
||||
|
||||
statusLED.high();
|
||||
}
|
||||
|
||||
//extern int __papiez_pedofil;
|
||||
void SpejsNode::loadJSON(std::vector<EndpointInitializer> initializers) {
|
||||
#ifdef RBOOT_SPIFFS_0
|
||||
debugf("trying to mount spiffs at 0x%08x, length %d", RBOOT_SPIFFS_0, SPIFF_SIZE);
|
||||
spiffs_mount_manual(RBOOT_SPIFFS_0, SPIFF_SIZE);
|
||||
#else
|
||||
debugf("trying to mount spiffs at 0x%08x, length %d", 0x100000, SPIFF_SIZE);
|
||||
spiffs_mount_manual(0x100000, SPIFF_SIZE);
|
||||
#endif
|
||||
|
||||
void SpejsNode::loadJSON() {
|
||||
/*
|
||||
Serial.printf("start: %08x\n", __start_endpoints);
|
||||
Serial.printf("stop: %08x\n", __stop_endpoints);
|
||||
Serial.printf("Endpoints count: %d\n", ENDPOINTS_COUNT);
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
if (fileExist(CONFIG_FILE)) {
|
||||
Serial.println("Found config file");
|
||||
int size = fileGetSize(CONFIG_FILE);
|
||||
Serial.printf("%d bytes\n", size);
|
||||
char* jsonString = new char[size + 1];
|
||||
fileGetContent(CONFIG_FILE, jsonString, size + 1);
|
||||
JsonObject& root = jsonBuffer.parseObject(jsonString);
|
||||
|
||||
if (root.containsKey("name"))
|
||||
deviceType = (root["name"]).asString();
|
||||
|
||||
for(int i = 0; i < ENDPOINTS_COUNT; i++) {
|
||||
struct endpoint_def* endpoint = __start_endpoints[i];
|
||||
Serial.printf(" -> %08x\r\n", endpoint);
|
||||
Serial.printf(" -> name: %s\r\n", endpoint->name);
|
||||
JsonObject& data = root["endpoints"].asObject();
|
||||
for (auto it: data) {
|
||||
bool found = false;
|
||||
|
||||
for(auto init: initializers) {
|
||||
Endpoint* ep = init(it.value);
|
||||
if (ep != NULL) {
|
||||
Serial.printf("%s: got object\n", it.key);
|
||||
registerEndpoint(it.key, ep);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
Serial.printf("%s: nothing found\n", it.key);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Serial.println("No configuration");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void SpejsNode::keepAliveHandler() {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <SmingCore/SmingCore.h>
|
||||
#include <Endpoint.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#define D0 16
|
||||
#define D1 5
|
||||
#define D2 4
|
||||
|
@ -95,7 +97,7 @@ public:
|
|||
|
||||
String DEV_TOPIC(String t);
|
||||
|
||||
void loadJSON();
|
||||
void loadJSON(std::vector<EndpointInitializer>);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,6 +17,14 @@ public:
|
|||
}
|
||||
|
||||
EndpointResult onValue(String property, String value);
|
||||
|
||||
static Endpoint* fromJSON(JsonObject& obj) {
|
||||
if (String(obj["type"].asString()) == "output" && obj.containsKey("gpio")) {
|
||||
return new OutputEndpoint(obj["gpio"], obj["inverted"]);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* ifndef OUTPUTENDPOINT_H */
|
||||
|
|
Loading…
Reference in New Issue