MQTT sending a custom commands

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
arnoldg
Normal user
Posts: 14
Joined: 29 Aug 2017, 07:02

MQTT sending a custom commands

#1 Post by arnoldg » 05 Jan 2018, 10:47

Hello,

because i'm in the transit from http to mqtt i need some help in altering my custom plugin.

In this plugin i send a custom command dim with a value.
How do i do this with mqtt, is espeasy accepting custom commands programmed within the plugin or do i need to do program some work around ?

below is my working plugin

Code: Select all

//#######################################################################################################
//#################################### Plugin 200: dimmer ##################################################
//#######################################################################################################

// Sample templates
//  Temp: [DHT11#Temperature]   Hum:[DHT11#humidity]
//  DS Temp:[Dallas1#Temperature#R]
//  Lux:[Lux#Lux#R]
//  Baro:[Baro#Pressure#R]

#define PLUGIN_200
#define PLUGIN_ID_200         20000
#define PLUGIN_NAME_200       "Dimmer 230V "
#define PLUGIN_VALUENAME1_200 "Dimmer"


boolean Plugin_200_init = false;

boolean Plugin_200(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;

  switch (function)
  {
    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_200;
        Device[deviceCount].Type = DEVICE_TYPE_I2C;
        Device[deviceCount].VType = SENSOR_TYPE_DIMMER;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = false;
        Device[deviceCount].ValueCount = 0;
        Device[deviceCount].SendDataOption = false;
        Device[deviceCount].TimerOption = false;
        break;
      }

    case PLUGIN_GET_DEVICENAME:
      {
        string = F(PLUGIN_NAME_200);
        break;
      }

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_200));
        break;
      }

      case PLUGIN_INIT:
        {
          Serial.begin(9600);
          addLog(LOG_LEVEL_INFO, F("Dimmer: Init OK "));
          break;
        }


      case PLUGIN_WRITE:
      {
        String log = "";
        String command = parseString(string, 1);

        if (command == F("dim"))
        {
          Plugin_200_Write(event->Par1);
          log = String(F(" Set Dim level to ")) + String(event->Par1);
          addLog(LOG_LEVEL_INFO, log);
        }
      }
    }
  return success;
}


//********************************************************************************
// write
//********************************************************************************
void Plugin_200_Write(byte Par1)
{
  Serial.write(Par1);
}

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: MQTT sending a custom commands

#2 Post by vader » 05 Jan 2018, 16:11

Why extra programming a new plug-in? All basic MQTT functions are on-board. You can setup this under "Controllers". What broker do you have?

arnoldg
Normal user
Posts: 14
Joined: 29 Aug 2017, 07:02

Re: MQTT sending a custom commands

#3 Post by arnoldg » 05 Jan 2018, 16:29

Hello,

i have installed mosquitto on my rasp.
I selected in controllermqtt openhab.

but i don't want to use the gpio or pwm commands.
i need to send command dim with a value from 0 to 100.

the plugin i sended did this throug http, i wan't to do the same thing with mqtt.

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: MQTT sending a custom commands

#4 Post by vader » 05 Jan 2018, 17:42

Ok, I'm not sure, but I mean all has to be done in the JSON format. So "dim" would be the topic, and the value of it the payload. What about the MQTT Import plug-in?

Post Reply

Who is online

Users browsing this forum: No registered users and 51 guests