parsing RGB from Dashboard

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
hash20
New user
Posts: 5
Joined: 18 Jan 2022, 19:19

parsing RGB from Dashboard

#1 Post by hash20 » 18 Jan 2022, 19:30

Hi guys.
Can you help me to do it!
When picked color in dashboard i receive: "room/light/color -> #rrggbb" // color in hex format start with '#' char

1. <Generic - MQTT Import'> can only float, no string :(
2. How to parse integers r,g,b from here ?

Thank's.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: parsing RGB from Dashboard

#2 Post by Ath » 18 Jan 2022, 19:47

Where is that value being sent from?
/Ton (PayPal.me)

hash20
New user
Posts: 5
Joined: 18 Jan 2022, 19:19

Re: parsing RGB from Dashboard

#3 Post by hash20 » 18 Jan 2022, 19:57

from android apk. MQTT Dashboard for example.

Another aplication was send the same '#rrggbb' format or 'RGBA(r,g,b,a)' (if use alpha) ' ' - text in payload from broker

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: parsing RGB from Dashboard

#4 Post by Ath » 18 Jan 2022, 20:19

I have been working on MQTT Import plugin for a while, see this PR #3424 I can add support for that type of data, as it currently doesn't support that yet.

Another approach could be to script some kind of replace on the sending side, replacing the "#" prefix by "0x", so the value is properly parsed, but then it still isn't split in R, G and B values.

You could mock up a rule that handles the value using string processing, I'll toy with that idea a bit.
/Ton (PayPal.me)

hash20
New user
Posts: 5
Joined: 18 Jan 2022, 19:19

Re: parsing RGB from Dashboard

#5 Post by hash20 » 19 Jan 2022, 12:52

Great work!!! Thanks. It's a light in end of tube :)

try compile but:
error: src\src\PluginStructs_tmp\__tmpfile.cpp:4752:54: error: 'compareValues' was not declared in this scope


later...
after adding to ESPEasyRules.cpp

Code: Select all

bool compareValues(char compare, float Value1, float Value2)
{
  bool match = false;

  switch (compare) {
    case '>' + '=':

      if (Value1 >= Value2) {
        match = true;
      }
      break;

    case '<' + '=':

      if (Value1 <= Value2) {
        match = true;
      }
      break;

    case '!' + '=':

      if (Value1 != Value2) {
        match = true;
      }
      break;

    case '>':

      if (Value1 > Value2) {
        match = true;
      }
      break;

    case '<':

      if (Value1 < Value2) {
        match = true;
      }
      break;

    case '=':

      if (Value1 == Value2) {
        match = true;
      }
      break;
  }
  return match;
}
result:
custom_ESP8266_4M1M SUCCESS 00:02:06.020

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: parsing RGB from Dashboard

#6 Post by Ath » 19 Jan 2022, 13:29

