Air Conditioning modbus bouncing values

Hi Blynkers,

I am trying to control my air conditioning machine from Blynk. The air conditioning is a modbus RTU slave, and I am using a esp32 with a RS-485 adapter for that.

With the help of the code from @Hussein_Daj, I adapted it, to control/command my machine, and really it is working. I can send commands, and they are executed correctly, and, if someone manage it with the previous control, I can see the AA state in blynk. So that is quite good

The only trouble I am having is, that I am trying to use the same widgets to control and command certain values, so, when I send a command, for example, to increase the temp (from 23), the number is increased to 24, after that, goes back to 23, and finally ends in 24, when this set is confimed. (all this happens in 1 or 2 seconds). Really It is like having “bouncing” values with the commands.
I have been testing with different intervals to request modbus info, but it did not impove.

I understand this is related to time issues, between blynk/modbus update times… because sometimes this is more noticeable than other times (sometimes even it is not happening, it seems that it is related to the moment when the button is pressed)… ​but I do not know how this can be solved :frowning:

The behaviour I would like is: Increase a value with the widget, see this new value at this moment… and wait 1 or 2 seconds until this value is confirmed by normal modbus message.
So, If there was any trouble with this value set, you will see 2 seconds the command, and it will show the real value in the machine again.
Please, dou you have any suggestion or any help fix it?
Let me know if you need any other info

Thanks in advance


#include <ModbusMaster.h>   // ModbusMaster

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#define TXD2 27
#define RXD2 26

ModbusMaster node;    // instantiate ModbusMaster object

char ModBusIO = 4;  //Pin que se emplea para enviar o recibir

bool AAEncendido;
float AATempAire;
float AATempReal;
byte AAModo;
byte AAVelocidad;

char auth[] = "xxxxx";
char ssid[] = "xxxxx";
char pass[] = "xxxxx";


void preTransmission()
{
  digitalWrite(ModBusIO, 1);
}
void postTransmission()
{
  digitalWrite(ModBusIO, 0);
}


BlynkTimer timer;

void myTimerEvent()
{
  Read();

  Blynk.virtualWrite(V0, AAEncendido); //AAEncendido
  Blynk.virtualWrite(V1, AATempAire); //AATempAire
  Blynk.virtualWrite(V2, AATempReal); //AATempReal
  Blynk.virtualWrite(V3, AAModo); //AAModo
  Blynk.virtualWrite(V4, AAVelocidad); //AAVelocidad del ventilador

}

void setup()
{
  pinMode(ModBusIO, OUTPUT);

  Serial.begin(19200);
  WiFi.mode(WIFI_STA);
  //  WiFi.hostname(myHostname);

  timer.setInterval(500L, myTimerEvent);
  
  Blynk.begin(auth, ssid, pass);

  digitalWrite (ModBusIO, LOW);

  Serial2.begin(19200, SERIAL_8E1, RXD2, TXD2);  /// Config modbus AA

  node.begin(1, Serial2);

  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);

  while (Blynk.connect() == false) {}

}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}




//Read Data

void Read() {

  uint8_t result;
  result = node.readHoldingRegisters(0, 5); // slave: read a range of 16-bit registers starting at register 0 to 5
  if (result == node.ku8MBSuccess)   // only do something with data if read is successful
  {
    AAEncendido =  ((bool)node.getResponseBuffer(0));
    AATempAire =  ((float)node.getResponseBuffer(1) / 10);
    AATempReal =  ((float)node.getResponseBuffer(2) / 10);
    AAModo =  ((byte)node.getResponseBuffer(3));
    AAVelocidad =  ((byte)node.getResponseBuffer(4) );
  }
}

//Write Data

BLYNK_WRITE(V0) //On Off Aire Acodicionado
{
  int pinValue = param.asInt(); // assigning incoming value from pin V0 to a variable
  node.writeSingleRegister(0, pinValue); //set power on !
}

BLYNK_WRITE(V1) //Fijar Temperatura
{
  int pinValue = param.asInt(); 
  node.writeSingleRegister(1, pinValue * 10); //set Temp
}


BLYNK_WRITE(V3) //Modo Aire Acondicionado
{
  int pinValue = param.asInt(); // assigning incoming value from pin V3 to a variable
  node.writeSingleRegister(3, pinValue); //set Modo  
}


BLYNK_WRITE(V4) //Velocidad Ventilador
{
  int pinValue = param.asInt(); // assigning incoming value from pin V4 to a variable
  node.writeSingleRegister(4, pinValue); //set Velocidad Ventilador
}

I guess it’s caused by you calling myTimerEventevery 500ms.

Pete.

Thank you Pete for the answer, but I have been testing with different values from 100 to 2000, and I am always having this effect :frowning:
Any other suggestion?
Thanks.

why so frequent?

Pete.