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);
}