Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT - Serial bridge #2190

Closed
wants to merge 12 commits into from

Conversation

danielztolnai
Copy link

@danielztolnai danielztolnai commented Mar 18, 2018

Software serial - MQTT bridge implemented as an xdrv. Useful when interfacing with devices having only a serial port for communication like for example projectors and older AV receivers.

Quick info and usage:

  • Configure pins "SerBr Rx" and "SerBr Tx"
  • Set the baud rate through cmnd/sonoff/SBrBaud (Can be anything from 1200 to 115200)
  • Send data through cmnd/sonoff/serialbr
  • Received data is published to stat/sonoff/SERIALBR
  • Delimiter functionality can be enabled by sending the ASCII code of the delimiter to cmnd/sonoff/SBrDelim
  • Delimiter functionality can be disabled by sending 0xff to cmnd/sonoff/SBrDelim
  • Added support for whitespace characters. It is possible to transmit for example a newline character by putting its escaped version ("\n") in the MQTT message

@danielztolnai danielztolnai changed the base branch from master to development March 18, 2018 17:28
@arendst
Copy link
Owner

arendst commented Mar 18, 2018

You're 8 hours too late. I have just released this functionality. ;-)

@danielztolnai
Copy link
Author

danielztolnai commented Mar 18, 2018

@arendst Your implementation is using the hardware serial. In a software serial implementation you can choose pins, and you will not have the ESP's reset messages on the serial line. (For example, I can't use the hardware implementation as my projector will go into serial error mode when it receives the bytes output by the ESP at boot.)

Correct me if I've missed something or said something wrong. :-)

@arendst
Copy link
Owner

arendst commented Mar 18, 2018

You are right but what currently uses tasmotaserial I see exceptions randomly so I choose the hardware option this time. I'll look into your implementation too.

@danielztolnai
Copy link
Author

danielztolnai commented Mar 18, 2018

@arendst I've been testing the basic implementation (using 38400 bps) for around 48 hours now and it seems to work (for now). I hope it will work for you as well. :-) Above the advantages I have mentioned before, this also has the comfort of working on devices that use the hardware serial for something else, like the older Sonoff Dual.

@arendst
Copy link
Owner

arendst commented Mar 19, 2018

Convinced! I will add to next pre-release. Well done.

arendst added a commit that referenced this pull request Mar 20, 2018
5.12.0h
 * Add support for Software Serial bridge using commands
SerialDelimiter, SBaudrate and SSerialSend. Supports 8N1 and text only
(#2190)
 * Add support for Hardware Serial bridge using commands
SerialDelimiter, Baudrate and SerialSend. Supports 8N1 and text only
(#2182)
@arendst
Copy link
Owner

arendst commented Mar 20, 2018

Implemented.

@arendst arendst closed this Mar 20, 2018
@danielztolnai
Copy link
Author

@arendst Please excuse my bluntness, but the implementation in my pull request is still superior to yours.

  1. You've disabled sending raw binary data. MQTT itself supports this, and it works well in my implementation.
  2. You've also disabled using any binary byte as the delimiter.
  3. You've wrapped the data received from the serial port in JSON. I understand that all Tasmota telemetry and status data uses JSON, but in the case of a serial port, it brings more problems to the table than advantages.
  4. The code that you use for MQTT input preprocessing removes all whitespace characters using the isspace() function but you have disabled the "\s" escaped space character in the Unescape() function. This makes it impossible to send a space character through the serial port.
  5. My implementation has the ability to disable unneeded parts of the code to save flash and memory space.

Points 1., 2. and 3. make it impossible to use your implementation as a transparent serial bridge, which is required in multiple serial port use cases. (Where you have to transfer raw binary data)

I am not pushing you to use my implementation as it is, but please fix these issues (1. to 4.) as having a transparent serial bridge has more opportunities than having a text only one. (Also, the transparent implementation has no drawbacks compared to the text only one.)

@aidanmountford
Copy link

Thanks guys.

I was literally looking at writing this last week ... I will run it up over the weekend and see how I go...

A

@Jason2866 Jason2866 mentioned this pull request Jul 9, 2018
curzon01 pushed a commit to curzon01/Tasmota that referenced this pull request Sep 6, 2018
5.12.0h
 * Add support for Software Serial bridge using commands
SerialDelimiter, SBaudrate and SSerialSend. Supports 8N1 and text only
(arendst#2190)
 * Add support for Hardware Serial bridge using commands
SerialDelimiter, Baudrate and SerialSend. Supports 8N1 and text only
(arendst#2182)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants