From 0d136c9e1f6677bd9b51435ae9d69dfd02e39585 Mon Sep 17 00:00:00 2001 From: dev0 <> Date: Thu, 20 Apr 2017 10:52:02 +0000 Subject: [PATCH] ESPEasy: urlEncode text for display commands git-svn-id: https://svn.fhem.de/fhem/trunk@14045 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/34_ESPEasy.pm | 77 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 97ef3bec2..79b77377f 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 34_ESPEasy: urlEncode text for display commands - feature: 71_PHILIPS_AUDIO: Added NP3500 support. "lvl" Reading bugfix. - change: 93_DbLog: version 2.16.5 primary key evaluation changed - bugfix: 32_withings: updated for new account key characters diff --git a/fhem/FHEM/34_ESPEasy.pm b/fhem/FHEM/34_ESPEasy.pm index 713f40993..fd7d4b8d4 100644 --- a/fhem/FHEM/34_ESPEasy.pm +++ b/fhem/FHEM/34_ESPEasy.pm @@ -36,7 +36,7 @@ use Color; # ------------------------------------------------------------------------------ # global/default values # ------------------------------------------------------------------------------ -my $module_version = 1.01; # Version of this module +my $module_version = 1.03; # Version of this module my $minEEBuild = 128; # informational my $minJsonVersion = 1.02; # checked in received data @@ -49,6 +49,9 @@ my $d_maxHttpSessions = 3; # concurrent connects to a single esp my $d_maxQueueSize = 250; # max queue size, my $d_resendFailedCmd = 0; # resend failed http requests by default? +my $d_displayTextEncode = 1; # urlEncode Text for Displays +my $d_displayTextWidth = 0; # display width, 0 => disable formating + # ------------------------------------------------------------------------------ # "setCmds" => "min. number of parameters" # ------------------------------------------------------------------------------ @@ -214,6 +217,8 @@ sub ESPEasy_Initialize($) ."colorpicker:RGB,HSV,HSVp " ."deniedIPs " ."disable:1,0 " + ."displayTextEncode:1,0 " + ."displayTextWidth " ."do_not_notify:0,1 " ."httpReqTimeout " ."IODev " @@ -484,6 +489,9 @@ sub ESPEasy_Set($$@) return "Unknown argument $cmd, choose one of ". $clist; } + # urlEncode parameter + @params = ESPEasy_urlEncodeDisplayText($hash,$cmd,@params); + # pin mapping (eg. D8 -> 15) my $pp = ESPEasy_paramPos($cmd,''); if ($pp && $params[$pp-1] =~ m/^[a-zA-Z]/) { @@ -859,6 +867,7 @@ sub ESPEasy_Attr(@) if (defined $hash->{SUBTYPE} && $hash->{SUBTYPE} eq "bridge" && ($aName =~ m/^(Interval|pollGPIOs|IODev|setState|readingSwitchText)$/ || $aName =~ m/^(readingPrefixGPIO|readingSuffixGPIOState|adjustValue)$/ + || $aName =~ m/^(displayTextEncode|displayTextWidth)$/ || $aName =~ m/^(presenceCheck|parseCmdResponse|rgbGPIOs|colorpicker)$/ || $aName =~ m/^(wwcwGPIOs|colorpickerCTww|colorpickerCTcw|mapLightCmds)$/)) { Log3 $name, 2, "$type $name: Attribut '$aName' can not be used by bridge"; @@ -875,7 +884,8 @@ sub ESPEasy_Attr(@) } elsif ($aName =~ m/^(autosave|autocreate|authentication|disable)$/ - || $aName =~ m/^(presenceCheck|readingSwitchText|resendFailedCmd)$/) { + || $aName =~ m/^(presenceCheck|readingSwitchText|resendFailedCmd)$/ + || $aName =~ m/^(displayTextEncode)$/) { $ret = "0,1" if ($cmd eq "set" && not $aVal =~ m/^(0|1)$/)} elsif ($aName eq "combineDevices") { @@ -912,6 +922,10 @@ sub ESPEasy_Attr(@) $ret = "integer" if ($cmd eq "set" && not $aVal =~ m/^(\d+)$/)} + elsif ($aName eq "displayTextWidth") { + $ret = "number of charaters per line" + if ($cmd eq "set" && not $aVal =~ m/^(\d+)$/)} + elsif ($aName eq "readingPrefixGPIO") { $ret = "[a-zA-Z0-9._-/]+" if ($cmd eq "set" && $aVal !~ m/^[A-Za-z\d_\.\-\/]+$/)} @@ -2042,6 +2056,47 @@ sub ESPEasy_adjustValue($$$) } +# ------------------------------------------------------------------------------ +sub ESPEasy_urlEncodeDisplayText($$@) +{ + my ($hash, $cmd, @params) = @_; + my $name = $hash->{NAME}; + my $enc = AttrVal($name, "displayTextEncode", $d_displayTextEncode); + my $pp = ESPEasy_paramPos($cmd,''); + + if ($enc && $pp) { + my (@p, @t); + my $c = scalar @params; + + # leading parameters + for (my $i=0; $i<$pp-1; $i++) { + push( @p, $params[$i] ) + } + + # collect all texts parameters + for (my $i=$pp-1; $i<$c; $i++) { + $params[$i] =~ s/,/./g; # comma is http url parameter splitter + #$params[$i] =~ s/[\x00-\x1F\x7F-\xFF]//g; # remove non-printable chrs + push( @t, $params[$i] ) + } + my $text = join(" ", @t); + + # fill line with leading/trailing spaces + my $width = AttrVal($name,"displayTextWidth", $d_displayTextWidth); + if ($width) { + $text = " " x ($p[1]-1) .$text. " " x ($width - length($text) - $p[1]+1); + $text = substr($text, 0, $width); + $p[1] = 1; + } + + push(@p, urlEncode($text)); + return @p; + } + + return @params; +} + + # ------------------------------------------------------------------------------ sub ESPEasy_isPmInstalled($$) { @@ -2852,7 +2907,7 @@ sub ESPEasy_removeGit($) Default: none
Eg. attr ESPxx adjustValue humidity:+0.1 - temperature+*:($VALUE-32)*5/9
+ temperature*:($VALUE-32)*5/9
Eg. attr ESPxx adjustValue .*:my_OwnFunction($NAME,$READING,$VALUE)

@@ -2884,6 +2939,22 @@ sub ESPEasy_removeGit($) Possible values: 0,1
Default: 0
+
  • displayTextEncode
    + Used to disable url encoding for text that is send to oled/lcd displays. + Useful if you want to encode the text by yourself.
    + Possible values: 0,1
    + Default: 1 (enabled)

  • + +
  • displayTextWidth
    + Used to specify number of characters per display line.
    + If set then all characters before and after the text on the same line will + be overwritten with spaces. Attribute + displayTextEncode must not be + disabled to use this feature. A 128x64px display has 16 characters per + line if you are using a 8px font.
    + Possible values: integer
    + Default: 0 (disabled)

  • +
  • Interval
    Used to set polling interval for presence check and GPIOs polling in seconds. 0 will disable this feature.