Coder Social home page Coder Social logo

andresarmento / modbus-esp8266 Goto Github PK

View Code? Open in Web Editor NEW
142.0 30.0 230.0 105 KB

A library that allows your ESP8266 to communicate via Modbus protocol, acting as a slave (master in development). Supports IP via wireless network (Modbus IP).

License: BSD 3-Clause "New" or "Revised" License

C++ 84.27% Arduino 15.73%

modbus-esp8266's Introduction

Modbus Library for ESP8266

This library allows your ESP8266 to communicate via Modbus protocol. The Modbus is a master-slave protocol used in industrial automation and can be used in other areas, such as home automation.

The Modbus generally uses serial RS-232 or RS-485 as physical layer (then called Modbus Serial) and TCP/IP via Ethernet or WiFi (Modbus IP).

In the current version the library allows the ESP8266 operate as a slave, supporting Modbus IP via wireless network. For more information about Modbus see:

http://pt.wikipedia.org/wiki/Modbus http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf http://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf

Features

  • Operates as a slave
  • Supports Modbus IP (TCP, not keep-alive)
  • Reply exception messages for all supported functions
  • Modbus functions supported:
    • 0x01 - Read Coils
    • 0x02 - Read Input Status (Read Discrete Inputs)
    • 0x03 - Read Holding Registers
    • 0x04 - Read Input Registers
    • 0x05 - Write Single Coil
    • 0x06 - Write Single Register
    • 0x0F - Write Multiple Coils
    • 0x10 - Write Multiple Registers

Notes:

  1. When using Modbus IP the transport protocol is TCP (port 502) and the connection is terminated to each transmitted message, that is, is not a keep-alive type connection.

  2. The offsets for registers are 0-based. So be careful when setting your supervisory system or your testing software. For example, in ScadaBR (http://www.scadabr.com.br) offsets are 0-based, then, a register configured as 100 in the library is set to 100 in ScadaBR. On the other hand, in the CAS Modbus Scanner (http://www.chipkin.com/products/software/modbus-software/cas-modbus-scanner/) offsets are 1-based, so a register configured as 100 in library should be 101 in this software.

  3. Early in the library Modbus.h file there is an option to limit the operation to the functions of Holding Registers, saving space in the program memory. Just comment out the following line:

#define USE_HOLDING_REGISTERS_ONLY

Thus, only the following functions are supported:

  • 0x03 - Read Holding Registers
  • 0x06 - Write Single Register
  • 0x10 - Write Multiple Registers

How to

This README is under development, for now, see the examples of the library.

Contributions

http://github.com/andresarmento/modbus-esp8266
prof (at) andresarmento (dot) com

License

The code in this repo is licensed under the BSD New License. See LICENSE.txt for more info.

modbus-esp8266's People

Contributors

andresarmento avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

modbus-esp8266's Issues

can't use slave ID with TCP Client?

Hi there, thanks for this library. I have got the example going on my ESP32 for modbus TCP client and I can read and write registers from my PC using modbus TCP query program from SimplyModbus. However, the client (ESP32) behaves the same no matter what I set the modbus slave ID to - it doesn't seem to pay any attention to that number.

In this application I'm working on I need to be able to respond differently depending on which slave ID the query is sent to. Is there a way to check ID for an incoming request?

Thanks for any thoughts.

Reset many times

i program the esp8266 esp-07 but it resets many times and randomly! the node mcu board works about 117 hours but the esp-07 works about 23 hours and then it resets what is the problem?????

Works well but need to be disconnected and reconnected

Hi
Thanks for your library. I tested with NODEMCU DEVKIT 1 and arduino 1.6.5. CAS Modbus scanner on PC. I tried the holding register example. I find that the after each poll by CAS I have to disconnect and reconnect else CAS shows no response from device after the 1st read.

TCP server port

Hello. I having a problem where I want to read holding registers from modbus tcp (as modbus master) but it failed. This is because the example code didn't provide server port. I want to use this address 192.168.0.1:8899 to read but it failed because the code defined as 192.168.0.1. I used IP-Client-SimpleRead.ino

Modbus serial on ESP8266

Hi,
Thanks a lot for this lib. I'm trying to use modbus serial on a ESP8266 but I'm not sure what to do, do I need to take ModbusSerial lib from modbus-arduino (there is none on esp8266 lib) and Modbus library from modbus-esp8266, is that correct ?

Issues with Input address 7 reading correct value.

Having issues with reading the correct value on mb.Ists(7, 1);. Reading a zero and not a 1.

/****************************************************/
// Address 1 on the PLC is Address 0 on the ESP8266
for (index1 = 0; index1 < 32; index1++)
{
mb.addIsts(index1);
}

void loop() {
//Call once inside loop() - all magic here
mb.task();
if (millis() > timer0 + 2000) {
timer0 = millis();
mb.Ists(0, 1);

   mb.Ists(3, 1);

   mb.Ists(5, 1);

   mb.Ists(6, 1);

   mb.Ists(7, 1);

   mb.Ists(8, 1);


  }  

Regarding ESP8266WiFi.h

Greetings,

On Arduino version 1.6.9, I manage to install ModbusIP library and compile provided examples.

I would like to implement modbus_esp8266.
Unfortunately I have faced some issues.
When I try installing modbus-esp8266 via >Sketch>Include Library>add. ZIP library, Arduino ide complains with the followings:

Arduino: 1.6.9 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"
Specified folder/zip file does not contain a valid library

What can be possible reason of this error message?

Regards,

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.