StrathbogieBrewing / VEDirect

Arduino interface for VE.Direct Hex protocol
MIT License
15 stars 7 forks source link

GET command always returns '11' #6

Open NEXT-JP opened 2 years ago

NEXT-JP commented 2 years ago

I am unable to successfully use the GET command (mppt.get(id)). A value of 11 is always returned, regardless of the value for id I provide.

Example code, basically just a modified version of the example.

#include "VEDirect.h"

void mpptCallback(uint16_t id, int32_t value);
VEDirect mppt(Serial1, mpptCallback);

uint16_t panelVoltage = 0;
uint16_t panelPower = 0;
uint16_t chargeVoltage = 0;
uint16_t chargeCurrent = 0;
uint16_t loadVoltage = 0;
uint16_t loadCurrent = 0;
uint16_t loadOnOff = 0;
uint16_t batterySense = 0;

void setup()
{
  Serial.begin(115200);
  mppt.begin();
  delay(1000);
}

void loop()
{
  static unsigned long secondsTimer = 0;
  mppt.update();
  unsigned long m = millis();
  if (m - secondsTimer > 1000L)
  {
    secondsTimer = m;
    Serial.println(mppt.get(0x0201)); // this prints 11 for any value of id!

    mppt.ping(); // send ping every second
  }
}

void mpptCallback(uint16_t id, int32_t value)
{

  if (id == VEDirect_kPanelVoltage)
  {
    panelVoltage = value;
  }
  if (id == VEDirect_kChargeCurrent)
  {
    chargeCurrent = value;
  }
}
StrathbogieBrewing commented 2 years ago

The get method returns the number of bytes written to the VE Direct device, in this case 11 bytes in the message. The system is asynchronous to allow for response messages getting mixed up. The callback function should look for the response to your request and print the value. Note that request 0x0201 needs to be implemented in the library and it's probably good to give it a name, like VEDirect_kDeviceState.

void mpptCallback(uint16_t id, int32_t value)
{
  if (id == 0x0201)
  {
    Serial.println(value);
  }
}