-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static sensor identifier for reporter configuration (thinkspeak for example) #2639
Comments
In current code, keys are always static. Either as a plain string, or string plus integer index. Index is generated on demand. Key contents are never parsed or split to parse certain parts separately. I think you are also mixing up the indexing used for and between modules. Thingspeak as-is iterates over available magnitudes, since it is the only index it has available. Would it be appropriate to replace explicit indexing with a separate 'entities' inside of Thingspeak module itself, not basing it on magnitudes count?
Meaning, modules stop tracking indexes and track some kind of addressable magnitude; either as index, or some unique string. Another thing to keep in mind is multiple instances of the same sensor, which would still (at least based on current code) depend on ordering. Some sensors provide addresses (I2C, port-based), so it might help in some cases |
I must have expressed myself wrong; by index I mean the one passed in this line of code espurna/code/espurna/sensor.cpp Line 4325 in 4c3122c
not the indexes of the keys in configuration. That index can clearly change from execution to execution if the number of sensors is modified. Thinkspeak currently maps that index to the respective thinkspeak field (0 when the magnitude is not associated with a field).
I don't know if I understand your idea exactly, but I think that should be the way. |
The above assumes that the number of sensors can change, but the number of slots per sensor cannot; a more general solution I think would be in BaseSensor:
and what thinkspeask would actually store would be PS: "Static Instance Id" is possibly incorrect; "Persistent Instance Id" actually better reflects my idea. |
If you are identifying magnitude, just pass along this unique key when initializing it in the web? Fields displayed on the home page associate via 'index', but could just as well be identified via this unique id.
Right, but why API needs 2 more IDs? Any reason why address can not be used, or some other extra properties identifying the device? Slot is technically unique for the specific sensor, so not really sure what 'staticSlotId' supposed to do here. You also have to keep in mind a possibility of 'setAddress()' for the sensor, where it can be generated by the user. Another approach is to pass identifying string to the sensor directly, i.e.
Where this could do whatever implementation wise. |
re. 'Persistent'... this also reminds me of the udev naming schemes for network devices, which are picked up from other unique properties of the network device. e.g. port, MAC, hw path or explicitly labeled https://www.freedesktop.org/software/systemd/man/latest/systemd.net-naming-scheme.html
following up the source of |
Ok, first of all I don't think this functionality is very important (after all, if you add or remove sensors, it doesn't add much more work to modify the configuration of thinkspeak or another reporter)... But anyway, I'm interested in learning how the web-related code works for others features (configuring AnalogInputs and NTCs sensors in particular).
espurna/code/espurna/thingspeak.cpp Line 721 in 4c3122c
and use a handler for onData(on_send_f), something like that:
I don't know if it would be correct; onData is called when the Save button is pressed? |
Ah, no, the magic happens here (apparently): Line 553 in 4c3122c
I guess there is no way to intercept the webSocket message generated by the save button.....
|
Same file, just a few lines below. Not sure how that helps here, though Lines 646 to 647 in 4c3122c
Only apparent issue is index shift, and leftover keys that possibly do nothing or overwrite old behaviour? Does not matter much for an end device, that is true. But could, in theory, be useful to limit other reading / reporting outputs e.g. MQTT and / or modify output topics to be more unique and identifying the sensor device itself vs. identifying Nth output |
One way I see to add unique IDs per sensor instance is the following:
It is backwards compatible (current sensor code does not require modification).New sensors, if they wish, can redefine createSubIdForSensorClass() to achieve truly persistent IDs. |
Regarding how to use this in reporters like Thinkspeak, I think the website should use a new module: it currently uses "magnitudes-module." I think that module should be, say "field-to-sns-slot-module," which generates configuration keys in the form For example, for Thinkspeak, it would generate (websocket message) something like
|
For example, in the case of Thinkspeak Thinkspeak.cpp
Well, the code to update the tspkField keys is missing, but as is it should be possible to use it by setting these keys manually from the console. As soon as I have some free time I will test it. |
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
to something like this
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
The text was updated successfully, but these errors were encountered: