I'm trying to develop a dimmer which is controlled by serial.
For this i use softserial on puin D1 and D2
But when i compill all looks good, but it isn't working.
What could be wrong ?
for testing purpose the esp should spit out the whole alfabet, but this isn't working.
on the TX and RX pin's i connected a serial to USB print to monitor the serial port.
and yes TX and RX are connected the right way.
this is when i upload the softserial example it is working !
Code: Select all
//#######################################################################################################
//#################################### Plugin 200: Dimmer ##################################################
//#######################################################################################################
#define PLUGIN_200
#define PLUGIN_ID_200 200
#define PLUGIN_NAME_200 "Dimmer 230V "
#define PLUGIN_VALUENAME1_200 "Dimmer"
#define MinDim 15
#define MaxDim 250
#include <SoftwareSerial.h> // to use pin 4 and 5 as RX and TX ports
SoftwareSerial DimSerial(D1,D2,false,256); // RX, TX
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_SINGLE;
Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
Device[deviceCount].SendDataOption = false;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_200);
break;
}
case PLUGIN_WEBFORM_LOAD:
{
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
success = true;
break;
}
case PLUGIN_INIT:
{
DimSerial.begin(9600);
addLog(LOG_LEVEL_INFO, F("Dimmer: Init OK "));
for (char ch = ' '; ch <= 'z'; ch++) {
DimSerial.write(ch);
}
DimSerial.println("");
break;
}
case PLUGIN_READ:
{
// This routine does not output any data and so we do not need to respond to regular read requests
success = false;
break;
}
case PLUGIN_WRITE:
{
String log = "";
String command = parseString(string, 1);
byte payload = (event->Par2 * 2.55);
if (payload<MinDim) { payload = 0; };
if (payload>MaxDim) { payload = 255; };
String status = "Command : "+ command + ", Payload : " + payload;
addLog(LOG_LEVEL_INFO, status);
if (command == F("dim"))
{
DimSerial.write(payload);
log = String(F(" Set Dim level to ")) + String(payload);
addLog(LOG_LEVEL_INFO, log);
}
success = true;
break;
}
}
return success;
}