PWM Output over mqtt

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Haubke
New user
Posts: 5
Joined: 18 Oct 2015, 12:35

PWM Output over mqtt

#1 Post by Haubke » 20 Oct 2015, 17:21

hello all,

i'm wokring on my home automation system. my question is.
is it possible to set a pwm output directly over lets say , openhab mqtt?.
only info i could find was over http. thats not what i want to use. i'm using espeasy r20.
so maybe i should get a later one? or should i dive deep in source code to make it possible?.

thanks in advance.

Haubke
New user
Posts: 5
Joined: 18 Oct 2015, 12:35

Re: PWM Output over mqtt

#2 Post by Haubke » 20 Oct 2015, 21:52

i guess i found the answer.

but i'm not sure.

i tried every way i could see how this should work:(i'm not a pro):
in case of openhab mqtt.

if message recieved the following case statement is run CPLUGIN_PROTOCOL_RECV.
this will split the topic in parts. so i guess in my case:

/woonkamer/pwm/16
/espname/cmd/pin, then payload is value.

after this it will call plugin.write(let this code run).
but then i see in _p001_switch.ino the folowing:
see arrows:

Code: Select all

case PLUGIN_WRITE:
      {
        String tmpString  = string;
        int argIndex = tmpString.indexOf(','); << ----- why this comma? is this only for http command?
        if (argIndex)
          tmpString = tmpString.substring(0, argIndex);
        if (tmpString.equalsIgnoreCase("GPIO"))
        {
          success = true;
          if (event->Par1 >= 0 && event->Par1 <= 16)   <<----- looks correct for gpio output
          {
            pinMode(event->Par1, OUTPUT);			<<----- first parameter pin number
            digitalWrite(event->Par1, event->Par2);		<<----- same
            if (printToWeb)
            {
              printWebString += F("GPIO ");
              printWebString += event->Par1;
              printWebString += F(" Set to ");
              printWebString += event->Par2;
              printWebString += F("<BR>");
            }
          }
        }

        if (tmpString.equalsIgnoreCase("PWM")) 	<<----- command pwm output
        {
          success = true;
          if (event->Par1 >= 0 && event->Par1 <= 1023)           <<<<<<<<<<--------------- should this be 0 - 16? or am i wrong?
          {
            pinMode(event->Par1, OUTPUT);
            analogWrite(event->Par1, event->Par2); <<<<<<<-------- analogwrite first parameter is pin number  second parameter value?
            if (printToWeb)
            {
[code/]
i once did get output out of my ledstrip true mqtt but i'm not able to replicate that. should i set some flag or something? 
i really have no clue.  tomorrow i will get further. 

maybe someone can help ? or give me advice where to look for th answer?.

thanks guys, keep up the good work.

edit//

i did send value to:
/woonkamer/pwm/16- value

but nothing happens. o and i think i found a bug. sometimes when i'm in device setup i get following error in browser:
ERR_CONTENT_LENGTH_MISMATCH. ?? sometimes it works sometimes not. btw i'm using latest build (39).


i guess it works fine. i'm so stupid sometimes haha. my mqtt client was at fault ;S but i still think the analogwrite function should be different. because you can have 1023 outputs?

thanks

Deennoo
Normal user
Posts: 158
Joined: 07 Sep 2015, 13:03

Re: PWM Output over mqtt

#3 Post by Deennoo » 22 Oct 2015, 13:09

does it can be the same way to send analog value to a domoticz mqtt ?

Haubke
New user
Posts: 5
Joined: 18 Oct 2015, 12:35

Re: PWM Output over mqtt

#4 Post by Haubke » 22 Oct 2015, 21:36

No if you use domoticz it would be different.

In topic of domoticz is (sensor data to domoticz )
domoticz/in

Out topic is: (receive data in esp)
Domoticz/out

But in domoticz you use json. So its a whole other way of sending/receiving data. You should take a look inside _c002.ino to look for how it works. (Still in development)I think its not ready yet(i'm not one of the programmers).
Greetings

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests