forked from andresarmento/modbus-esp8266
-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathserver.ino
51 lines (40 loc) · 1.04 KB
/
server.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Modbus-Arduino Example - Test Holding Register (Modbus IP ESP8266)
Configure Holding Register (offset 100) with initial value 0xABCD
You can get or set this holding register
Original library
Copyright by André Sarmento Barbosa
http://github.com/andresarmento/modbus-arduino
Current version
(c)2017 Alexander Emelianov ([email protected])
https://github.com/emelianov/modbus-esp8266
*/
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else //ESP32
#include <WiFi.h>
#endif
#include <ModbusIP_ESP8266.h>
// Modbus Registers Offsets
const int TEST_HREG = 100;
//ModbusIP object
ModbusIP mb;
void setup() {
Serial.begin(115200);
WiFi.begin("your_ssid", "your_password");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
mb.server();
mb.addHreg(TEST_HREG, 0xABCD);
}
void loop() {
//Call once inside loop() - all magic here
mb.task();
delay(10);
}