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. sending string via nrf and the other receivers making trouble - why?

sending string via nrf and the other receivers making trouble - why?

Scheduled Pinned Locked Moved Development
8 Posts 3 Posters 2.8k Views 2 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.
  • choffmannC Offline
    choffmannC Offline
    choffmann
    wrote on last edited by
    #1

    Hello,
    ich have configured an arduino nano via nrf24L01+ and a LED-Stripe. My Idea is to send a LEDNumber and a HEX-Code for the color to set the LED to Color xy...

    I use FHEM and a own Perl-Method to convert the HEX Code to an Splittable string. This i send via Network-GW to my arduino as String.
    At this moment where the code is sending other receivers like Temp-Sensors sending 12502°C as Temperatur...

    I dont find the problem.
    Can somebody help?

    The sendet code via FHEM is:
    set <NAME> status7 0-0-255

    #include <MySensor.h>
    #include <SPI.h>
    #include <EEPROM.h>
    #include <MyTransportNRF24.h>
    #include <MyHwATMega328.h>
    #include <RemoteReceiver.h>
    #include <RemoteTransmitter.h>
    #include <InterruptChain.h>
    
    #include "FastLED.h"
    #define DATA_PIN 3
    #define CLOCK_PIN 13
    #define NUM_LEDS 19
    CRGB leds[NUM_LEDS];
    
    
    #define NUMBER_OF_OUTLETS 99
    #define SN "LEDRahmenEG"
    #define SV "1.6"
    
    const byte SC_CHILD_ID = 0 ;
    //unsigned long receivedCode = 0 ;
    
    
    MySensor gw;
    MyMessage scene_on(SC_CHILD_ID, V_LEVEL);
    MyMessage scene_off(SC_CHILD_ID, V_LEVEL);
    
    void setup() {
      Serial.begin(115200);
      gw.begin(incomingMessage);
      gw.sendSketchInfo(SN, SV);
      FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
    
      //TEST
      //leds[9].g=1;
      //leds[9].b=255;
      //leds[10].r=255;
      //leds[11].b=255;
      //FastLED.show();
    
      //  Create a child device for each outlet
      for (int sensor = 1; sensor <= NUMBER_OF_OUTLETS; sensor++) {
        gw.present(sensor, S_LIGHT);
        delay(2);
      }
    }
    
    void loop() {
      gw.process();
    }
    
    String getValue(String data, char separator, int index) {
      int found = 0;
      int strIndex[] = {0, -1};
      int maxIndex = data.length() - 1;
    
      for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
          found++;
          strIndex[0] = strIndex[1] + 1;
          strIndex[1] = (i == maxIndex) ? i + 1 : i;
        }
      }
    
      return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
    }
    
    //command has been received from gateway
    void incomingMessage(const MyMessage &message) {
      Serial.println(message.sensor);
      Serial.println(".......");
      Serial.println(message.getInt());
      if (message.type == V_LIGHT) {
        Serial.print("LED ID #: ");
        Serial.println(message.sensor);
        Serial.print("Color: ");
        Serial.println(message.getString());
    
        //receive String like 125-255-111 call getValue and split
        //.toInt() convert the String Number to int and would be assigned to the LED
        leds[message.sensor].r = getValue(message.getString(), '-', 0).toInt();
        leds[message.sensor].g = getValue(message.getString(), '-', 1).toInt();
        leds[message.sensor].b = getValue(message.getString(), '-', 2).toInt();
        FastLED.show();
    
        if (message.sensor == 99) {
          for (int i = 0; i < NUM_LEDS; ++i) {
            leds[i].r = getValue(message.getString(), '-', 0).toInt();
            leds[i].g = getValue(message.getString(), '-', 1).toInt();
            leds[i].b = getValue(message.getString(), '-', 2).toInt();
            FastLED.show();
          }
        }
      }
      delay(50);
    }
    

    The Serial-Monitor shows

    • message.sensor = 7
    • message.getString() = 0-0-255enEG

    Why is there "enEG" at the end?

    Thanks
    Christian

    1 Reply Last reply
    0
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #2

      Make sure to run the latest version in master branch.

      1 Reply Last reply
      0
      • choffmannC Offline
        choffmannC Offline
        choffmann
        wrote on last edited by
        #3

        Sorry,
        what did you mean with that?
        what is a master branch?

        1 Reply Last reply
        0
        • hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #4

          1.5.4 is the latest version on the master branch (on github).

          https://github.com/mysensors/Arduino/releases

          1 Reply Last reply
          0
          • choffmannC Offline
            choffmannC Offline
            choffmann
            wrote on last edited by
            #5

            OK,

            my Mysensors version is 1.5.3 i will update it.
            Do i have to update my Gateway too?

            In the link they talk about issues with the Getters in version 1.5.4. is this what you think that could be the problem?!

            Thanks

            m26872M 1 Reply Last reply
            0
            • choffmannC choffmann

              OK,

              my Mysensors version is 1.5.3 i will update it.
              Do i have to update my Gateway too?

              In the link they talk about issues with the Getters in version 1.5.4. is this what you think that could be the problem?!

              Thanks

              m26872M Offline
              m26872M Offline
              m26872
              Hardware Contributor
              wrote on last edited by
              #6

              @choffmann I would be very happy if you didn't mind to also share some of your FHEM code....?

              1 Reply Last reply
              0
              • choffmannC Offline
                choffmannC Offline
                choffmann
                wrote on last edited by
                #7

                i hope that i can update my arduino tomorrow, so that i can test if this will work....

                The FHEM code you want:
                The Devices:
                define LEDRahmen MYSENSORS_DEVICE 102 ... autmatic including des Reading/Devices
                define LEDRahmenSwitch dummy -- for setting LED and Color manually
                define LEDRahmenSwitchNotify notify LEDRahmenSwitch.* { sendLEDColor($EVTPART0, $EVTPART1) }

                and the 99_myUtils.pm Mehtods:
                (NEW: i have changed the Method from send String like 0-255-0 to 000-255-000 - see Method "changeLengthTo" )

                
                sub sendLEDColor($$){
                  my ($stat,$val) = @_;
                  my $tmp;
                  $tmp .= changeLengthTo(hexstr_to_signed32int(substr($val,0,2)),3);
                  $tmp .= "-";
                  $tmp .= changeLengthTo(hexstr_to_signed32int(substr($val,2,2)),3);
                  $tmp .= "-";
                  $tmp .= changeLengthTo(hexstr_to_signed32int(substr($val,4,6)),3);
                
                  #my $m = hexstr_to_signed32int($tmp);
                  #Log 1, "MeinE Testmethode";
                  #Log 1, $;
                  fhem("set LEDRahmen status".$stat." ".$tmp."");
                
                
                }
                
                sub changeLengthTo($$){
                  my($str,$toLength) = @_;
                  my $tmpstr;
                  for(my $i = (length($str)+1); $i <= $toLength; $i++){
                    $tmpstr.= "0";
                  }
                  return $tmpstr.$str;
                }
                
                sub hexstr_to_signed32int($) {
                    my ($hexstr) = @_;
                    die "Invalid hex string: $hexstr"
                        if $hexstr !~ /^[0-9A-Fa-f]{1,8}$/;
                 
                    my $num = hex($hexstr);
                    return $num >> 31 ? $num - 2 ** 32 : $num;
                }
                
                m26872M 1 Reply Last reply
                1
                • choffmannC choffmann

                  i hope that i can update my arduino tomorrow, so that i can test if this will work....

                  The FHEM code you want:
                  The Devices:
                  define LEDRahmen MYSENSORS_DEVICE 102 ... autmatic including des Reading/Devices
                  define LEDRahmenSwitch dummy -- for setting LED and Color manually
                  define LEDRahmenSwitchNotify notify LEDRahmenSwitch.* { sendLEDColor($EVTPART0, $EVTPART1) }

                  and the 99_myUtils.pm Mehtods:
                  (NEW: i have changed the Method from send String like 0-255-0 to 000-255-000 - see Method "changeLengthTo" )

                  
                  sub sendLEDColor($$){
                    my ($stat,$val) = @_;
                    my $tmp;
                    $tmp .= changeLengthTo(hexstr_to_signed32int(substr($val,0,2)),3);
                    $tmp .= "-";
                    $tmp .= changeLengthTo(hexstr_to_signed32int(substr($val,2,2)),3);
                    $tmp .= "-";
                    $tmp .= changeLengthTo(hexstr_to_signed32int(substr($val,4,6)),3);
                  
                    #my $m = hexstr_to_signed32int($tmp);
                    #Log 1, "MeinE Testmethode";
                    #Log 1, $;
                    fhem("set LEDRahmen status".$stat." ".$tmp."");
                  
                  
                  }
                  
                  sub changeLengthTo($$){
                    my($str,$toLength) = @_;
                    my $tmpstr;
                    for(my $i = (length($str)+1); $i <= $toLength; $i++){
                      $tmpstr.= "0";
                    }
                    return $tmpstr.$str;
                  }
                  
                  sub hexstr_to_signed32int($) {
                      my ($hexstr) = @_;
                      die "Invalid hex string: $hexstr"
                          if $hexstr !~ /^[0-9A-Fa-f]{1,8}$/;
                   
                      my $num = hex($hexstr);
                      return $num >> 31 ? $num - 2 ** 32 : $num;
                  }
                  
                  m26872M Offline
                  m26872M Offline
                  m26872
                  Hardware Contributor
                  wrote on last edited by
                  #8

                  @choffmann Thanks a lot! Please let us know you if the update solved your issue.

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


                  24

                  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