Reading an EV Motor canbus data

Hello All,

I am using an esp32 with an mcp2515 connected. I am using it to read the can bus data of the EV motor I have in my boat. I have it setup and semi-working, but…
The data can come in 2 forms, a byte for things like a 0 to 100 percent value ie state of charge, or a word format which is made up of 2 bytes. I am able to read the single 1 byte values but I am still stuck on the 2 byte word values.

canbus:
  - platform: mcp2515
    id: my_mcp2515
    spi_id: McpSpi
    cs_pin: GPIO15
    can_id: 4
    use_extended_id: false
    bit_rate: 250KBPS
    clock: 8MHZ #One of 8MHZ, 16MHZ or 20MHZ
    mode:  NORMAL #LISTENONLY #NORMAL # LOOPBACK
    on_frame:
    - can_id: 0x301 #[canbus:066]: received can message std can_id=0x301 size=8
      use_extended_id: false
      then:
      - lambda: |-
          int xSize = x.size();
          ESP_LOGD("xSize: ", "%d", xSize );
          
          if(x.size() > 0) {
            ESP_LOGD("main", "--------------------");
            ESP_LOGD("sent from motor 0x301 x [0]: ", "%d", x[0] ); //rpm
            ESP_LOGD("sent from motor 0x301 x [1]: ", "%d", x[1] ); //rpm
            ESP_LOGD("sent from motor 0x301 x [2]: ", "%d", x[2] ); //SoC
            ESP_LOGD("sent from motor 0x301 x [3]: ", "%d", x[3] ); //amps
            ESP_LOGD("sent from motor 0x301 x [4]: ", "%d", x[4] ); //amps
            ESP_LOGD("sent from motor 0x301 x [5]: ", "%d", x[5] ); //volts
            ESP_LOGD("sent from motor 0x301 x [6]: ", "%d", x[6] ); //volts
            ESP_LOGD("sent from motor 0x301 x [7]: ", "%d", x[7] ); //inverter temp
            
            //RPM
            // Convert both the integers to string
            std::string byte0 = to_string(x[0]);
            std::string byte1 = to_string(x[1]);
            std::string rpm_str = byte1 + byte0;
            // Convert the concatenated string to integer
            int rpm_int_tmp = atoi(rpm_str.c_str());
            int rpm_int = rpm_int_tmp / 10;
            //ESP_LOGD("newRPM: ", "%d", rpm_int);
            id(motor_rpm).publish_state(rpm_int);
            
            int propeller_int = rpm_int / 2.49;
            id(propeller_rpm).publish_state(propeller_int);

            //STATE OF CHARGE
            int soc = x[2];
            id(motor_battery_soc).publish_state(soc);
            //ESP_LOGD("soc: %d", soc);
         }

I have tried setting the data to char and string but when converting back to an int, I get the same values so I have stuck with %d.

the only think I can think of that might be causing these problems is the range column in the following image from the netgain hyper9 documents. using voltage as an example, in my configuration I get a 2 and 4, reversed this is 42 volts, BUT the controller and battery says its 96v (which is correct). So this range is not 0 to 100 it is a range.

Any thoughts?

How did you go with your config? What was the issue?

Looks to me like the code is set to read from CAN address 0x301, when it should be reading from 0x401 as it is configured in the screenshot from Tau