Siemens sentron pac3100 modbus

//MERHABA ARKADAŞLAR SIEMENS SENTRON PAC3100 MODBUS HABERLEŞMESİNİ SAĞLADIM https://www.youtube.com/shorts/2MwrhZhBr8U

#include <SPI.h>

#include <Ethernet.h>

#include <ModbusMaster.h>

#include <SoftwareSerial.h>

// Ethernet ayarları

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress ip(192, 168, 0, 10);

EthernetServer server(80);

// Modbus ayarları

const uint8_t slaveAddress = 1;

#define RX_PIN 8

#define TX_PIN 9

ModbusMaster node;

SoftwareSerial modbusSerial(RX_PIN, TX_PIN);

// Register adresleri ve isimleri

const uint16_t registerAddresses[] = {0x0001, 0x0003, 0x0005, 0x0007, 0x0009, 0x000B};

const char* registerNames[] = {"Gerilim a-n", "Gerilim b-n", "Gerilim c-n", "Gerilim a-b", "Gerilim a-c", "Gerilim b-c"};

float voltages[6];

void setup() {

Serial.begin(9600);

modbusSerial.begin(9600);

node.begin(slaveAddress, modbusSerial);

// Ethernet başlat

Ethernet.begin(mac, ip);

server.begin();

Serial.println("Server is ready at 192.168.0.10");

}

void loop() {

// Ethernet istemcisi ile bağlantıyı kabul et

EthernetClient client = server.available();

if (client) {

// Voltajları oku

for (int i = 0; i < 6; i++) {

  readVoltage(registerAddresses[i], &voltages[i]);

}


// HTTP başlığını gönder

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html; charset=UTF-8");

client.println("Connection: close");

client.println();


// HTML sayfasını oluştur

client.println("<!DOCTYPE html>");

client.println("<html lang='tr'>");

client.println("<head><title>Gerilim Okumaları</title>");

client.println("<meta http-equiv='refresh' content='5'>"); // 5 saniyede bir sayfayı yenile

client.println("<style>");

client.println("body { font-family: Arial, sans-serif; background-color: #f4f4f4; color: #333; text-align: center; padding: 50px; }");

client.println("h1 { color: #5A9; }");

client.println(".voltage { background-color: #fff; padding: 20px; margin: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); }");

client.println("</style>");

client.println("</head>");

client.println("<body>");

client.println("<h1>Gerilim Okumaları</h1>");


// Voltaj değerlerini alt alta göster

for (int i = 0; i < 6; i++) {

  client.print("<div class='voltage'><strong>");

  client.print(registerNames[i]);

  client.print(":</strong> ");

  client.print(voltages[i], 6);

  client.println(" V</div>");

}


client.println("</body>");

client.println("</html>");



delay(10); // Veriyi göndermek için zaman tanı



// İstemciyi kapat

client.stop();

}

}

void readVoltage(uint16_t address, float *voltage) {

uint8_t result;

uint16_t raw[2];

uint32_t combined;

result = node.readHoldingRegisters(address, 2);

if (result == node.ku8MBSuccess) {

raw[0] = node.getResponseBuffer(0);

raw[1] = node.getResponseBuffer(1);


combined = ((uint32_t)raw[0] << 16) | raw[1];

float *value = (float*)&combined;

*voltage = *value;

} else {

*voltage = NAN;

}

}

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

Please edit your post, select all code and click the <CODE/> button; next save your post. This will apply so called code tags to your code which makes the code easier to read and easier to copy; the forum software will also display it correctly. See How to get the best out of this forum.


Is there a question?

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