Elektroda.com
Elektroda.com
X
This content has been translated flag-pl » flag-en View the original version here.
  • TCP-IP / RS485 ESP8266 converter

    Simple TCPIP / RS485 converter.
    The device allows you to create a remote port rs232 / rs485 in linux and windows systems and allows communication with devices via lan / internet. The project is based on UARTtransparentbridge code, but MAX485 support has been added to it. ESP8266 programmed in ArduinoIDE, source code and "schematic" attached.
    On linux, after booting the device, just use 'socat':
    Code: text
    Log in, to see the code

    When this command is issued, a virtual UART will be created in / dev / espS0.

    Tested on the ORNO OR-WE-504 indicator.

    TCP-IP / RS485 ESP8266 converter

    Cool? Ranking DIY
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
    About Author
    dktr
    Level 23  
    Offline 
    dktr wrote 667 posts with rating 407, helped 34 times. Live in city OstrĂ³da. Been with us since 2003 year.
  • #2
    george2002

    Level 21  
    Is it something like esp-link? https://hackaday.io/page/1304-virtual-serial-port-tunnel-to-use-with-esp-link " target="_blank" rel="noopener nofollow ugc" title="http:// https://hackaday.io/page/1304-virtual-serial-port-tunnel-to-use-with-esp-link " class="postlink inline-block "> https://hackaday.io/page/1304-virtual-serial-port-tunnel-to-use-with-esp-link because esp-link has a lot of options, only the RS485 support is probably not implemented from what I read quickly :)
    How about stability? and it works at what speeds and whether they can be changed easily or the code needs to be uploaded to esp8266 to make it different :) ?
  • #3
    dktr
    Level 23  
    Yes, it will be the same as ESPlink, in 1200,2400,9600 it works fine but requires changes in the code - serial.begin () I have nothing else with rs485 except this orno indicator, I polled the counter all night every 1 sec and all the results are correct, not a single transmission error.
  • #4
    jajen
    Level 17  
    Does this converter work at 3.3v with esp? It shouldn't because they're at 5v.
  • #5
    levy^
    Level 17  
    it should work, but at much shorter distances
  • #6
    george2002

    Level 21  
    It is enough to replace it with the MAX3485 and everything in accordance with the art and ranges ;)
  • #7
    ditomek
    Level 22  
    On what basis do you calculate the time needed to control the RE / DE signal?
    Doesn't cut anything with longer thongs?
  • #8
    byrrt
    Level 21  
    Not supporting RS485 (DE signal) is not a problem:
    TCP-IP / RS485 ESP8266 converter
    Proven - works, also in many production devices.

    Added after 1 [minutes]:

    ditomek wrote:
    On what basis do you calculate the time needed to control the RE / DE signal?

    This is not calculated, only the DE signal leaves after leaving the last byte from the send buffer.
  • #9
    ditomek
    Level 22  
    on the first post, re_de is controlled from the ESP pin, so the diagram you pasted later does not make sense. By the way, I use a similar one myself in my projects.
    I am asking this because in arduino the time needed to control re_de is not as easy as it seems.
    in general Serial.print is backed up by the interrupt system and for longer strings the handling ends faster than actually sending the data.
    This means that since you have a short delay after print and re_de switch, the transmit direction will change to receive faster than the send buffer will be emptied. This is the case with the Atmega. I wonder what ESP is like, that's why I asked.
  • #10
    piterek-23
    Level 33  
    byrrt wrote:
    Not supporting RS485 (DE signal) is not a problem:
    TCP-IP / RS485 ESP8266 converter
    Proven - works, also in many production devices.

    And how to select elements when UART works at the 3V3 level?
    MAX485 to MAX3485, what about the rest?
  • #11
    byrrt
    Level 21  
    piterek-23 wrote:
    MAX485 to MAX3485, what about the rest?

    what about the rest? stays the same ...
  • #12
    piterek-23
    Level 33  
    I meant the transistor and resistors because the entire power supply will change from 5V to 3V3. If nothing needs to be changed that's great, but I preferred to ask.
    Thanks, I'll be testing soon ;)
  • #13
    uzi18
    Level 24  
    george2002 wrote:
    Is it something like esp-link? https://hackaday.io/page/1304-virtual-serial-port-tunnel-to-use-with-esp-link " target="_blank" rel="noopener nofollow ugc" title="http:// https://hackaday.io/page/1304-virtual-serial-port-tunnel-to-use-with-esp-link " class="postlink inline-block "> https://hackaday.io/page/1304-virtual-serial-port-tunnel-to-use-with-esp-link because esp-link has a lot of options, only the RS485 support is probably not implemented from what I read quickly :)
    How about stability? and it works at what speeds and whether they can be changed easily or the code needs to be uploaded to esp8266 to make it different :) ?


    There is an esp-link latka with rs485 support, you have to look at repo / issue
  • #14
    piterek-23
    Level 33  
    Gentlemen, everything works great, but ... but there is a small problem ...
    If, for example, I reset the router, ESP loses the connection and can not reconnect - just do ESP reset and everything is OK again.
    Can it be improved somehow? :)
  • #15
    uzi18
    Level 24  
    Are you talking about the software from 1 post?
  • #16
    piterek-23
    Level 33  
    uzi18 wrote:
    Are you talking about the software from 1 post?

    Yes.
  • #18
    jajen
    Level 17  
    Hello,

    I also use this converter. I get an error compiling this new version

    es-rs485: 19: error:'earchwifi 'was not declared in this scope

    How can I fix it?
  • #19
    dktr
    Level 23  
    I think I broke something and I didn't attach this file, but the one from this attachment compiles without error.
    Another thing is that ESP itself will reconnect to the network and will work, but the socat will probably collapse and you need to fire it again. For full automation on the server, you can make a file, e.g. cgi or php, which will launch socat and this file will be asked by ESP when connected to the network.
  • #20
    jajen
    Level 17  
    Already ok. New version of arduin ide helped. Thanks
  • #21
    piterek-23
    Level 33  
    dktr wrote:
    I think I broke something and I didn't attach this file, but the one from this attachment compiles without error.

    Everything seems to be working as it should. When ESP was working, I did a router reset several times and each time ESP reconnected.
    dktr wrote:
    Another thing is that ESP itself will reconnect to the network and will work, but the socat will probably collapse and you need to fire it again.

    That's right, you should re-use the socat command ... :(
    dktr wrote:
    For full automation on the server, you can make a file, e.g. cgi or php, which will launch socat and this file will be asked by ESP when connected to the network.

    Would you have an idea for such a script?
    The only thing left to be happy is "automation" of socat ;)

    I tried something like this:
    Code: bash
    Log in, to see the code

    The link / dev / ttyUSB10 is created, but no longer reading the counter.

    Many thanks for the WiFi fix ;)
  • #22
    dktr
    Level 23  
    In the next version of the software, the function of downloading the file from the server when connected to the wireless network has been added:

    const String url = "http://192.168.2.40/esp_rs485.php?sign=";

    in this variable you must specify the address of the file on the server which, after querying it, will compile and restart socat. By the way, you can download the signal level with which esp8266 connected to the network into the variable.

    In php:
  • #23
    piterek-23
    Level 33  
    Can you suggest how it should all look exactly, how to automate it?

    I have soft "es-rs485_v2" on ESP, and in it I changed to my:
    WiFiServer localServer (4321);
    IPAddress staticIP (192, 168, 1, 221);
    IPAddress gateway (192, 168, 1, 1);
    IPAddress subnet (255, 255, 255, 0);
    const String url = "http://192.168.1.2/esp_rs485.php?sign=";
    WiFi.begin ("my_net", "my_password");

    On the server I created a php file with the following content:
    Code: php
    Log in, to see the code

    Now what, what about socat?
    If I manually add:
    Code: bash
    Log in, to see the code

    It all seems okay
  • #24
    byrrt
    Level 21  
    byrrt wrote:

    Not supporting RS485 (DE signal) is not a problem:
    TCP-IP / RS485 ESP8266 converter
    Proven - works, also in many production devices.


    Recently, I was returning to the topic and it would be bad if I had not written that - although this solution works, it is not free from defects. In this case, the transmitter in RS485 is turned on only when the USART in the prock sends zero .. When one - the system switches to the receiver. The effect is this:

    TCP-IP / RS485 ESP8266 converter

    On the left - transmission - using the circuit from the diagram I have posted, on the right - from the system in which DE is properly controlled. It looks like this when terminators are attached at the ends of the line, without them it always looks good (even with DE controlled only in transmitting zero).
    Yes for posterity ..

    If we have one transmission speed, we can control the delay system DE.

    TCP-IP / RS485 ESP8266 converter

    The elements must be selected according to the speed.
  • #25
    uzi18
    Level 24  
    Termination on short lengths of wire usually does not work properly.
    How long do you have the line?
  • #26
    byrrt
    Level 21  
    It always works, it has no effect, because here you just make a voltage divider (polarizing resistor - terminators - polarizing resistor). In the version with a transistor without a delay system, the transmitter transmits only 0, instead of transmitting it, it releases the lines slowly ..
  • #28
    po_48
    Level 8  
    Hello, I have a problem with uploading the es-rs485_v2.ino file by Arduino
    what am i doing wrong?
  • #29
    dktr
    Level 23  
    po_48 wrote:
    Hello, I have a problem with uploading the es-rs485_v2.ino file by Arduino
    what am i doing wrong?


    You need a glass ball. Any details?
  • #30
    po_48
    Level 8  
    Arduino: 1.8.1 (Windows XP), Tile: "Generic ESP8266 Module, 80 MHz, ck, 26 MHz, 40MHz, QIO, 8M (7M SPIFFS), 2, v2 Lower Memory, Disabled, None, All Flash Contents, 115200 "

    In file included from c: \ documents and settings \ admin \ local settings \ application data \ arduino15 \ packages \ esp8266 \ tools \ xtensa-lx106-elf-gcc \ 1.20.0-26-gb404fb9-2 \ xtensa-lx106-elf \ include \ c ++ \ 4.8.2 \ utility: 68: 0,

    from c: \ documents and settings \ admin \ local settings \ application data \ arduino15 \ packages \ esp8266 \ tools \ xtensa-lx106-elf-gcc \ 1.20.0-26-gb404fb9-2 \ xtensa-lx106-elf \ include \ c ++ \ 4.8.2 \ algorithm: 60,

    from C: \ Documents and Settings \ admin \ Local Settings \ Application Data \ Arduino15 \ packages \ esp8266 \ hardware \ esp8266 \ 2.4.1 \ cores \ esp8266 / Arduino.h: 254,

    from sketch \ es-rs485_v2.ino.cpp: 1:

    c: \ documents and settings \ admin \ local settings \ application data \ arduino15 \ packages \ esp8266 \ tools \ xtensa-lx106-elf-gcc \ 1.20.0-26-gb404fb9-2 \ xtensa-lx106-elf \ include \ c ++ \ 4.8.2 \ xtensa-lx106-elf \ bits \ c ++ config.h: 426: 29: fatal error: bits / os_defines.h: No such file or directory

    #include

    ^

    compilation terminated.

    exit status 1
    Compilation error for Generic ESP8266 Module.

    This report should contain more information if in
    File -> Preferences will be enabled "Show
    detailed information during compilation "