Skip to content

Commit 1841474

Browse files
committed
Change examples to work with new API
1 parent 9f083b9 commit 1841474

File tree

11 files changed

+56
-23
lines changed

11 files changed

+56
-23
lines changed

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ This README is under development, for now, see the examples of the library.
6363

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

examples/TestAnalogInput/TestAnalogInput.ino

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
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

813
#include <ESP8266WiFi.h>
9-
#include <Modbus.h>
1014
#include <ModbusIP_ESP8266.h>
1115

1216
//Modbus Registers Offsets (0-9999)
@@ -18,21 +22,20 @@ ModbusIP mb;
1822
long ts;
1923

2024
void setup() {
21-
Serial.begin(115200);
25+
Serial.begin(74880);
2226

23-
//Config Modbus IP
24-
mb.config("your_ssid", "your_password");
25-
27+
WiFi.begin("your_ssid", "your_password");
2628
while (WiFi.status() != WL_CONNECTED) {
2729
delay(500);
2830
Serial.print(".");
2931
}
30-
32+
3133
Serial.println("");
3234
Serial.println("WiFi connected");
3335
Serial.println("IP address: ");
3436
Serial.println(WiFi.localIP());
3537

38+
mb.begin(); //Sart Modbus IP
3639
// Add SENSOR_IREG register - Use addIreg() for analog Inputs
3740
mb.addIreg(SENSOR_IREG);
3841

examples/TestHoldingReg/TestHoldingReg.ino

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
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

914
#include <ESP8266WiFi.h>
10-
#include <Modbus.h>
1115
#include <ModbusIP_ESP8266.h>
1216

1317
// Modbus Registers Offsets (0-9999)
@@ -18,9 +22,9 @@ const int TEST_HREG = 100;
1822
ModbusIP mb;
1923

2024
void setup() {
21-
Serial.begin(115200);
25+
Serial.begin(74880);
2226

23-
mb.config("your_ssid", "your_password");
27+
WiFi.begin("your_ssid", "your_password");
2428

2529
while (WiFi.status() != WL_CONNECTED) {
2630
delay(500);
@@ -32,6 +36,7 @@ void setup() {
3236
Serial.println("IP address: ");
3337
Serial.println(WiFi.localIP());
3438

39+
mb.begin();
3540
mb.addHreg(TEST_HREG, 0xABCD);
3641
}
3742

examples/TestLed/TestLed.ino

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
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

813
#include <ESP8266WiFi.h>
9-
#include <Modbus.h>
1014
#include <ModbusIP_ESP8266.h>
1115

1216
//Modbus Registers Offsets (0-9999)
@@ -18,9 +22,9 @@ const int ledPin = 0; //GPIO0
1822
ModbusIP mb;
1923

2024
void setup() {
21-
Serial.begin(115200);
25+
Serial.begin(74880);
2226

23-
mb.config("your_ssid", "your_password");
27+
WiFi.begin("your_ssid", "your_password");
2428

2529
while (WiFi.status() != WL_CONNECTED) {
2630
delay(500);
@@ -32,6 +36,8 @@ void setup() {
3236
Serial.println("IP address: ");
3337
Serial.println(WiFi.localIP());
3438

39+
mb.begin();
40+
3541
pinMode(ledPin, OUTPUT);
3642
mb.addCoil(LED_COIL);
3743
}

examples/TestSwitchStatus/TestSwitchStatus.ino

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
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

813
#include <ESP8266WiFi.h>
9-
#include <Modbus.h>
1014
#include <ModbusIP_ESP8266.h>
1115

1216
//Modbus Registers Offsets (0-9999)
@@ -18,8 +22,14 @@ const int switchPin = 0; //GPIO0
1822
ModbusIP mb;
1923

2024
void setup() {
25+
26+
WiFi.begin("your_ssid", "your_password");
27+
while (WiFi.status() != WL_CONNECTED) {
28+
delay(500);
29+
Serial.print(".");
30+
}
2131
//Config Modbus IP
22-
mb.config("your_ssid", "your_password");
32+
mb.begin();
2333
//Set ledPin mode
2434
pinMode(switchPin, INPUT);
2535
// 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)

src/Modbus.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
2-
Modbus.cpp - Source for Modbus Base Library
2+
Modbus.h - Header for Modbus Base Library
33
Copyright (C) 2014 André Sarmento Barbosa
4+
2017 Alexander Emelianov ([email protected])
45
*/
56
#include "Modbus.h"
67

@@ -197,7 +198,7 @@ void Modbus::readRegisters(uint16_t startreg, uint16_t numregs) {
197198

198199
//Check Address
199200
//*** See comments on readCoils method.
200-
if (!this->searchRegister(startreg + 40001)) {
201+
if (!this->searchRegister(startreg + HREG_BASE)) {
201202
this->exceptionResponse(MB_FC_READ_REGS, MB_EX_ILLEGAL_ADDRESS);
202203
return;
203204
}
@@ -261,7 +262,7 @@ void Modbus::writeMultipleRegisters(byte* frame,uint16_t startreg, uint16_t numo
261262

262263
//Check Address (startreg...startreg + numregs)
263264
for (int k = 0; k < numoutputs; k++) {
264-
if (!this->searchRegister(startreg + 40001 + k)) {
265+
if (!this->searchRegister(startreg + HREG_BASE + k)) {
265266
this->exceptionResponse(MB_FC_WRITE_REGS, MB_EX_ILLEGAL_ADDRESS);
266267
return;
267268
}

src/Modbus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
Modbus.h - Header for Modbus Base Library
33
Copyright (C) 2014 André Sarmento Barbosa
4+
2017 Alexander Emelianov ([email protected])
45
*/
56
#include "Arduino.h"
67

src/ModbusIP_ESP8266.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
2-
ModbusIP_ESP8266.cpp - Source for Modbus IP ESP8266 Library
3-
Copyright (C) 2015 André Sarmento Barbosa
2+
Modbus.h - Header for Modbus Base Library
3+
Copyright (C) 2014 André Sarmento Barbosa
4+
2017 Alexander Emelianov ([email protected])
45
*/
56
#include "ModbusIP_ESP8266.h"
67

0 commit comments

Comments
 (0)