Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. choffmann
    3. Best
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Best posts made by choffmann

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

      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;
      }
      
      posted in Development
      choffmann
      choffmann