Skip to content

Commit a236934

Browse files
committed
Misc
2 parents 508bfe1 + 34b7530 commit a236934

File tree

14 files changed

+165
-140
lines changed

14 files changed

+165
-140
lines changed

.gitmodules

Whitespace-only changes.

LICENSE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Copyright (c) 2015, Andr� Sarmento Barbosa
2+
2017, Alexander Emelianov ([email protected])
23
All rights reserved.
34

5+
46
Redistribution and use in source and binary forms, with or without modification,
57
are permitted provided that the following conditions are met:
68

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
Modbus Library for ESP8266
2-
==========================
1+
# Modbus Library for ESP8266/ESP32
32

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

76
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).
@@ -11,12 +10,13 @@ In the current version the library allows the ESP8266 operate as a slave, suppor
1110
http://pt.wikipedia.org/wiki/Modbus http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf
1211
http://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf
1312

14-
Features
15-
========
13+
## Features
14+
15+
Keep alive and ESP32 support added to original library. This features is under testing.
1616

1717
<ul>
1818
<li>Operates as a slave</li>
19-
<li>Supports Modbus IP (TCP, not keep-alive)</li>
19+
<li>Supports Modbus IP (TCP)</li>
2020
<li>Reply exception messages for all supported functions</li>
2121
<li>Modbus functions supported:</li>
2222
<ul>
@@ -33,7 +33,7 @@ Features
3333

3434
<b>Notes:</b>
3535

36-
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.
36+
1. When using Modbus IP the transport protocol is TCP (port 502).
3737

3838
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)
3939
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
@@ -54,19 +54,23 @@ Thus, only the following functions are supported:
5454
</ul>
5555

5656

57-
How to
58-
======
57+
## How to
5958

6059
```
6160
This README is under development, for now, see the examples of the library.
6261
```
6362

64-
Contributions
65-
=============
63+
## Contributions
64+
65+
https://github.com/emelinov/modbus-esp8266
66+
67+
68+
69+
Original version:
6670
http://github.com/andresarmento/modbus-esp8266<br>
6771
prof (at) andresarmento (dot) com
6872

69-
License
70-
=======
73+
## License
74+
7175
The code in this repo is licensed under the BSD New License. See LICENSE.txt for more info.
7276

TODO.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/TestAnalogInput/TestAnalogInput.ino

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
/*
22
Modbus-Arduino Example - Test Holding Register (Modbus IP ESP8266)
33
Read Analog sensor on Pin ADC (ADC input between 0 ... 1V)
4+
Original library
45
Copyright by André Sarmento Barbosa
56
http://github.com/andresarmento/modbus-arduino
7+
8+
Current version
9+
(c)2017 Alexander Emelianov ([email protected])
10+
https://github.com/emelianov/modbus-esp8266
611
*/
712

8-
#include <ESP8266WiFi.h>
9-
#include <Modbus.h>
13+
#ifdef ESP8266
14+
#include <ESP8266WiFi.h>
15+
#else
16+
#include <WiFi.h>
17+
#endif
1018
#include <ModbusIP_ESP8266.h>
1119

1220
//Modbus Registers Offsets (0-9999)
@@ -18,21 +26,20 @@ ModbusIP mb;
1826
long ts;
1927

