Coder Social home page Coder Social logo

yuzi40277738 / arduino-modbus-rtu-tcp-gateway Goto Github PK

View Code? Open in Web Editor NEW

This project forked from budulinek/arduino-modbus-rtu-tcp-gateway

0.0 1.0 0.0 1.62 MB

Arduino-based Modbus RTU to Modbus TCP/UDP gateway with web interface. Allows you to connect Modbus RTU slaves (such as sensors, energy meters, HVAC devices) to Modbus TCP/UDP masters (such as home automation systems). You can adjust settings through web interface.

License: GNU General Public License v3.0

C++ 100.00%

arduino-modbus-rtu-tcp-gateway's Introduction

arduino-modbus-rtu-tcp-gateway

Arduino-based Modbus RTU to Modbus TCP/UDP gateway with web interface. Allows you to connect Modbus RTU slaves (such as sensors, energy meters, HVAC devices) to Modbus TCP/UDP masters (such as home automation systems). You can adjust settings through web interface.

What is it good for?

Allows you to connect your Modbus RTU slaves (such as sensors, energy meters, HVAC devices) to Modbus TCP/UDP masters (such as monitoring systems, home automation systems). You do not need commercial Modbus gateways. Arduino (with an ethernet shield and a cheap MAX485 module) can do the job!

Change settings of your Arduino-based Modbus RTU to Modbus TCP/UDP gateway via web interface (settings are automatically stored in EEPROM).

Screenshots of the web interface:

01

02

03

04

05

What are the technical specifications?

  • slaves are connected via RS485 interface
  • master(s) are connected via ethernet interface
  • up to 247 Modbus RTU slaves
  • up to 8 TCP/UDP sockets for Modbus TCP/UDP masters and for the web interface
  • RS485 interface protocols:
    • Modbus RTU
  • Ethernet interface protocols:
    • Modbus TCP
    • Modbus UDP
    • Modbus RTU over TCP
    • Modbus RTU over UDP
  • supports broadcast (slave address 0x00) and error codes
  • supports all Modbus function codes
  • settings can be changed via web interface, stored in EEPROM
  • diagnostics and Modbus RTU scan via web interface
  • optimized queue for Modbus requests
    • prioritization of requests to responding slaves
    • queue will accept only one requests to non-responding slaves

How can I build it myself?

Get the hardware (cheap clones from China are sufficient) and connect together:

  • Arduino Nano, Uno or Mega (and possibly other). On Mega you have to configure Serial in ADVANCED SETTINGS in the sketch.
  • W5100, W5200 or W5500 based Ethernet shield (for Nano, I recommend W5500 Ethernet Shield from RobotDyn)
  • TTL to RS485 module:
    • with hardware automatic flow control (recommended)
      Arduino <-> Module
      Tx1 <-> Tx
      Rx0 <-> Rx
    • with flow controlled by pin (such as MAX485 module)
      Arduino <-> MAX485
      Tx1 <-> DI
      Rx0 <-> RO
      Pin 6 <-> DE,RE

Here is my setup: Terminal shield + Arduino Nano + W5500 eth shield (RobotDyn) + TTL to RS485 module (HW automatic flow control) 01

Download this repository (all *.ino files) and open arduino-modbus-rtu-tcp-gateway.ino in Arduino IDE. Download all required libraries (both are available in "library manager"). If you want, you can check the default factory settings (can be later changed via web interface) and advanced settings (can only be changed in sketch). Compile and upload your program to Arduino. Connect your Arduino to ethernet, connect your Modbus RTU slaves to MAX485 module. Use your web browser to access the web interface on default IP http://192.168.1.254 Enjoy :-)

Where can I learn more about Modbus protocols?

https://en.wikipedia.org/wiki/Modbus

https://modbus.org/specs.php

http://www.simplymodbus.ca/FAQ.htm

Can I use just the web interface for my own project?

Feel free to use this sketch as a template for a web interface within your own project. Look into the main file (arduino-modbus-rtu-tcp-gateway.ino) for how settings are stored in and loaded from EEPROM during boot. Ethernet interface and Webserver is started via function in 01-interfaces.ino. All other functions related to the web server (reading from clients, sending pages to clients) can be found in separate files (04-webserver.ino , 05-pages.ino ). Feel free to adjust them.

The key to success is:

Big thanks to the authors of these libraries and tutorials!

Limitations

Portability

The code was tested on Arduino Nano, Uno and Mega, ethernet chips W5100 and W5500. It may work on other platforms, but:

Ethernet socket

The default Ethernet.h library determines MAX_SOCK_NUM by microcontroller RAM (not by Ethernet chip type). So if you use W5500 (which has 8 sockets available) on Arduino Nano, only 4 sockets will be used. If you want to force the library to use 8 sockets, redefine MAX_SOCK_NUM in advanced settings in the sketch.

Memory

Not everything could fit into the limited flash memory of Arduino Nano / Uno. If you have a microcontroller with more memory (such as Mega), you can enable extra features in the main sketch by uncommenting:

  • #define ENABLE_DHCP will allow you to set "Auto IP" via DHCP in the IP settings web interface. Leased IP is automatically renewed.

06

  • #define ENABLE_EXTRA_DIAG shows extra info on "Current status" page: per socket diagnostics, run time counter.

01x

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.