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. Troubleshooting
  3. a little programming help please.

a little programming help please.

Scheduled Pinned Locked Moved Troubleshooting
13 Posts 3 Posters 3.8k Views 1 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.
  • M mvader

    thanks for looking at this for me.
    I gave your suggestion a try, i'm still having issues

    char* outlet[]={"0","1111111","2222222","3333333"};
    where S = to one of the elements in the array
    Serial.println(outlet[(S)]); <-- this works
    mySwitch.send(outlet[(S)], 24); <-- this errors

    error: invalid conversion from 'char*' to 'long unsigned int' [-fpermissive]

    why does it print, but not put that same value in the next command?
    I want it to work like this
    myswitch.send (VALUE of the element in the arra,24);
    how do i get that value in there?

    AWIA Offline
    AWIA Offline
    AWI
    Hero Member
    wrote on last edited by
    #4

    @mvader

    You are using a "setter" for a float value (or pointer) see API

    // Setters for payload
    MyMessage& set(void* payload, uint8_t length);
    MyMessage& set(const char* value);
    MyMessage& set(uint8_t value);
    MyMessage& set(float value, uint8_t decimals);
    MyMessage& set(unsigned long value);
    MyMessage& set(long value);
    MyMessage& set(unsigned int value);
    MyMessage& set(int value);
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mvader
      wrote on last edited by
      #5

      so the value of S is a number it's the sensor ID # that my vera has assigned to my outlets
      when i click "ON" in vera, it will send (if say outlet 3) S will then equal 3
      i then want to send out the code that is assigned to outlet 3
      i was using an array to store them, but i would be fine defining outlet1= outlet2= etc
      either way when i get to the function as the bottom
      i want the code to show outlet(S) S being the outlet, but outlet(S) should = 1111641 and that is what code i want sent out
      i can't seem to figure out how to make that happen
      in a shell script i can just do outlet$S and then that = outlet3 (the value of)
      can you do that in arduino/C ?

      #include <MySensor.h>
      #include <SPI.h>  
      #include <RCSwitch.h>
      
      #define RF433_CHILD_ID 0
      #define NUMBER_OF_OUTLETS 4 
      #define char* outlet[]={"0","1119683","1111641","1114582"};   
      
      MySensor gw;
      RCSwitch mySwitch = RCSwitch();
      
      void setup() 
      {
      mySwitch.enableTransmit(2); 
      Serial.begin(115200); 
      gw.begin(incomingMessage, AUTO, true);
      gw.sendSketchInfo("RF433C", "1.0");
      
      for(int i=0; i<NUMBER_OF_OUTLETS;i++)
      {
      gw.present(i+1, S_LIGHT);
      }
      
      }
      
      void loop()
      {
        gw.process();
      }
      
      void incomingMessage(const MyMessage &message)
      {
        if (message.type==V_LIGHT) {
        int incomingLightState =  message.getBool(); 
        int S = message.sensor;
      
       if (incomingLightState==1)
       {
       Serial.println(outlet[(S)]);
       mySwitch.send(outlet[(S)], 24);
       } 
        }
      }
      
      
      1 Reply Last reply
      0
      • M mvader

        thanks for looking at this for me.
        I gave your suggestion a try, i'm still having issues

        char* outlet[]={"0","1111111","2222222","3333333"};
        where S = to one of the elements in the array
        Serial.println(outlet[(S)]); <-- this works
        mySwitch.send(outlet[(S)], 24); <-- this errors

        error: invalid conversion from 'char*' to 'long unsigned int' [-fpermissive]

        why does it print, but not put that same value in the next command?
        I want it to work like this
        myswitch.send (VALUE of the element in the arra,24);
        how do i get that value in there?

        sowardS Offline
        sowardS Offline
        soward
        wrote on last edited by
        #6

        Maybe you could post your entire sketch here?

        M 1 Reply Last reply
        0
        • sowardS soward

          Maybe you could post your entire sketch here?

          M Offline
          M Offline
          mvader
          wrote on last edited by
          #7

          @soward said:

          Maybe you could post your entire sketch here?

          that is my entire sketch (above your post) lol
          i have not been able to get any further

          AWIA 1 Reply Last reply
          0
          • M mvader

            @soward said:

            Maybe you could post your entire sketch here?

            that is my entire sketch (above your post) lol
            i have not been able to get any further

            AWIA Offline
            AWIA Offline
            AWI
            Hero Member
            wrote on last edited by
            #8

            @mvader
            I don't know what you are trying to accomplish but RCSwtich.send expects either a character array (= implicit pointer) or an "unsigned long" Code with a length value. I does not have anything to do with MySensors. It is probably easier for you to browse through the RCSwitch examples before combining it with the MySensors API (which has similar characteristics..

            Below the RCSwitch definitions.

            void send(unsigned long Code, unsigned int length);
            void send(char* Code);
            
            1 Reply Last reply
            0
            • M Offline
              M Offline
              mvader
              wrote on last edited by mvader
              #9

              @AWI
              i'm confused why you say it doesn't have anything to do with mysensors.
              i have a working sketch that controls 433 outlets on my - mysensors network
              the issue i have is i'm trying to shorten the sketch.
              the way it is written now, it defines an on and off code for each outlet
              if you have many outlets that's allot of "IF" statements.
              in the shell script world i could easily shorten that by using a variable and for loop.
              as admitted i'm a scripter and know little about c/arduino programming
              here is a modified working sketch

              /*  RF433Mhz Transmitter node:
                  This sketch allows On-Off-Keying (OOK) control of four 433Mhz relay outlets
                  which utilize the common PT2262 encoding chip for signal transmission. The sketch could
                  be easily expanded to include additional outlets.  The sensor node consists of a nano 
                  connected to a NRF24L01 and a 433Mhz transmitter connected to pin 3, 5V and Gnd.  The 
                  transmitter can run off of 3.3V as well. 
                  
                  The sketch is based on the MySensors project (http://www.mysensors.org). 
                  Submitted by Dwalt.
              */ 
              
              //  Include related libraries
              #include <MySensor.h>
              #include <SPI.h>  
              #include <RCSwitch.h>
              
              //  Define Constants
              #define RF433_CHILD_ID 0
              #define NUMBER_OF_OUTLETS 4 // Each outlet will have 2 OOK codes
              //#define SEND_DATA 2
              
              #define CODE_1On 1119683
              #define CODE_1Off 1119692
              #define CODE_2On 6287580
              #define CODE_2Off 6287572
              #define CODE_3On 6287578
              #define CODE_3Off 6287570
              #define CODE_4On 6287577
              #define CODE_4Off 6287569
              
              MySensor gw;
              
              RCSwitch mySwitch = RCSwitch();
              
              void setup() 
              {
                
              
              mySwitch.enableTransmit(2); 
                
               Serial.begin(115200); // Not sure why this was included
              
               //  The node is mains powered, so why not make it a repeater.
               gw.begin(incomingMessage, AUTO, true);
               
               // Send the sketch version information to gateway
               gw.sendSketchInfo("RF433", "1.1");
               
               // Register outlets to gw (they will be created as child devices)
               for(int i=0; i<NUMBER_OF_OUTLETS;i++) {
                 gw.present(i+1, S_LIGHT);
              
               }
                  
              }
              
              void loop() {
                gw.process();
              }
                void incomingMessage(const MyMessage &message) {
                
                if (message.type==V_LIGHT) {
                int incomingLightState =  message.getBool(); 
                int incomingOutlet = message.sensor;
                
                Serial.print("Outlet #: ");
                Serial.println(message.sensor);
                Serial.print("Command: ");
                Serial.println(message.getBool());
               
               if (incomingOutlet==1) {
               if (incomingLightState==1) {
                  // Turn on  socket 1
                  Serial.println("Turn on Socket 1");
               mySwitch.send(CODE_1On, 24); // These codes are unique to each outlet
               delay(50); 
               }
               if (incomingLightState==0)  {
                  // Turn off socket 1
               Serial.println("Turn off Socket 1");
              mySwitch.send(CODE_1Off, 24);
              delay(50); 
               }
               }
               if (incomingOutlet==2) {
               if (incomingLightState==1) {
                  // Turn on  socket 2
                  Serial.println("Turn on Socket 2");
              mySwitch.send(CODE_2On, 24);
               delay(50); 
               }
               if (incomingLightState==0)  {
                  // Turn off socket 2
               Serial.println("Turn off Socket 2");
              mySwitch.send(CODE_2Off, 24);
              delay(50); 
               }
               }
               if (incomingOutlet==3) {
               if (incomingLightState==1) {
                  // Turn on  socket 3
                  Serial.println("Turn on Socket 3");
              mySwitch.send(CODE_3On, 24);
               delay(50); 
               }
               if (incomingLightState==0)  {
                  // Turn off socket 3
               Serial.println("Turn off Socket 3");
              mySwitch.send(CODE_3Off, 24);
              delay(50); 
               }
               }
               if (incomingOutlet==4) {
               if (incomingLightState==1) {
                  // Turn on  socket 4
                  Serial.println("Turn on Socket 4");
               mySwitch.send(CODE_4On, 24);
               delay(50); 
               }
               if (incomingLightState==0)  {
                  // Turn off socket 4
               Serial.println("Turn off Socket 4");
              mySwitch.send(CODE_4Off, 24);
              delay(50); 
               }
               }
                }
               delay(50);
               }    
                  
              
              AWIA 1 Reply Last reply
              0
              • M mvader

                @AWI
                i'm confused why you say it doesn't have anything to do with mysensors.
                i have a working sketch that controls 433 outlets on my - mysensors network
                the issue i have is i'm trying to shorten the sketch.
                the way it is written now, it defines an on and off code for each outlet
                if you have many outlets that's allot of "IF" statements.
                in the shell script world i could easily shorten that by using a variable and for loop.
                as admitted i'm a scripter and know little about c/arduino programming
                here is a modified working sketch

                /*  RF433Mhz Transmitter node:
                    This sketch allows On-Off-Keying (OOK) control of four 433Mhz relay outlets
                    which utilize the common PT2262 encoding chip for signal transmission. The sketch could
                    be easily expanded to include additional outlets.  The sensor node consists of a nano 
                    connected to a NRF24L01 and a 433Mhz transmitter connected to pin 3, 5V and Gnd.  The 
                    transmitter can run off of 3.3V as well. 
                    
                    The sketch is based on the MySensors project (http://www.mysensors.org). 
                    Submitted by Dwalt.
                */ 
                
                //  Include related libraries
                #include <MySensor.h>
                #include <SPI.h>  
                #include <RCSwitch.h>
                
                //  Define Constants
                #define RF433_CHILD_ID 0
                #define NUMBER_OF_OUTLETS 4 // Each outlet will have 2 OOK codes
                //#define SEND_DATA 2
                
                #define CODE_1On 1119683
                #define CODE_1Off 1119692
                #define CODE_2On 6287580
                #define CODE_2Off 6287572
                #define CODE_3On 6287578
                #define CODE_3Off 6287570
                #define CODE_4On 6287577
                #define CODE_4Off 6287569
                
                MySensor gw;
                
                RCSwitch mySwitch = RCSwitch();
                
                void setup() 
                {
                  
                
                mySwitch.enableTransmit(2); 
                  
                 Serial.begin(115200); // Not sure why this was included
                
                 //  The node is mains powered, so why not make it a repeater.
                 gw.begin(incomingMessage, AUTO, true);
                 
                 // Send the sketch version information to gateway
                 gw.sendSketchInfo("RF433", "1.1");
                 
                 // Register outlets to gw (they will be created as child devices)
                 for(int i=0; i<NUMBER_OF_OUTLETS;i++) {
                   gw.present(i+1, S_LIGHT);
                
                 }
                    
                }
                
                void loop() {
                  gw.process();
                }
                  void incomingMessage(const MyMessage &message) {
                  
                  if (message.type==V_LIGHT) {
                  int incomingLightState =  message.getBool(); 
                  int incomingOutlet = message.sensor;
                  
                  Serial.print("Outlet #: ");
                  Serial.println(message.sensor);
                  Serial.print("Command: ");
                  Serial.println(message.getBool());
                 
                 if (incomingOutlet==1) {
                 if (incomingLightState==1) {
                    // Turn on  socket 1
                    Serial.println("Turn on Socket 1");
                 mySwitch.send(CODE_1On, 24); // These codes are unique to each outlet
                 delay(50); 
                 }
                 if (incomingLightState==0)  {
                    // Turn off socket 1
                 Serial.println("Turn off Socket 1");
                mySwitch.send(CODE_1Off, 24);
                delay(50); 
                 }
                 }
                 if (incomingOutlet==2) {
                 if (incomingLightState==1) {
                    // Turn on  socket 2
                    Serial.println("Turn on Socket 2");
                mySwitch.send(CODE_2On, 24);
                 delay(50); 
                 }
                 if (incomingLightState==0)  {
                    // Turn off socket 2
                 Serial.println("Turn off Socket 2");
                mySwitch.send(CODE_2Off, 24);
                delay(50); 
                 }
                 }
                 if (incomingOutlet==3) {
                 if (incomingLightState==1) {
                    // Turn on  socket 3
                    Serial.println("Turn on Socket 3");
                mySwitch.send(CODE_3On, 24);
                 delay(50); 
                 }
                 if (incomingLightState==0)  {
                    // Turn off socket 3
                 Serial.println("Turn off Socket 3");
                mySwitch.send(CODE_3Off, 24);
                delay(50); 
                 }
                 }
                 if (incomingOutlet==4) {
                 if (incomingLightState==1) {
                    // Turn on  socket 4
                    Serial.println("Turn on Socket 4");
                 mySwitch.send(CODE_4On, 24);
                 delay(50); 
                 }
                 if (incomingLightState==0)  {
                    // Turn off socket 4
                 Serial.println("Turn off Socket 4");
                mySwitch.send(CODE_4Off, 24);
                delay(50); 
                 }
                 }
                  }
                 delay(50);
                 }    
                    
                
                AWIA Offline
                AWIA Offline
                AWI
                Hero Member
                wrote on last edited by AWI
                #10

                @mvader If you look at the similar statement in this sketch:

                #define CODE_1On 1119683
                (better written as:)
                const int CODE_1On = 1119683   // define integer with value
                mySwitch.send(CODE_1On, 24); // These codes are unique to each outlet
                

                CODE_10n is an Integer "type"

                In the other sketch you are using "outlet[(S)]" which is a char array (or pointer) type.

                #define char* outlet[]={"0","1119683","1111641","1114582"};
                (better written as:)
                const char outlet[] = {"0","1119683","1111641","1114582"};   // define an array with character arrays
                
                 Serial.println(outlet[(S)]);
                 mySwitch.send(outlet[(S)], 24);
                

                While the mySwitch.send( .. ) either wants a character array ("ABCDEF12121") or an integer with length (12234, 24)

                C++ does not automatically convert types...

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mvader
                  wrote on last edited by
                  #11

                  I must still be missing something.
                  appreciate the correction on the declared part.
                  however, i still don't know how to make outlet(S) (where S is the outlet number)
                  work.
                  i constantly get a "outlet" is not defined.. etc
                  outlet is not specifically defined, but i'm not trying to send just "outlet"
                  i'm trying to send the value of outlet3
                  the variable S is supposed to represent the 3 (or whatever other outlet # is sent back by vera)

                  this allows me to use 1 piece of code, instead of saying
                  if outlet 1
                  if outlet 2
                  if outlet 3
                  etc
                  i can just say outlet(S)
                  but that' isn't working. why? not possible or not coded correctly?

                  AWIA 1 Reply Last reply
                  0
                  • M mvader

                    I must still be missing something.
                    appreciate the correction on the declared part.
                    however, i still don't know how to make outlet(S) (where S is the outlet number)
                    work.
                    i constantly get a "outlet" is not defined.. etc
                    outlet is not specifically defined, but i'm not trying to send just "outlet"
                    i'm trying to send the value of outlet3
                    the variable S is supposed to represent the 3 (or whatever other outlet # is sent back by vera)

                    this allows me to use 1 piece of code, instead of saying
                    if outlet 1
                    if outlet 2
                    if outlet 3
                    etc
                    i can just say outlet(S)
                    but that' isn't working. why? not possible or not coded correctly?

                    AWIA Offline
                    AWIA Offline
                    AWI
                    Hero Member
                    wrote on last edited by
                    #12

                    @mvader sorry for confusing you.. try this:

                    const unsigned long outlet[]= {0,1119683,1111641,1114582};   
                    

                    i.s.o.

                    #define char* outlet[]={"0","1119683","1111641","1114582"}; 
                    
                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mvader
                      wrote on last edited by
                      #13

                      I think that may have done the trick.. i'll follow up in a bit
                      thanks!

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


                      19

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.1k

                      Posts


                      Copyright 2025 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