-
Notifications
You must be signed in to change notification settings - Fork 634
Description
Description
Hi. Several modifications that I am proposing allow creating new sensors in runtime; now, code associated with reports (thinkspeak for example), associates the reported values to the magnitude index. This index depends on the number of sensors (and slots) in the system and changes from execution to execution if the number of sensors changes.
My idea is to be able to associate each instance of a sensor with a unique static identifier (which is maintained from execution to execution), and which, together with the slot being reported, can be univocally used by the code that makes the reports.
This would allow adding or removing sensors, without modifying the configuration of the reporter.
In the specific case of thinkspeak, I think it could be done modifying
espurna/code/espurna/thingspeak.cpp
Line 107 in 1366713
| size_t magnitude(size_t index) { |
#if SENSOR_SUPPORT
size_t magnitude(size_t index) {
return getSetting({FPSTR(keys::Magnitude), index}, build::Unset);
}
#endif
to something like this
#if SENSOR_SUPPORT
size_t magnitude(size_t index) {
auto& magnitude = magnitude::get(index);
int instanceSensorId = magnitude.sensor->staticInstId();
if (instanceSensorId <=0)
return getSetting({FPSTR(keys::Magnitude), index}, build::Unset);
String prefixWithId = FPSTR(keys::Magnitude) + "_"+ instanceSensorId + "_";
return getSetting({prefixWithId, magnitude.slot}, build::Unset);
}
#endif
In this way, the association of thingspeak fields with sensors that support static ID would be stored in configuration under a key with the form
tspkMagnitude_ID_slot
In this specific case I don't know what other code would have to be modified; I don't know where these keys are written (do I have to modify the code associated with the web?)
Beyond this, I don't know if there is perhaps a more general and elegant solution that I'm not seeing (perhaps associating the static id with the magnitudes instead of the sensors?).
Any suggestions?
Solution
No response
Alternatives
No response
Additional context
No response