2028
void setup() {
21-
Serial.begin(115200);
29+
Serial.begin(74880);
2230

23-
//Config Modbus IP
24-
mb.config("your_ssid", "your_password");
25-
31+
WiFi.begin("your_ssid", "your_password");
2632
while (WiFi.status() != WL_CONNECTED) {
2733
delay(500);
2834
Serial.print(".");
2935
}
30-
36+
3137
Serial.println("");
3238
Serial.println("WiFi connected");
3339
Serial.println("IP address: ");
3440
Serial.println(WiFi.localIP());
3541

42+
mb.begin(); //Sart Modbus IP
3643
// Add SENSOR_IREG register - Use addIreg() for analog Inputs
3744
mb.addIreg(SENSOR_IREG);
3845

examples/TestHoldingReg/TestHoldingReg.ino

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22
Modbus-Arduino Example - Test Holding Register (Modbus IP ESP8266)
33
Configure Holding Register (offset 100) with initial value 0xABCD
44
You can get or set this holding register
5+
Original library
56
Copyright by André Sarmento Barbosa
67
http://github.com/andresarmento/modbus-arduino
8+
9+
Current version
10+
(c)2017 Alexander Emelianov ([email protected])
11+
https://github.com/emelianov/modbus-esp8266
712
*/
813

9-
#include <ESP8266WiFi.h>
10-
#include <Modbus.h>
14+
#ifdef ESP8266
15+
#include <ESP8266WiFi.h>
16+
#else
17+
#include <WiFi.h>
18+
#endif
1119
#include <ModbusIP_ESP8266.h>
1220

1321
// Modbus Registers Offsets (0-9999)
@@ -18,9 +26,9 @@ const int TEST_HREG = 100;
1826
ModbusIP mb;
1927

2028
void setup() {
21-
Serial.begin(115200);
29+
Serial.begin(74880);
2230

23-
mb.config("your_ssid", "your_password");
31+
WiFi.begin("your_ssid", "your_password");
2432

2533
while (WiFi.status() != WL_CONNECTED) {
2634
delay(500);
@@ -32,6 +40,7 @@ void setup() {
3240
Serial.println("IP address: ");
3341
Serial.println(WiFi.localIP());
3442

43+
mb.begin();
3544
mb.addHreg(TEST_HREG, 0xABCD);
3645
}
3746

examples/TestLed/TestLed.ino

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
/*
22
Modbus-Arduino Example - Test Led (Modbus IP ESP8266)
33
Control a Led on GPIO0 pin using Write Single Coil Modbus Function
4+
Original library
45
Copyright by André Sarmento Barbosa
56
http://github.com/andresarmento/modbus-arduino
7+
8+
Current version
9+
(c)2017 Alexander Emelianov ([email protected])
10+
https://github.com/emelianov/modbus-esp8266
611
*/
712

8-
#include <ESP8266WiFi.h>
9-
#include <Modbus.h>
13+
#ifdef ESP8266
14+
#include <ESP8266WiFi.h>
15+
#else
16+
#include <WiFi.h>
17+
#endif
1018
#include <ModbusIP_ESP8266.h>
1119

1220
//Modbus Registers Offsets (0-9999)
@@ -18,9 +26,9 @@ const int ledPin = 0; //GPIO0
1826
ModbusIP mb;
1927

2028
void setup() {
21-
Serial.begin(115200);
29+
Serial.begin(74880);
2230

23-
mb.config("your_ssid", "your_password");
31+
WiFi.begin("your_ssid", "your_password");
2432

2533
while (WiFi.status() != WL_CONNECTED) {
2634
delay(500);
@@ -32,6 +40,8 @@ void setup() {
3240
Serial.println("IP address: ");
3341
Serial.println(WiFi.localIP());
3442

43+
mb.begin();
44+
3545
pinMode(ledPin, OUTPUT);
3646
mb.addCoil(LED_COIL);
3747
}

examples/TestSwitchStatus/TestSwitchStatus.ino

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
/*
22
Modbus-Arduino Example - Test Holding Register (Modbus IP ESP8266)
33
Read Switch Status on pin GPIO0
4+
Original library
45
Copyright by André Sarmento Barbosa
56
http://github.com/andresarmento/modbus-arduino
7+
8+
Current version
9+
(c)2017 Alexander Emelianov ([email protected])
10+
https://github.com/emelianov/modbus-esp8266
611
*/
712

8-
#include <ESP8266WiFi.h>
9-
#include <Modbus.h>
13+
#ifdef ESP8266
14+
#include <ESP8266WiFi.h>
15+
#else
16+
#include <WiFi.h>
17+
#endif
1018
#include <ModbusIP_ESP8266.h>
1119

1220
//Modbus Registers Offsets (0-9999)
@@ -18,8 +26,14 @@ const int switchPin = 0; //GPIO0
1826
ModbusIP mb;
1927

2028
void setup() {
29+
30+
WiFi.begin("your_ssid", "your_password");
31+
while (WiFi.status() != WL_CONNECTED) {
32+
delay(500);
33+
Serial.print(".");
34+
}
2135
//Config Modbus IP
22-
mb.config("your_ssid", "your_password");
36+
mb.begin();
2337
//Set ledPin mode
2438
pinMode(switchPin, INPUT);
2539
// Add SWITCH_ISTS register - Use addIsts() for digital inputs

keywords.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ModbusIP KEYWORD1
55
ModbusIP_ESP8266 KEYWORD1
66

77
# Methods and Functions (KEYWORD2)
8-
config KEYWORD2
8+
begin KEYWORD2
99
task KEYWORD2
1010

1111
# Constants (LITERAL1)
@@ -14,7 +14,6 @@ task KEYWORD2
1414

1515
# Datatypes (KEYWORD1)
1616
Modbus KEYWORD1
17-
u_int KEYWORD1
1817
TRegister KEYWORD1
1918

2019
# Methods and Functions (KEYWORD2)

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ sentence=Modbus Library for ESP8266
66
paragraph=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.
77
category=Communication
88
url=https://github.com/emelianov/modbus-esp8266
9-
architectures=esp8266
9+
architectures=esp8266,esp32

0 commit comments

Comments
 (0)