Arduino DUE werte per MQTT an Broker senden

Hallo, bin ziemlich neu hier, ich arbeite hauptsächlich mit Tasmota, leider kann ich nicht die Werte mit Tasmota auslesen, es geht nur mit Arduino Due, es geht um Tesla Batteriepack auslesen. Alle Werte bekomme ich ohne Probleme, allerdings möchte ich gerne meine Werte weiter per MQTT leiten, aber wie kann ich das machen? Hat jemand eine Idee?


Du könntest eine passende Schnittstelle zum Netzwerk / Internet per Lan oder Wlan anbauen. Das geht z.B. per ESP8266 und dann per Wlan.

danke für schnelle Antwort, wie soll das gehen? Meinst du alle daten auf ESP8266 senden?

Ja, du musst diese Daten ja irgendwie ins Netz bekommen. Ich sehe da diesen als einfachste Lösung. Das geht dann über die UART.
Evtl. kannst du deine Daten ja auch mit einem ESP32 auslesen und damit direkt weiter senden, also ohne den DUE.

ja, das ist die Frage, wie bekomme ich die Daten ins Netz? Ok, muss ich probieren, ob ESP32 geht.

Da gibt es hier im Forum reichlich Ansätze. Mit dem ESP8266 oder ESP32.
Wenn du die Daten mit einem ESP32 auslesen kannst, was ich ganz stark vermute, ist das dann die einfachere Lösung.

1 Like

Angeblich sollte es kein Problem auf esp32 zum Laufen bringen, allerdings muss in code, was geändert werden, weil esp32 keine serielle USB-Port hat. Wo soll ich die Änderungen vornehmen (welche Datei) und wie bekomme ich die Daten wieder auf PC?
Hier ist link zum github

so sollte die Datei geändert werden:

I think really the biggest change to compile on an ESP32 is that it has no USB based serial so all the status output needs to go to a normal serial port instead and the serial port to communicate with the BMS slaves is initialized differently.

Here's some quick advice for setting up the serial port to the tesla hardware:
HardwareSerial Serial2(1); //define second serial port for Tesla BMS board
Serial2.begin(BMS_BAUD, SERIAL_8N1, 4, 2); //rx pin is 4, tx pin is 2

Obviously BMS_BAUD should be one of the speeds, 612500 being a common one. There's a slightly faster one for newer Tesla hardware, 631578. I think we had better luck just using 631578 all the time. I don't think the ESP32 can quite generate that exact rate but it gets close enough.

So, no, I don't believe the ESP32 is available anywhere but really you just redirect all serial console output to Serial and all BMS traffic to Serial2 - initialized as above.

Wer sagt das ?
Oder welcher ESP32 ist das ? Es gibt nicht nur einen.

Ach ESP32 Devkit hat doch serielle USB-Port? Oder ist es nicht richtig?

Das ist richtig. Der hat den seriellen USB-Port.
darüber kann der geflasht und auch debuggt werden.

Würdest du mir helfen, diese auf esp32_Devkitc_V4 zum Laufen zu bringen? Natürlich nicht um sonst!
Da muss, glaube ich, was in Code geändert werden, wegen seriellen Port

SERIAL_8N1, /* rx */ GPIO_NUM_2, /* tx */ GPIO_NUM_1);
oder so:
SERIAL_8N1, 4, 2); //rx pin is 4, tx pin is 2

ich weiß nicht, ob das richtig ist :tired_face:

da gibt es ein Projekt auf esp32 Hier

Folgende Anweisungen sollten bei dir funktionieren:

// Definitionen
#define BMS_BAUD 9600
#define RX_BMS_PIN    16                                // BMS UART RX Serial2 
#define TX_BMS_PIN    17                                // BMS UART TX Serial2 

HardwareSerial BMS_Serial2(1);

//Setup
BMS_Serial2.begin(BMS_BAUD, SERIAL_8N1, RX_BMS_PIN, TX_BMS_PIN);

Die Baud Zahl evtl. anpassen.

Dankeschön :pray: 16 ist RX und 17 ist TX dass heißt RX auf GPIO 16 und RX auf GPIO 17 versteht ich richtig?

Gerne...
Ja, das ist korrekt.

Hm… :thinking: irgendwie funktioniert es nicht. Sketch ist drauf, startet soweit aber kommen keine Werte. Solle eventuell in config.h auch was geändert werden (was ich aber nicht glaube) oder nicht?
So ist mein Code:

#include <Arduino.h>
#include "Logger.h"
#include "SerialConsole.h"
#include "BMSModuleManager.h"
#include "SystemIO.h"
#include <esp32_can.h>

#define BMS_BAUD  612500
#define RX_BMS_PIN    16 
#define TX_BMS_PIN    17 
//#define BMS_BAUD  617647
//#define BMS_BAUD  608695

HardwareSerial BMS_Serial2(1); //define second serial port for Tesla BMS board

BMSModuleManager bms;
EEPROMSettings settings;
SerialConsole console;
uint32_t lastUpdate;

