Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Convert sketch from 1.3 to 1.4

Convert sketch from 1.3 to 1.4

Scheduled Pinned Locked Moved Development
14 Posts 5 Posters 7.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A a-lurker

    @C4Vette

    "Are there any guidelines on how to convert a sketch that was made for the 1.3 libraries to 1.4?
    I would very much like to use the DimmableLED sketch but I know too little about coding. I found a few obvious differences but nevertheless did not succeed in making the sketch work.

    I found it here: http://forum.micasaverde.com/index.php/topic,23342.0.html and I know the maker blacey is also on this forum and think it is a very nice sketch. The only way I see how to get this to work is to downgrade to the 1.3 libraries but than I would have to start all over."

    <>
    It's not easy to cover all possibilities but here are a few notes and examples based on a temperature sensor plus some other info that might help with the DimmableSketch. I can re-edit this post if there are any corrections needed or something else needs to be added.

    AT THE START OF THE PROGRAM:

    #include <Sensor.h>  change to  #include <MySensor.h>
    #include <EEPROM.h>  <-- this line is no longer required  - delete
    #include <RF24.h>    <-- this line is no longer required  - delete
    Sensor gw;           change to -->  MySensor gw;
    Sensor gw(9,10);     change to -->  MySensor gw;
    
    // Initialize temperature message   <-- insert line
    MyMessage msg(0,V_TEMP);            <-- insert line
    

    IN void setup():

    // send the Sketch Version Information to the Gateway   <-- insert line
    gw.sendSketchInfo("My sketch name", "0.50");            <-- insert line
    
    gw.sendSensorPresentation(i, S_TEMP);  change to -->  gw.present(i, S_TEMP);
    
    metric = gw.isMetricSystem();  change to -->  metric = gw.getConfig().isMetric;
    

    IN void loop():

    // process incoming messages (like config from server)   <-- insert line
    gw.process();                                        <-- insert line
    
    gw.sendVariable(i, V_TEMP, temperature, 1);  change to -->  gw.send(msg.setSensor(i).set(temperature,1));  // send float with one decimal point
    

    SEARCH FOR THE FOLLOWING:

    gw.powerUp();   <-- this line is no longer required - delete if found
    
    sendSensorPresentation   change variable name to --> present
    

    If the following is found then this can be deleted:

    // Set RADIO_ID to something unique in your sensor network (1-254)
    // or set to AUTO if you want gw to assign a RADIO_ID for you.
    #define RADIO_ID AUTO
    
    If the #define RADIO_ID AUTO was found and deleted as above then change this also
    gw.begin( RADIO_ID ); change to --> gw.begin();
    

    OTHER EXAMPLE MESSAGES:

    // batteryPcnt is a uint8_t
    gw.sendBatteryLevel(batteryPcnt);
    
    // I've not checked this
    gw.sendVariable( 0, V_DIMMER, currentLevel ); change to --> gw.send(currentLevel);
    

    INITIALIZING THE SENSOR TO HANDLE A MESSAGE FROM THE MAIN GATEWAY:

    // handle incoming messages
    void incomingMessage(MyMessage message)
    {
       // handle your messages here
       // I've not checked this
       setDimmableLEDState(message);
    }
    
    // the call back incomingMessage receives any incoming messages
    gw.begin(incomingMessage);
    
    BulldogLowellB Offline
    BulldogLowellB Offline
    BulldogLowell
    Contest Winner
    wrote on last edited by
    #2

    @a-lurker

    I looked this over, thanks. This, and @hek's update on the new version are falling a bit short for me to convert some of my sketches.

    I guess I really need to see some better examples of converted code, before and after.

    I must be missing something, to me it should be more intuitive what to do here.

    hekH 1 Reply Last reply
    0
    • BulldogLowellB BulldogLowell

      @a-lurker

      I looked this over, thanks. This, and @hek's update on the new version are falling a bit short for me to convert some of my sketches.

      I guess I really need to see some better examples of converted code, before and after.

      I must be missing something, to me it should be more intuitive what to do here.

      hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #3

      @BulldogLowell

      You just have to compare the provided examples between 1.3<->1.4. They have all been converted.

      BulldogLowellB clippermiamiC 2 Replies Last reply
      0
      • hekH hek

        @BulldogLowell

        You just have to compare the provided examples between 1.3<->1.4. They have all been converted.

        BulldogLowellB Offline
        BulldogLowellB Offline
        BulldogLowell
        Contest Winner
        wrote on last edited by
        #4

        @hek

        MyMessage msg(0,V_TEMP); 
        

        Is this needed for every child device??

        YveauxY 1 Reply Last reply
        0
        • BulldogLowellB BulldogLowell

          @hek

          MyMessage msg(0,V_TEMP); 
          

          Is this needed for every child device??

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #5

          @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:

          http://yveaux.blogspot.nl

          BulldogLowellB 1 Reply Last reply
          0
          • YveauxY Yveaux

            @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:

            BulldogLowellB Offline
            BulldogLowellB Offline
            BulldogLowell
            Contest Winner
            wrote on last edited by
            #6

            @Yveaux

            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?

            YveauxY 1 Reply Last reply
            0
            • hekH hek

              @BulldogLowell

              You just have to compare the provided examples between 1.3<->1.4. They have all been converted.

              clippermiamiC Offline
              clippermiamiC Offline
              clippermiami
              Hero Member
              wrote on last edited by
              #7

              @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.

              1 Reply Last reply
              0
              • BulldogLowellB BulldogLowell

                @Yveaux

                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?

                YveauxY Offline
                YveauxY Offline
                Yveaux
                Mod
                wrote on last edited by
                #8

                @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...

                http://yveaux.blogspot.nl

                clippermiamiC BulldogLowellB 2 Replies Last reply
                0
                • YveauxY Yveaux

                  @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...

                  clippermiamiC Offline
                  clippermiamiC Offline
                  clippermiami
                  Hero Member
                  wrote on last edited by
                  #9

                  @Yveaux Good idea :)

                  John

                  1 Reply Last reply
                  0
                  • YveauxY Yveaux

                    @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...

                    BulldogLowellB Offline
                    BulldogLowellB Offline
                    BulldogLowell
                    Contest Winner
                    wrote on last edited by
                    #10

                    @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.

                    YveauxY 1 Reply Last reply
                    0
                    • BulldogLowellB BulldogLowell

                      @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.

                      YveauxY Offline
                      YveauxY Offline
                      Yveaux
                      Mod
                      wrote on last edited by
                      #11

                      @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 ;-)

                      http://yveaux.blogspot.nl

                      BulldogLowellB 1 Reply Last reply
                      0
                      • YveauxY Yveaux

                        @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 ;-)

                        BulldogLowellB Offline
                        BulldogLowellB Offline
                        BulldogLowell
                        Contest Winner
                        wrote on last edited by
                        #12

                        @Yveaux

                        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!!

                        YveauxY 1 Reply Last reply
                        0
                        • BulldogLowellB BulldogLowell

                          @Yveaux

                          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!!

                          YveauxY Offline
                          YveauxY Offline
                          Yveaux
                          Mod
                          wrote on last edited by Yveaux
                          #13

                          @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
                          }
                          

                          http://yveaux.blogspot.nl

                          BulldogLowellB 1 Reply Last reply
                          1
                          • YveauxY Yveaux

                            @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
                            }
                            
                            BulldogLowellB Offline
                            BulldogLowellB Offline
                            BulldogLowell
                            Contest Winner
                            wrote on last edited by
                            #14

                            @Yveaux

                            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

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            14

                            Online

                            11.7k

                            Users

                            11.2k

                            Topics

                            113.0k

                            Posts


                            Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • MySensors
                            • OpenHardware.io
                            • Categories
                            • Recent
                            • Tags
                            • Popular