You should be able to download a precompiled build from the last Github actions run (Scroll to the bottom at the right side of that screen, there's a Binaries.zip file)
If your build-type isn't included, because it failed/got cancelled, then I can create a local build for you to see if that already helps, just mention the name of the .bin file you use for flashing.
/Ton (PayPal.me)

hash20
New user
Posts: 5
Joined: 18 Jan 2022, 19:19

Re: parsing RGB from Dashboard

#7 Post by hash20 » 19 Jan 2022, 18:16

Ath wrote: 19 Jan 2022, 13:29 You should be able to download a precompiled build from the last Github actions run (Scroll to the bottom at the right side of that screen, there's a Binaries.zip file)
If your build-type isn't included, because it failed/got cancelled, then I can create a local build for you to see if that already helps, just mention the name of the .bin file you use for flashing.
Thank's

I was compiled success.

After i was added some code:

Code: Select all

if (matchedTopic && Payload.substring(0, 1) == F("#")) {
          addLog(LOG_LEVEL_INFO, F("IMPT : ... transforming HTML color to JSON"));
          int r,g,b = 0;
          sscanf(Payload.c_str(), "#%02x%02x%02x", &r, &g, &b); 
          Payload = "{\"r\":" ;
          Payload += r;
          Payload += ",\"g\":";
          Payload += g;
          Payload += ",\"b\":";
          Payload += b;
          Payload += "}\n";
        }
It Work!!!

Code: Select all

66305 : Info   : IMPT : ... transforming HTML color to JSON
66308 : Info   : IMPT : [controll#Rgb] : 0.00
66369 : Info   : EVENT: controll#room/test/rgb/Rgb=#ffffff
66468 : Info   : EVENT: controll#Rgb={"r":255,"g":255,"b":255}

Code: Select all

977929 : Info   : IMPT : ... transforming HTML color to JSON
977931 : Info   : IMPT : MQTT 037 JSON data detected.
but i don't understand how to catch event in rules for getting data."Parse JSON messages: set ON" in plugin settings. Help please :)

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: parsing RGB from Dashboard

#8 Post by Ath » 19 Jan 2022, 20:02

hash20 wrote: 19 Jan 2022, 12:52 try compile but:
error: src\src\PluginStructs_tmp\__tmpfile.cpp:4752:54: error: 'compareValues' was not declared in this scope


later...
after adding to ESPEasyRules.cpp
Not sure why you have to add that to the source code, I've never had to do anything like that. Did you clone the regular ESPEasy project, or forked it first?
hash20 wrote: 19 Jan 2022, 18:16 After i was added some code:

Code: Select all

if (matchedTopic && Payload.substring(0, 1) == F("#")) {
          addLog(LOG_LEVEL_INFO, F("IMPT : ... transforming HTML color to JSON"));
...
I think converting a message that starts with a # could be converted into separate R, G, B values a bit easier if I add that as a mapping. I'll think of a way to implement that, and generate a single event with 3 values from it, so you could handle it in rules.

Also want to take 1 step back and ask the 'big' question: What is the purpose of having your MQTT rrggbb color value split into separate colors?
/Ton (PayPal.me)

hash20
New user
Posts: 5
Joined: 18 Jan 2022, 19:19

Re: parsing RGB from Dashboard

#9 Post by hash20 » 19 Jan 2022, 20:48

Not sure why you have to add that to the source code, I've never had to do anything like that. Did you clone the regular ESPEasy project, or forked it first?
Sorry, it my first expirience with Platformio and EasyESP (3-4 days) :) i just create a new project from git. I don't understand how i can do it, but it work :))))
I think converting a message that starts with a # could be converted into separate R, G, B values a bit easier if I add that as a mapping. I'll think of a way to implement that, and generate a single event with 3 values from it, so you could handle it in rules.
Ok, thanks. But i want make it self :)
... if you will "toy" with it then better parse 4 parameters R,G,B,W (full support for all strips will be or can use this chanell as alpha)
Also want to take 1 step back and ask the 'big' question: What is the purpose of having your MQTT rrggbb color value split into separate colors?
I'm using application https://play.google.com/store/apps/deta ... mqtt&gl=UA

it have color picker component. After picked it publish ' #rrggbb' message to assigned topic.
i want to recieve it and send the command in rules:

Code: Select all

NeoPixelAll,[dummy#VarGreen],[dummy#VarRed],[dummy#VarBlue],[dummy#VarWhite]]

I try get this fucked parameters while.... help please :roll:

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: parsing RGB from Dashboard

#10 Post by Ath » 19 Jan 2022, 22:16

hash20 wrote: 19 Jan 2022, 20:48 Ok, thanks. But i want make it self :)
... if you will "toy" with it then better parse 4 parameters R,G,B,W (full support for all strips will be or can use this chanell as alpha)
I wrote a starters guide for development on ESPEasy: https://espeasy.readthedocs.io/en/lates ... on-espeasy
hash20 wrote: 19 Jan 2022, 20:48 I'm using application https://play.google.com/store/apps/deta ... mqtt&gl=UA

it have color picker component. After picked it publish ' #rrggbb' message to assigned topic.
i want to recieve it and send the command in rules:

Code: Select all

NeoPixelAll,[dummy#VarGreen],[dummy#VarRed],[dummy#VarBlue],[dummy#VarWhite]]
That last line could be in a rule like:

Code: Select all

on controll#Rgb do
 NeoPixelAll,%eventvalue1%,%eventvalue2%,%eventvalue4%,%eventvalue4%
endon
after I add that splitting and parsing of #RGBW into separate values ;)
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests