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();
|
virtual void onConnected();
|
||||||
|
|
||||||
|
static Endpoint* fromJSON(JsonObject& obj) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T> class ValueEndpoint : public Endpoint {
|
template <class T> class ValueEndpoint : public Endpoint {
|
||||||
|
@ -45,27 +49,6 @@ public:
|
||||||
ValueEndpoint(String _type) : Endpoint(_type) {}
|
ValueEndpoint(String _type) : Endpoint(_type) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct endpoint_def {
|
typedef Endpoint* (*EndpointInitializer) (JsonObject&);
|
||||||
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))
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include <endpoints/ImplementationEndpoint.h>
|
#include <endpoints/ImplementationEndpoint.h>
|
||||||
|
|
||||||
|
#define CONFIG_FILE "config.json"
|
||||||
|
|
||||||
void SpejsNode::init() {
|
void SpejsNode::init() {
|
||||||
deviceID = WifiStation.getMAC().substring(6, 12);
|
deviceID = WifiStation.getMAC().substring(6, 12);
|
||||||
|
|
||||||
|
@ -29,26 +31,51 @@ void SpejsNode::init() {
|
||||||
// Keepalive Timer initialization
|
// Keepalive Timer initialization
|
||||||
keepaliveTimer.initializeMs(10000, TimerDelegate(&SpejsNode::keepAliveHandler, this)).start();
|
keepaliveTimer.initializeMs(10000, TimerDelegate(&SpejsNode::keepAliveHandler, this)).start();
|
||||||
|
|
||||||
loadJSON();
|
|
||||||
|
|
||||||
statusLED.high();
|
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() {
|
DynamicJsonBuffer jsonBuffer;
|
||||||
/*
|
if (fileExist(CONFIG_FILE)) {
|
||||||
Serial.printf("start: %08x\n", __start_endpoints);
|
Serial.println("Found config file");
|
||||||
Serial.printf("stop: %08x\n", __stop_endpoints);
|
int size = fileGetSize(CONFIG_FILE);
|
||||||
Serial.printf("Endpoints count: %d\n", ENDPOINTS_COUNT);
|
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++) {
|
JsonObject& data = root["endpoints"].asObject();
|
||||||
struct endpoint_def* endpoint = __start_endpoints[i];
|
for (auto it: data) {
|
||||||
Serial.printf(" -> %08x\r\n", endpoint);
|
bool found = false;
|
||||||
Serial.printf(" -> name: %s\r\n", endpoint->name);
|
|
||||||
|
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() {
|
void SpejsNode::keepAliveHandler() {
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <SmingCore/SmingCore.h>
|
#include <SmingCore/SmingCore.h>
|
||||||
#include <Endpoint.h>
|
#include <Endpoint.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#define D0 16
|
#define D0 16
|
||||||
#define D1 5
|
#define D1 5
|
||||||
#define D2 4
|
#define D2 4
|
||||||
|
@ -95,7 +97,7 @@ public:
|
||||||
|
|
||||||
String DEV_TOPIC(String t);
|
String DEV_TOPIC(String t);
|
||||||
|
|
||||||
void loadJSON();
|
void loadJSON(std::vector<EndpointInitializer>);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,6 +17,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
EndpointResult onValue(String property, String value);
|
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 */
|
#endif /* ifndef OUTPUTENDPOINT_H */
|
||||||
|
|
Loading…
Reference in New Issue