Victron Energy solar a vyčtení hodnot

jankop
Příspěvky: 1029
Registrován: 06 zář 2017, 20:04
Reputation: 0
Bydliště: Brno
Kontaktovat uživatele:

Re: Victron Energy solar a vyčtení hodnot

Příspěvek od jankop » 16 bře 2022, 18:54

A vypisovalo ti to vůbec někdy nějaké hodnoty?
Ty hodnoty bez zapojení dalších prvků mohou být klidně nulové.

Kony
Příspěvky: 382
Registrován: 09 dub 2020, 11:43
Reputation: 0

Re: Victron Energy solar a vyčtení hodnot

Příspěvek od Kony » 16 bře 2022, 18:58

ee nikdy mi to nic nevypisovalo :)
proto jsem psal, ze musim vyzkouset ten orig :)

jankop
Příspěvky: 1029
Registrován: 06 zář 2017, 20:04
Reputation: 0
Bydliště: Brno
Kontaktovat uživatele:

Re: Victron Energy solar a vyčtení hodnot

Příspěvek od jankop » 16 bře 2022, 19:37

Original zkus, ale ten to nespasí. Moje úprava vypisuje nuly, protože tam ty proměnné nulami inicializuji. Ale bez solárního panelu tam nuly být mají.
Zkus třeba tohle, pokud tam budou samé nuly když je připojen Victron, tak to funguje správně. Pokud tam bude 1.0 , 2.0, 3.0, 4.0 tak to data z Victronu nepřijímá. :D

Kód: Vybrat vše

/*
    Victron.Arduino-ESP8266
    A:Pim Rutgers
    E:pim@physee.eu
    Code to grab data from the VE.Direct-Protocol on Arduino / ESP8266.
    Tested on NodeMCU v1.0
    The fields of the serial commands are configured in "config.h"
*/
#include <SoftwareSerial.h>
#include "config.h"

// Serial variables
#define rxPin D7
#define txPin D8                                    // TX Not used
SoftwareSerial victronSerial(rxPin, txPin);         // RX, TX Using Software Serial so we can use the hardware serial to check the ouput
// via the USB serial provided by the NodeMCU.
char receivedChars[buffsize];                       // an array to store the received data
char tempChars[buffsize];                           // an array to manipulate the received data
char recv_label[num_keywords][label_bytes]  = {0};  // {0} tells the compiler to initalize it with 0.
char recv_value[num_keywords][value_bytes]  = {0};  // That does not mean it is filled with 0's
char value[num_keywords][value_bytes]       = {0};  // The array that holds the verified data
static byte blockindex = 0;
bool new_data = false;
bool blockend = false;
float Vx = 1000;
float Ix = 2000;
float PPVx = 3.0;
float H21x = 4.0;


void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  victronSerial.begin(19200);
}

void loop() {
  // Receive information on Serial from MPPT
  RecvWithEndMarker();
  HandleNewData();

  // Just print the values every second,
  // Add your own code here to use the data.
  // Make sure to not used delay(X)s of bigger than 50ms,
  // so make use of the same principle used in PrintEverySecond()
  // or use some sort of Alarm/Timer Library
  PrintEverySecond();
}

// Serial Handling
// ---
// This block handles the serial reception of the data in a
// non blocking way. It checks the Serial line for characters and
// parses them in fields. If a block of data is send, which always ends
// with "Checksum" field, the whole block is checked and if deemed correct
// copied to the 'value' array.

void RecvWithEndMarker() {
  static byte ndx = 0;
  char endMarker = '\n';
  char rc;

  while (victronSerial.available() > 0 && new_data == false) {
    rc = victronSerial.read();
    if (rc != endMarker) {
      receivedChars[ndx] = rc;
      ndx++;
      if (ndx >= buffsize) {
        ndx = buffsize - 1;
      }
    }
    else {
      receivedChars[ndx] = '\0'; // terminate the string
      ndx = 0;
      new_data = true;
    }
    yield();
  }
}

void HandleNewData() {
  // We have gotten a field of data
  if (new_data == true) {
    //Copy it to the temp array because parseData will alter it.
    strcpy(tempChars, receivedChars);
    ParseData();
    new_data = false;
  }
}

void ParseData() {
  char * strtokIndx; // this is used by strtok() as an index
  strtokIndx = strtok(tempChars, "\t");     // get the first part - the label
  // The last field of a block is always the Checksum
  if (strcmp(strtokIndx, "Checksum") == 0) {
    blockend = true;
  }
  strcpy(recv_label[blockindex], strtokIndx); // copy it to label

  // Now get the value
  strtokIndx = strtok(NULL, "\r");    // This continues where the previous call left off until '/r'.
  if (strtokIndx != NULL) {           // We need to check here if we don't receive NULL.
    strcpy(recv_value[blockindex], strtokIndx);
  }
  blockindex++;

  if (blockend) {
    // We got a whole block into the received data.
    // Check if the data received is not corrupted.
    // Sum off all received bytes should be 0;
    byte checksum = 0;
    for (int x = 0; x < blockindex; x++) {
      // Loop over the labels and value gotten and add them.
      // Using a byte so the the % 256 is integrated.
      char *v = recv_value[x];
      char *l = recv_label[x];
      while (*v) {
        checksum += *v;
        v++;
      }
      while (*l) {
        checksum += *l;
        l++;
      }
      // Because we strip the new line(10), the carriage return(13) and
      // the horizontal tab(9) we add them here again.
      checksum += 32;
    }
    // Checksum should be 0, so if !0 we have correct data.
    if (!checksum) {
      // Since we are getting blocks that are part of a
      // keyword chain, but are not certain where it starts
      // we look for the corresponding label. This loop has a trick
      // that will start searching for the next label at the start of the last
      // hit, which should optimize it.
      int start = 0;
      for (int i = 0; i < blockindex; i++) {
        for (int j = start; (j - start) < num_keywords; j++) {
          if (strcmp(recv_label[i], keywords[j % num_keywords]) == 0) {
            // found the label, copy it to the value array
            strcpy(value[j], recv_value[i]);
            start = (j + 1) % num_keywords; // start searching the next one at this hit +1
            break;
          }
        }
      }
    }
    // Reset the block index, and make sure we clear blockend.
    blockindex = 0;
    blockend = false;
  }
}

