Hallo,
ich will ein Smartmeter auslesen (Netzbezug, Netzeinspeisung), ich kann ihn per Android-App über IP (192, 168, 178, 78), Port (502) und ID (73) erreichen und abfragen. Ich finde für einen NodeMCU (esp8266) aber kein passendes Beispiel womit ich das Smartmeter erreichen kann.
Hat vielleicht jemand eine Bibliothek und ein Beispiel, womit das geht?
Ich möchte die folgenden Register auslesen:
Übersicht Interne Momentanwert Register
Start End Start End
address address address address Size R/W Function codes Type Units OBIS-Code Description
(dec) (dec) (hex) (hex)
0 1 0x0000 0x0001 2 RO 0x03 uint32 0.1 W 1-0:1.4.0*255 Active power+
2 3 0x0002 0x0003 2 RO 0x03 uint32 0.1 W 1-0:2.4.0*255 Active power-
Ich habe das folgende versucht, bekomme aber keine Daten ausgelesen:
/*
Board: NodeMCU 1.0 (ESP-12E)
*/
#include <ESP8266WiFi.h>
#include <ModbusIP_ESP8266.h>
const int REG = 0; // Modbus Hreg Offset
IPAddress remote(192, 168, 178, 78); // Address of Modbus Slave device
ModbusIP mb; //ModbusIP object
uint16_t res = 0;
#ifndef STASSID
#define STASSID "Cudy"
#define STAPSK "12345678"
#endif
const char* ssid = STASSID; // your network SSID (name)
const char* pass = STAPSK; // your network password
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();
mb.client();
// We start by connecting to a WiFi network
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
if (mb.isConnected(remote)) { // Check if connection to Modbus Slave is established
Serial.println("modbus is connected");
//mb.readHreg(remote, REG, &res); // Initiate Read Coil from Modbus Slave
mb.readIreg(remote, 0, &res, 1, 0, 73);
Serial.println(res);
mb.readIreg(remote, 2, &res, 1, 0, 73);
Serial.println(res);
mb.readIreg(remote, 4, &res, 2, 0, 73);
Serial.println(res);
} else {
Serial.println("modbus not connected");
mb.connect(remote); // Try to connect if no connection
}
mb.task(); // Common local Modbus task
delay(5000);
}
