Skip to content

maxx-ukoo/esp32-modbus-tcp2rtu

Repository files navigation

ESP32 IOT Module

Features

  • Ethernet support
  • Web UI for configuration based on React 16 with Bootstrap
  • TCP to RTU transparent mode
  • OTA Update
  • MQTT client (control GPIO pins)

Hardware

This firmware can be run on any ESP32 board with LAN8720 Ethernet PHY. Tested on my EtherESP board. This board fully compatible with wESP32 board

Status

These functions tested:

  • Modbus gateway - read input register, read holding registers
  • OTA update

Build

This library request patch to esp-idf

 components/freemodbus/common/include/esp_modbus_common.h | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/components/freemodbus/common/include/esp_modbus_common.h b/components/freemodbus/common/include/esp_modbus_common.h
index cd171c755..ea2da148c 100644
--- a/components/freemodbus/common/include/esp_modbus_common.h
+++ b/components/freemodbus/common/include/esp_modbus_common.h
@@ -30,29 +30,29 @@
 
 // The Macros below handle the endianness while transfer N byte data into buffer
 #define _XFER_4_RD(dst, src) { \
-    *(uint8_t *)(dst)++ = *(uint8_t*)(src + 1); \
     *(uint8_t *)(dst)++ = *(uint8_t*)(src + 0); \
-    *(uint8_t *)(dst)++ = *(uint8_t*)(src + 3); \
+    *(uint8_t *)(dst)++ = *(uint8_t*)(src + 1); \
     *(uint8_t *)(dst)++ = *(uint8_t*)(src + 2); \
+    *(uint8_t *)(dst)++ = *(uint8_t*)(src + 3); \
     (src) += 4; \
 }
 
 #define _XFER_2_RD(dst, src) { \
-    *(uint8_t *)(dst)++ = *(uint8_t *)(src + 1); \
     *(uint8_t *)(dst)++ = *(uint8_t *)(src + 0); \
+    *(uint8_t *)(dst)++ = *(uint8_t *)(src + 1); \
     (src) += 2; \
 }
 
 #define _XFER_4_WR(dst, src) { \
-    *(uint8_t *)(dst + 1) = *(uint8_t *)(src)++; \
     *(uint8_t *)(dst + 0) = *(uint8_t *)(src)++; \
-    *(uint8_t *)(dst + 3) = *(uint8_t *)(src)++; \
-    *(uint8_t *)(dst + 2) = *(uint8_t *)(src)++ ; \
+    *(uint8_t *)(dst + 1) = *(uint8_t *)(src)++; \
+    *(uint8_t *)(dst + 2) = *(uint8_t *)(src)++; \
+    *(uint8_t *)(dst + 3) = *(uint8_t *)(src)++ ; \
 }
 
 #define _XFER_2_WR(dst, src) { \
-    *(uint8_t *)(dst + 1) = *(uint8_t *)(src)++; \
     *(uint8_t *)(dst + 0) = *(uint8_t *)(src)++; \
+    *(uint8_t *)(dst + 1) = *(uint8_t *)(src)++; \
 }
 
 /**

Build

  1. Prepare environment - https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html
  2. Firmware build
idf.py build
idf.py -p COMX flash
  1. UI build
cd front
npm start build

Debug usage

Set state

TOPIC: /HOST/gpio/command { "pin": 23, "state": 5 }

Get state

/api/gpio/state?pin=23

Upload file via CURL

curl -k -vvv -F upload=@/mnt/d/Projects/wesp32/esp32-modbus-tcp2rtu/front/dist/main.test.gz https://192.168.0.42/ota/upload/file

Links

Setup webapp Bootstrap IEEE754 converter OTA ESP32 pins reference

Copyright (C) 2019 Maksym Krasovskyi

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published