void loadSettings()
{
        Logger::console("Resetting to factory defaults");
        settings.version = EEPROM_VERSION;
        settings.checksum = 0;
        settings.canSpeed = 500000;
        settings.batteryID = 0x01; //in the future should be 0xFF to force it to ask for an address
        settings.OverVSetpoint = 4.1f;
        settings.UnderVSetpoint = 2.3f;
        settings.OverTSetpoint = 65.0f;
        settings.UnderTSetpoint = -10.0f;
        settings.balanceVoltage = 3.9f;
        settings.balanceHyst = 0.04f;
        settings.logLevel = 2;
        
    Logger::setLoglevel((Logger::LogLevel)settings.logLevel);
}

void initializeCAN()
{
    uint32_t id;
    CAN0.begin(settings.canSpeed);
    if (settings.batteryID < 0xF)
    {
        //Setup filter for direct access to our registered battery ID
        id = (0xBAul << 20) + (((uint32_t)settings.batteryID & 0xF) << 16);
        CAN0.setRXFilter(0, id, 0x1FFF0000ul, true);
        //Setup filter for request for all batteries to give summary data
        id = (0xBAul << 20) + (0xFul << 16);
        CAN0.setRXFilter(1, id, 0x1FFF0000ul, true);
    }
}

void setup() 
{
    delay(2000);  //just for easy debugging. It takes a few seconds for USB to come up properly on most OS's
    SERIALCONSOLE.begin(115200);
    SERIALCONSOLE.println("Starting up!");
    BMS_Serial2.begin(BMS_BAUD, SERIAL_8N1, RX_BMS_PIN, TX_BMS_PIN); //rx pin is 16, tx pin is 17

    SERIALCONSOLE.println("Started serial interface to BMS.");

    pinMode(13, INPUT);

    Serial.println("Load EEPROM");
    loadSettings();
    Serial.println("Initialize CAN");
    initializeCAN();
    Serial.println("System IO setup");
    //systemIO.setup();

    Serial.println("Init BMS board numbers");
    bms.renumberBoardIDs();

    //Logger::setLoglevel(Logger::Debug);

    lastUpdate = 0;

    Serial.println("BMS clear faults");
    bms.clearFaults();
    Serial.println("End of setup");
    Serial.println("Send ? line to get help. d to get detailed updates, p to get summary updates.");
    delay(1000);
}

void loop() 
{
    CAN_FRAME incoming;

    console.loop();

    if (millis() > (lastUpdate + 1000))
    {    
        lastUpdate = millis();
        bms.balanceCells();
        bms.getAllVoltTemp();
    }

    if (CAN0.available()) {
        CAN0.read(incoming);
        bms.processCANMsg(incoming);
    }
}

Und hier ist config.h

#pragma once

#include <Arduino.h>

extern HardwareSerial Serial2;

//Set to the proper port for your USB connection - SerialUSB on Due (Native) or Serial for Due (Programming) or Teensy
#define SERIALCONSOLE   Serial

//Define this to be the serial port the Tesla BMS modules are connected to.
//On the Due you need to use a USART port (Serial1, Serial2, Serial3) and update the call to serialSpecialInit if not Serial1
#define SERIAL  Serial2

#define REG_DEV_STATUS      0
#define REG_GPAI            1
#define REG_VCELL1          3
#define REG_VCELL2          5
#define REG_VCELL3          7
#define REG_VCELL4          9
#define REG_VCELL5          0xB
#define REG_VCELL6          0xD
#define REG_TEMPERATURE1    0xF
#define REG_TEMPERATURE2    0x11
#define REG_ALERT_STATUS    0x20
#define REG_FAULT_STATUS    0x21
#define REG_COV_FAULT       0x22
#define REG_CUV_FAULT       0x23
#define REG_ADC_CTRL        0x30
#define REG_IO_CTRL         0x31
#define REG_BAL_CTRL        0x32
#define REG_BAL_TIME        0x33
#define REG_ADC_CONV        0x34
#define REG_ADDR_CTRL       0x3B

#define MAX_MODULE_ADDR     0x3E

#define EEPROM_VERSION      0x10    //update any time EEPROM struct below is changed.
#define EEPROM_PAGE         0

#define DIN1                55
#define DIN2                54
#define DIN3                57
#define DIN4                56
#define DOUT4_H             2
#define DOUT4_L             3
#define DOUT3_H             4
#define DOUT3_L             5
#define DOUT2_H             6
#define DOUT2_L             7
#define DOUT1_H             8
#define DOUT1_L             9

typedef struct {
    uint8_t version;
    uint8_t checksum;
    uint32_t canSpeed;
    uint8_t batteryID;  //which battery ID should this board associate as on the CAN bus
    uint8_t logLevel;
    float OverVSetpoint;
    float UnderVSetpoint;
    float OverTSetpoint;
    float UnderTSetpoint;
    float balanceVoltage;
    float balanceHyst;
} EEPROMSettings;

Ok, sorry,...da ich die Hardware und auch MQTT nicht habe, kann ich leider nicht weiter helfen.

Guten Morgen,
hab’s endlich geschafft, jetzt bekomme ich die ganze Werte auf esp32. Nächste frage :joy::man_facepalming:: wie bekomme ich alle Daten jetzt in influxdb oder mqtt? :thinking:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.