Trying to get data from sensor to Nodemcu

I am using a power meter connected to a Nodemcu through a Max485. I find difficulties on programming the Nodemcu to get the data from the sensor. I have try to use some testing software to directly send a request to the sensor from the computer and we could retrieved the correct output. But we cant get it from using the Nodemcu.
The code now we have is

#include <ModbusRTU.h>
ModbusRTU mb;
#include <SoftwareSerial.h>
SoftwareSerial mod;
#define DE 2 // For MAX485 chip
#define RE 6
#define TX 15 //     RX, TX 
#define RX 13
#define RS485receive LOW
#define RS485transmit HIGH
SoftwareSerial S(RX, TX); // (RX , TX)

void setup() {
  Serial.begin(9600);
  S.begin(9600, SWSERIAL_8N1);
  delay(1000);

}

float voltage;

void loop() {
  digitalWrite(RE, HIGH);    // init Transmit
  digitalWrite(DE, HIGH); 
  byte request[] = {0xD1, 0x03, 0x00, 0x0B, 0x00, 0x01, 0xE6, 0x58}; // inquiry frame
  S.write(request, sizeof(request));
  delay(100);
  S.flush();

  digitalWrite(DE, LOW);      // Init Receive
  digitalWrite(RE, LOW); 
  byte buf[16];
  S.readBytes(buf, 16);
 
  
  Serial.print("voltage : ");
  for( byte i=0; i<50; i++ ) {
  Serial.print(buf[i], HEX);
  Serial.print(" ");
  }
  
  Serial.print(" ==> ");
  Serial.print(buf[3]);
  Serial.print("V");
  Serial.println();                  
  delay(10000);
}

This is the result we get from the serial monitor

Check if the libraries are made for nodemcu.
What would a correct output look like?

So I should use a library that support the ESP8266 like the modbus-esp8266? The correct output should contains something similar to the RHS of this picture.

All libraries don't work for all controllers. Some will compile and some won't.
Of course You need to use libraries made for the controller You use.
Modbus or not is beyond my knowledge.

The problem has been solved. Seems we follow the wrong guide of connecting the wire. This site help us to solved all the stuff.
https://www.cybertice.com/article/451/%E0%B8%AA%E0%B8%AD%E0%B8%99%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-esp8266-%E0%B9%80%E0%B8%8B%E0%B9%87%E0%B8%99%E0%B9%80%E0%B8%8B%E0%B8%AD%E0%B8%A3%E0%B9%8C%E0%B8%A7%E0%B8%B1%E0%B8%94%E0%B8%AD%E0%B8%B8%E0%B8%93%E0%B8%AB%E0%B8%A0%E0%B8%B9%E0%B8%A1%E0%B8%B4%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%8A%E0%B8%B7%E0%B9%89%E0%B8%99-xy-md02-sht20-temperature-and-humidity-rs485

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