Connection from xiao esp32-C3 to s2100 via modbus

I am trying to send data (test integer) to S2100 and received on LoRa

This is program :

/*  ESP32-C3 -> RS485 (MAX3485/MAX485) XIAO_RS485_Expansion_Board
    https://files.seeedstudio.com/wiki/rs485_ExpansionBoard/Seeed_Studio_XIAO_RS485_Expansion_Board.pdf
    — RS485 DI  <- ESP32C3 TX 
    — RS485 RO  -> ESP32C3 RX
    — RS485 DE+RE -> ESP32C3 TXEN (SAME GPIO)
    Alim: 3V3/5V.

    Protocol: Modbus RTU SLAVE
    Address slave: 1
    Baud: 9600 8N1
    Register Holding 0x0000 : integer no sign 0..100
*/

#include <ModbusRTU.h>

#define RS485_TX_PIN   4   // (XIAO ESP32-C3: D4)
#define RS485_RX_PIN   5   // (XIAO ESP32-C3: D5)
#define RS485_TXEN_PIN 2   // DE/RE same GPIO D2

// id Modbus
static const uint8_t SLAVE_ID = 1;
static const uint32_t BAUD = 9600;

// Registers
static const uint16_t HREG_BIKE_COUNT = 0x0000;  // value 0..100

HardwareSerial RS485(1);
ModbusRTU mb;

// value from to 0..100
uint16_t clamp100(int v) {
  if (v < 0) return 0;
  if (v > 100) return 100;
  return (uint16_t)v;
}

void setup() {
  Serial.begin(115200);
  delay(500);
  pinMode(RS485_TXEN_PIN, OUTPUT);
  digitalWrite(RS485_TXEN_PIN, LOW);

  RS485.begin(BAUD, SERIAL_8N1, RS485_RX_PIN, RS485_TX_PIN);

  mb.begin(&RS485, RS485_TXEN_PIN); // control DE/RE auto
  mb.setBaudrate(BAUD);
  mb.slave(SLAVE_ID);

  // define (Holding Register) 0x0000 with initiale value 0
  mb.addHreg(HREG_BIKE_COUNT, 0);

  Serial.println(F("Modbus RTU slave ready."));
  Serial.println(F("the S2100 (master RS485) must read HREG 0x0000 (fonction 03)."));
}

void loop() {
  // Service Modbus (response to S2100's queries )
  mb.task();
  int v = random(100);
  uint16_t bounded = clamp100(v);
  mb.Hreg(HREG_BIKE_COUNT, bounded);
  Serial.print(F("New value (0..100) = "));
  Serial.println(bounded);
  delay(60*1000);
}

The S2100 config follow

This the decoder javascript :slight_smile:

function decodeUplink(input) {
  let bytes = input.bytes;
  let data = {};

  // Parcours du payload SenseCAP (peut contenir plusieurs channels)
  /*for (let i = 0; i < bytes.length;) {
    let channelId = (bytes[i] << 8) | bytes[i+1]; // 2 octets
    let dataType = bytes[i+2];                   // 1 octet
    i += 3;

    if (dataType === 0x02) { // Uint16
      let value = (bytes[i] << 8) | bytes[i+1];
      data["channel_" + channelId] = value;
      i += 2;
    } else {
      // type non supporté (skip ?)
      break;
    }
  }*/
  for (let i = 0; i < bytes.length;) {
    let channelId = (bytes[i] << 8) | bytes[i+1]; // 2 octets
    let dataType = bytes[i+2];                   // 1 octet
    i += 3;

    if (channelId === 0x1301) {
      let value = (bytes[i] << 8) | bytes[i+1]; // Uint16
      data["dataType"] = dataType;
      data.bike_count = value;
      i += 2;
    } else {
      // skip unsupported / unknown
      break;
    }
  }

Now this is the payload i am receiving : 1301000103 and not correct.

Is there is someone who can help me to solve this. Thanks