{"id":25344562,"url":"https://github.com/bitmeal/esp32-modbus-tcp-coupler","last_synced_at":"2025-10-29T14:30:45.101Z","repository":{"id":56765549,"uuid":"381105173","full_name":"bitmeal/esp32-modbus-tcp-coupler","owner":"bitmeal","description":"Make an ESP32 act as a Modbus/TCP bus-coupler; exposing onboard digital and analog IO as a Modbus slave device","archived":false,"fork":false,"pushed_at":"2021-06-28T17:04:21.000Z","size":21,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-07-27T18:24:05.820Z","etag":null,"topics":["esp-idf","esp32","modbus","modbus-slave","modbus-tcp","modbus-tcp-slave"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitmeal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-28T17:03:23.000Z","updated_at":"2023-02-14T16:04:35.000Z","dependencies_parsed_at":"2022-08-16T02:10:46.492Z","dependency_job_id":null,"html_url":"https://github.com/bitmeal/esp32-modbus-tcp-coupler","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitmeal%2Fesp32-modbus-tcp-coupler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitmeal%2Fesp32-modbus-tcp-coupler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitmeal%2Fesp32-modbus-tcp-coupler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitmeal%2Fesp32-modbus-tcp-coupler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitmeal","download_url":"https://codeload.github.com/bitmeal/esp32-modbus-tcp-coupler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238834426,"owners_count":19538713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esp-idf","esp32","modbus","modbus-slave","modbus-tcp","modbus-tcp-slave"],"created_at":"2025-02-14T11:35:47.328Z","updated_at":"2025-10-29T14:30:44.739Z","avatar_url":"https://github.com/bitmeal.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esp32 modbus/tcp coupler\nTransform an ESP32 into a simple Modbus/TCP bus-coupler/IO-device. Use any GPIO as *coil* or *discrete input* with configurable pull resistor. Use up to 8 onboard ADC and two onboard DAC channels as analog IO from *input-* or *holding registers*. IOs are sampled in a fixed frequency realtime loop, with single digit microsecond jitter, and nano- to microseconds simultaneity of IO operations (see IO section below for details).\n\n## quick-start\n0. build \u0026 flash with ESP-IDF toolchain\n1. connect to serial console\n2. perform WiFi configuration using serial console\n3. *POST* an IO configuration to `http://\u003cesp32-ip-address\u003e/config`\n4. 🎉\n\n### example IO configuration\n```json\n{\n    \"pull\": \"down\",\n    \"discrete_in\": [14, 12],\n    \"coils\": [22, 23],\n    \"input_reg\": [35, 34],\n    \"holding_reg\": [25, 26]\n}\n```\nAll IOs are configured by using their GPIO Number! For *input registers* (ADC) and *holding registers* (DAC), be sure to select a pin that is connected to the internal DAC or one of the **ADC1** channels!\n\n*Pins will be checked for requested function and configuration will fail if unsupported.*\n\n\nAvailable configuration fields: ***array of GPIO numbers to use as*** ...\n* `pull`: enable pull resistors on digital inputs (`up`, `down`, *omit*)\n* `discrete_in`: [...] digital **in**puts\n* `coils`: [...] digital **out**puts\n* `input_reg`: [...] analog input channels for **ADC1**\n* `holding_reg`: [...] analog output channels\n\n## Modbus/TCP\n* Unit/Device `1`\n* Port `502`\n\n## IO info\n* All IOs/registers start at address 0\n* All \"register-IOs\" use one register (16 bits) each\n* IO data is read and written in a realtime loop with *100Hz*\n* Digital IO and analog out (DAC) are read and written within \u003c 2µs\n* Analog input timing: *see below*\n\n\n### input registers\n* 16 bit wide (`WORD`)\n* to be interpreted as unsigned integer value\n* payload data width 12 bits\n* raw ADC readings @ 11db internal attenuation\n\nAnalog input channels are sampled consecutively at *200kHz* in two DMA buffers holding 16 samples each. Under normal operation all channels should be sampled in order and the time difference between samples for different channels should be lower than `(\u003cchannel_count\u003e - 1)/200kHz` (`^= 35µs` @ 8 channels). Maximum age of analog readings should be lower than `2 * 16 / 200kHz ^= 160µs`.\n\n### holding registers\n* 16 bit wide (`WORD`)\n* only 8 bits of payload as **unsigned integer**\n* raw DAC output values (*0-255*)\n\n\n## building \u0026 optimization\nFor consistent and fast sample rates and least IO-loop-jitter, configure a high CPU clock and high RTOS tick rate. A `sdkconfig.defaults` is provided and should set the following parameters accordingly:\n```ini\n#sdkconfig.defaults\n\nCONFIG_ESP32_DEFAULT_CPU_FREQ_240=y\nCONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240\n\nCONFIG_FREERTOS_HZ=1000\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitmeal%2Fesp32-modbus-tcp-coupler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitmeal%2Fesp32-modbus-tcp-coupler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitmeal%2Fesp32-modbus-tcp-coupler/lists"}