Hek,
I have completed a first pass at implementing the sketch version reporting feature and am posting it here for some early feedback because I am open to adjusting it to meet your standards or wishes. Below is a summary of the changes and an attachment that shows the new UI:
[ul][li]I ended up adding both a Sketch Name and a Sketch Version internal-message variables because my initial tests only allowed me to transfer 13 characters (interestingly enough, tonight, I was able to transfer the expected 25 characters [32 - 7-byte message protocol header] after syncing my forked repo with your upstream master branch). Anyway, separating them may be bit a more future-proof in case some-day, you want to be able to alert users to sensors that are out-of-date with respect to some public version database on MySensors.org. Also, given the limited UI space, breaking the name and version a part, seemed a bit easier for limited layout[/li]
[li]There are 3 new sensor methods - sendSketchName(const char *name), sendSketchVersion(const char *version) and sendSketchInfo(const char *name, const char *version). sendSketchInfo() is a convenience method that simply calls the other two methods and is what should normally be called by the users in the setup method.[/li]
[li]I’m not sure about the UI - see below. We can either go with as is (but I need your help to avoid the ellipses “…” on the SketchVersion - I’m missing something simple) or I can change the layout back to your original layout but try to place a concatenated sketch name and version in the lower-right corner of the Arduino Node… One can also envision using the Sketch Name for the Node…[/li][/ul]
Sensor.h changes
/**
* Sends sketch info to sensor net gateway for this radio node.
* A sensor node sketch should normally call this method during setup() anytime after calling begin()
* @param name String containing a short Sketch name
* @param version String containing a short Sketch version
*/
void sendSketchInfo(const char *name, const char *version);
/**
* Sends sketch name to sensor net gateway for this radio node.
* @param info String containing a short Sketch name and version
*/
void sendSketchName(const char *name);
/**
* Sends sketch version to sensor net gateway for this radio node.
* @param info String containing a short Sketch name and version
*/
void sendSketchVersion(const char *version);
Sensor.cpp changes
void Sensor::sendSketchInfo(const char *name, const char *version) {
sendSketchName(name);
sendSketchVersion(version);
}
void Sensor::sendSketchName(const char *name) {
if (name != NULL)
sendInternal(I_SKETCH_NAME, name);
}
void Sensor::sendSketchVersion(const char *version) {
if (version != NULL)
sendInternal(I_SKETCH_VERSION, version);
}
Alternatives to consider. Thinking about this from a sensor user/developer “keep it simple stupid” stand-point, it might be better to implement the name and version as Sensor class properties that can be used by the Begin() method to send the name and version to the gateway akin to what it does for the node presentation; and either change the sendSketchInfo() to setSketchInfo() or add the name and version as arguments to the Sensor constructor so the instance variables are guaranteed to be set before Begin() is called. Another, somewhat less desirable from best-practices stand-point, but effective option would be to set them as #defines or global static constants at the top of the file… So for example, currently, a sensor sketch can do the following in setup after Begin():
setup() {
...
gw.begin(...)
...
gw.sendSensorInfo("DimmableLED", "1.0");
....
}
but this entails the user explicitly adding code to report the sensor node sketch and version when maybe it should be more declarative and the Sensor class should take care of the rest when it sends the node presentation to the gateway. For example, in the header of the file, the user could set the following globals to be used by Sensor::Begin(); yes, these could be #defines.
const char *sensorName = “DimmableLED”
const char *sensorVersion = “1.0”
This boils down to the following 3 design decisions:
[ol][li]Single I_SKECTH_VERSION internal variables or 2 - I_SKETCH_NAME and I_SKETCH_VERSION[/li]
[li]Usage pattern - declare as constants in file header that are used by Sensor::begin() to send to gateway or gw.sendSensorInfo in the setup() method.[/li]
[li]UI as is with some cleanup or change dashboard view or change in some other way (e.g. revert to original layout but place “Name Version” in lower-right corner)
[/li][/ol]
I look forward to your thoughts so I can take another pass and submit a pull request.
Once this is a bit closer, I will commit to my fork repo and send you a pull request so you can do a formal code review.
Best,
Bruce