0

I'm trying to read data from Makel M600 model meter with ESP32. I use RS485 and IEC 62056-21. I send command to get device identification but serial monitor prints unreadable characters. Here is the my full code:

#include <WiFi.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(16,17);  // RX, TX pins

const char* ssid = "--";
const char* password = "--";


void setup() {
  Serial.begin(9600);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());


  delay(1000);
  Serial.begin(9600);
  mySerial.begin(9600);

  // Cihaz kimliği sorgusu gönderme
  mySerial.println("/?!<CR><LF>");
}

void loop() {
  if (mySerial.available()) {
    String response = mySerial.readStringUntil('\n');
    Serial.println("Received: " + response);

    // Baud hızı değişikliği isteği gönderme
    if (response.startsWith("/SAT")) {
      mySerial.println("[DATA]050<CR><LF>");
    }

    // Aktif tüketim sorgusu gönderme
    if (response.startsWith("/SAT")) {
      mySerial.print("[SOH]R2[STX]1.8.0()[ETX][BCC]");
    }
  }
}

And here is the output:

14:56:18.453 -> �z����....
14:56:20.577 -> WiFi connected
14:56:20.577 -> IP address: **********
14:56:22.608 -> Received: ������

I'm new with it so I hope you can help me.

I tried to use HardwareSerial but it didn't work. I tried to convert it to string, change pins, and different codes but it's not working. Serial monitor still prints unreadable characters.

  • 1
    Do you have the user manual of the meter where it describe the protocol it use? Are you sure it return ASCII or String? Not binary? – hcheung Aug 21 '23 at 13:44
  • Where did the first line of output containing the periods `....` come from? I don't do ESP32 stuff, but what you're sending to the meter looks like text copied *verbatim* from a document that describes the protocol rather than strings that conform to the programming language. E.G. `"[DATA]050"` and `"[SOH]R2[STX]1.8.0()[ETX][BCC]"`. IOW the strings containing `` or `[SOH]` are probably not going to produce the ASCII codes or byte values that you want/need. – sawdust Aug 22 '23 at 03:14
  • You should also make sure that the baud rate you are using (9600) is the same value that the Makel M600 model meter is using. – Matias B Aug 22 '23 at 17:51

0 Answers0