Convert sketch from 1.3 to 1.4
-
You just have to compare the provided examples between 1.3<->1.4. They have all been converted.
-
-
@BulldogLowell yes, if you declare a message for each child and initialize it once.
You can also create a single message in loop () and change its properties on the fly (don't have my PC near right now, so no code example.... :cry:thanks, I guess I have tunnel vision here.
I have 3 hours on a plane tonight, I'll fiddle with it then and see if I can't get a sketch to even compile!
gw.loadState???
where is all of this explained? Did I miss some document that has all of these?
-
You just have to compare the provided examples between 1.3<->1.4. They have all been converted.
@hek So, all the examples provided on MySensors.org are already configured for the 1.4 Library including the Serial Gateway? It will probably be easier to simply make minor tweaks to the examples to suit my specific configs then.
-
thanks, I guess I have tunnel vision here.
I have 3 hours on a plane tonight, I'll fiddle with it then and see if I can't get a sketch to even compile!
gw.loadState???
where is all of this explained? Did I miss some document that has all of these?
-
@BulldogLowell The 1.4 library is still under development and documentation is only present in the code. If you're unable to read the code then maybe you should delay the switch to 1.4 until released and stable...
@Yveaux Good idea :)
John
-
@BulldogLowell The 1.4 library is still under development and documentation is only present in the code. If you're unable to read the code then maybe you should delay the switch to 1.4 until released and stable...
@Yveaux said:
If you're unable to read the code then maybe you should delay the switch to 1.4 until released and stable...
sort of goes without saying, right?!!
I can read the code, I just have to spend the time deciphering the calls.
I have built some more complex sketches that were using a lot of the richness of the MySensors capability, I am just trying to piece it all together from the bits that are in each (very lean) example.
-
@Yveaux said:
If you're unable to read the code then maybe you should delay the switch to 1.4 until released and stable...
sort of goes without saying, right?!!
I can read the code, I just have to spend the time deciphering the calls.
I have built some more complex sketches that were using a lot of the richness of the MySensors capability, I am just trying to piece it all together from the bits that are in each (very lean) example.
@BulldogLowell said:
@Yveaux said:
sort of goes without saying, right?!!
Not necessarily... Some people just want it because it's new and probably better.
Then they get frustrated when they run into problems.I'm not saying you're one of them and I also don't mean you cannot read code, I just want to stress that it might be better to wait unless you are prepared to run into troubles ;-)
-
@BulldogLowell said:
@Yveaux said:
sort of goes without saying, right?!!
Not necessarily... Some people just want it because it's new and probably better.
Then they get frustrated when they run into problems.I'm not saying you're one of them and I also don't mean you cannot read code, I just want to stress that it might be better to wait unless you are prepared to run into troubles ;-)
yeah, perhaps I'll go back to creating new stuff and wait for the dust to settle on the API.
I may sneak n a bit of time on this, though. I cannot stand not knowing! :)
thanks!!
-
yeah, perhaps I'll go back to creating new stuff and wait for the dust to settle on the API.
I may sneak n a bit of time on this, though. I cannot stand not knowing! :)
thanks!!
@BulldogLowell Just some stuff for in the plane tonight, should you decide to dive into 1.4 a little deeper.
It shows how to create and send messages with the 1.4 library.The example below shows 3 possible scenarios, each with their own pros & cons. Combinations are also possible.
It will depend on the application and your preference which one to choose.I prefer option 1.
#include <MySensor.h> #define NODE_ID (64) #define CHILD_ID_TEMP (0) #define CHILD_ID_HUMIDITY (1) #define CHILD_ID_LIGHT (2) MySensor gw; void setup() { gw.begin( NULL, NODE_ID, false /*relay*/ ); gw.sendSketchInfo("My 1.4 Sensor", "1.0"); gw.present(CHILD_ID_TEMP, S_TEMP); gw.present(CHILD_ID_HUMIDITY, S_HUM); gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { // ... fetch data from sensors ... double humi = SHT2x.GetHumidity(); double temp = SHT2x.GetTemperature(); int lightLevel = analogRead(LDR_PIN)/10.23; // Option 1 -- compact, message on stack: // Create a new MyMessage instance for every message to send, // and set the value by chaining (using the reference to the // MyMessage instance returned by the constructor) gw.send( MyMessage(CHILD_ID_TEMP, V_TEMP).set(temp, 1) ); gw.send( MyMessage(CHILD_ID_HUMIDITY, V_HUM).set(humi, 1) ); gw.send( MyMessage(CHILD_ID_LIGHT, V_LIGHT_LEVEL).set(lightLevel) ); // Option 2 -- longer, message in RAM: // Create the MyMessage instance once, and re-use it for every sensor static MyMessage msg; msg.setSensor(CHILD_ID_TEMP); msg.setType(V_TEMP); msg.set(temp, 1); gw.send(msg); msg.setSensor(CHILD_ID_HUMIDITY); msg.setType(V_HUM); msg.set(humi, 1); gw.send(msg); // etc. // Option 3 -- static msg for each sensor. More RAM, less CPU: // Create a MyMessage instance for each sensor once. static MyMessage msgTemp; static MyMessage msgHum; static MyMessage msgLight; static bool initDone = false; if (!initDone) // Better to do the init once in setup(), it is only here for clarity. { msgTemp.setSensor(CHILD_ID_TEMP); msgTemp.setType(V_TEMP); msgTemp.setSensor(CHILD_ID_HUMIDITY); msgTemp.setType(V_HUM); msgTemp.setSensor(CHILD_ID_LIGHT); msgTemp.setType(V_LIGHT_LEVEL); initDone = true; } msgTemp.set(temp, 1); gw.send(msgTemp); msgHum.set(humi, 1); gw.send(msgHum); msgLight.set(light); gw.send(msgLight); // ... e.g. sleep the CPU & radio } -
@BulldogLowell Just some stuff for in the plane tonight, should you decide to dive into 1.4 a little deeper.
It shows how to create and send messages with the 1.4 library.The example below shows 3 possible scenarios, each with their own pros & cons. Combinations are also possible.
It will depend on the application and your preference which one to choose.I prefer option 1.
#include <MySensor.h> #define NODE_ID (64) #define CHILD_ID_TEMP (0) #define CHILD_ID_HUMIDITY (1) #define CHILD_ID_LIGHT (2) MySensor gw; void setup() { gw.begin( NULL, NODE_ID, false /*relay*/ ); gw.sendSketchInfo("My 1.4 Sensor", "1.0"); gw.present(CHILD_ID_TEMP, S_TEMP); gw.present(CHILD_ID_HUMIDITY, S_HUM); gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { // ... fetch data from sensors ... double humi = SHT2x.GetHumidity(); double temp = SHT2x.GetTemperature(); int lightLevel = analogRead(LDR_PIN)/10.23; // Option 1 -- compact, message on stack: // Create a new MyMessage instance for every message to send, // and set the value by chaining (using the reference to the // MyMessage instance returned by the constructor) gw.send( MyMessage(CHILD_ID_TEMP, V_TEMP).set(temp, 1) ); gw.send( MyMessage(CHILD_ID_HUMIDITY, V_HUM).set(humi, 1) ); gw.send( MyMessage(CHILD_ID_LIGHT, V_LIGHT_LEVEL).set(lightLevel) ); // Option 2 -- longer, message in RAM: // Create the MyMessage instance once, and re-use it for every sensor static MyMessage msg; msg.setSensor(CHILD_ID_TEMP); msg.setType(V_TEMP); msg.set(temp, 1); gw.send(msg); msg.setSensor(CHILD_ID_HUMIDITY); msg.setType(V_HUM); msg.set(humi, 1); gw.send(msg); // etc. // Option 3 -- static msg for each sensor. More RAM, less CPU: // Create a MyMessage instance for each sensor once. static MyMessage msgTemp; static MyMessage msgHum; static MyMessage msgLight; static bool initDone = false; if (!initDone) // Better to do the init once in setup(), it is only here for clarity. { msgTemp.setSensor(CHILD_ID_TEMP); msgTemp.setType(V_TEMP); msgTemp.setSensor(CHILD_ID_HUMIDITY); msgTemp.setType(V_HUM); msgTemp.setSensor(CHILD_ID_LIGHT); msgTemp.setType(V_LIGHT_LEVEL); initDone = true; } msgTemp.set(temp, 1); gw.send(msgTemp); msgHum.set(humi, 1); gw.send(msgHum); msgLight.set(light); gw.send(msgLight); // ... e.g. sleep the CPU & radio }WOW! thanks!
I appreciate that and will look it over. Hopefully I'll have something to share with you tomorrow (or a problem that I need help).
thanks again.
Jim