void PrintEverySecond() {
  static unsigned long prev_millis;
  if (millis() - prev_millis > 1000) {
    PrintValues();
    prev_millis = millis();
  }
}

void PrintValues() {
  Vx = atof(value[V])/1000;
  Ix = atof(value[I])/1000;
  PPVx = atof(value[PPV]);
  H21x = atof(value[H21]);
  Serial.print(keywords[3]);
  Serial.print(",");
  Serial.println(Vx);
  Serial.print(keywords[4]);
  Serial.print(",");
  Serial.println(Ix);
  Serial.print(keywords[6]);
  Serial.print(",");
  Serial.println(PPVx);
  Serial.print(keywords[13]);
  Serial.print(",");
  Serial.println(H21x);
  Serial.println("");
}

Kony
Příspěvky: 382
Registrován: 09 dub 2020, 11:43
Reputation: 0

Re: Victron Energy solar a vyčtení hodnot

Příspěvek od Kony » 16 bře 2022, 20:16

Vyzkousim a dam vedet. Diky moc za ponoc

jankop
Příspěvky: 1029
Registrován: 06 zář 2017, 20:04
Reputation: 0
Bydliště: Brno
Kontaktovat uživatele:

Re: Victron Energy solar a vyčtení hodnot

Příspěvek od jankop » 17 bře 2022, 13:39

Omlouvám se, ten výše uvedený program je sice funkční, ale nic neřeší. Když použiješ ten původní, tak bude vypisovat z Victronu snad i nějaké nenulové parametry. A bude-li to tak, pak komunikace funguje.

Kony
Příspěvky: 382
Registrován: 09 dub 2020, 11:43
Reputation: 0

Re: Victron Energy solar a vyčtení hodnot

Příspěvek od Kony » 17 bře 2022, 16:05

Nahral jsem original.... a nic, ale pak jsem si zaval hrat s aplikaci v mobilu vcetne Ve.Network nebo jak se to jmenuje a pak prepinat ruzne varianty v nastaveni Tx portu a jednou to poslalo udaje a pak porad ty stejny, ikdyz jsem ruzne zatezoval baterky tak porad stejny

Ale vubec nevim jak se mi to podarilo, zkousim znovu ruzne prepinat a nic. Zase nevycita

Kony
Příspěvky: 382
Registrován: 09 dub 2020, 11:43
Reputation: 0

Re: Victron Energy solar a vyčtení hodnot

Příspěvek od Kony » 17 bře 2022, 16:33

Nemuze to byt tim optomodulem, z je tam psano 12V ??

Kony
Příspěvky: 382
Registrován: 09 dub 2020, 11:43
Reputation: 0

Re: Victron Energy solar a vyčtení hodnot

Příspěvek od Kony » 17 bře 2022, 16:56

Napadlo me i tam dat mobil s androidem a sparovat to, ale zase jak vytahnout ty data z te aplikace a donutit mobil aby byl porad zapnuty a rozsviceny..
a nebo uplne psycho nejak vyresit stale zapnuty displey a pomoci externi kamery odecitat hodnoty...

Am tuto kameru https://dratek.cz/arduino/1578-640x480- ... 7yEALw_wcB

Kony
Příspěvky: 382
Registrován: 09 dub 2020, 11:43
Reputation: 0

Re: Victron Energy solar a vyčtení hodnot

Příspěvek od Kony » 17 bře 2022, 17:51

Nevim jestli je to realny pomoci te kamery odecitat ty hodnoty. Nacitaly by se cca jednou za minutu ze snimku v priloze... a prevedly ty hodnoty na promenne..
Přílohy
BAE4E347-AFE9-4402-9418-FFD47BEE1C81.jpeg

jankop
Příspěvky: 1029
Registrován: 06 zář 2017, 20:04
Reputation: 0
Bydliště: Brno
Kontaktovat uživatele:

Re: Victron Energy solar a vyčtení hodnot

Příspěvek od jankop » 17 bře 2022, 20:15

Vymýšlíš nereálné nesmysly. Ten optočlen by na 90% měl být v pořádku. Když odpojíš Victron a připojíš místo něj zdroj 5 voltů, tak na D7 ESP8266 by mělo být napětí menší než 1V. Odhaduji, že někde spíš děláš chybu.

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 6 hostů