Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef ESP8266
- #include <ESP8266WiFi.h>
- #else //ESP32
- #include <WiFi.h>
- #endif
- #include <ModbusIP_ESP8266.h>
- ModbusIP mb;
- int a1 = 0;
- int b1 = 0;
- void setup() {
- Serial.begin(9600);
- WiFi.begin("SSID", "PASS");//replace with WiFi name & 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(0); //input - i
- mb.addHreg(1); //color - a
- mb.addHreg(2); //enum/state - b
- }
- void loop() {
- mb.task();
- int a = mb.Hreg(1);
- if (a1 != a) {
- Serial.println(a);
- a1 = a;
- }
- int b = mb.Hreg(2);
- if (b != b1) {
- Serial.println(b + 10);
- if (b == 0) a1 = 0;
- b1 = b;
- }
- }
- void serialEvent() {
- while (Serial.available()) {
- int i = Serial.parseInt();
- if (Serial.read() == char(13)) {
- mb.Hreg(0, i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement