The UART interface is designed to send text or hex commands between an external device (e.g., Arduino) and a host.

The maximum command size is 127 bytes. Every command line may terminate with a special configurable byte: CR (0x0D), LF (0x0A) or 0x03 (ETX). The firmware also adds the ending signature to each of the commands that the device receives from a host and outputs to UART. If the end signature is not defined, the firmware waits 300 ms and outputs the whole buffer to a host.

UART uses P02 and P03 pins (3.3V). You should enable UART on P02 on an output pin in the configuration.

You can also select a baud rate for the UART interface in the firmware configuration.

UART configuration. P02 is required. P03 is optional.

Zigbee cluster: ZCL_CLUSTER_ID_GEN_MULTISTATE_VALUE_BASIC
Zigbee attributes: ATTRID_IOV_BASIC_STATE_TEXT – UART data. You should use the “ZCL_DATATYPE_OCTET_STR” (0x41) or “ZCL_DATATYPE_CHAR_STR” (0x42) data types for this attribute.

Zigbee2MQTT commands

write – sends data to a UART.
Topic: z2m/[friedly_name]/set/action
Payload: text command

The following command allows you to send any bytes. The first byte in the array (2) is the number of bytes following the length.
Topic: z2m/[friedly_name]/set
Payload: {“action”: [2, 0, 0]}

Example

if you want to send the following sequence of bytes: 0xAA 0x03 0x08 0x10 0x04 0xC9.

  1. Convert all bytes to decimal: 170 3 8 16 4 201.
  2. Count your bytes: 6.
  3. Make a payload string: {“action”: [6, 170, 3, 8, 16, 4, 201]}
  4. Send it using MQTT Explorer or a similar utility:
    1. Select the device in the tree (fig. 1).
    2. Go to “Publish” and specify the full topic name.
    3. Specify the payload.
    4. Click the Publish button.
Sending data to UART
Sending data to UART

Comments
Harvey Specter
Posted at 10:33 June 9, 2021
Parats
Reply
Author

Hello, I need to get some ascii datas form uart communication.
Could I set up a uart input ?

    Harvey Specter
    Posted at 03:29 June 10, 2021
    Owner
    Reply
    Author

    If you define UART on “Output”, it can send data in both directions. But you can configure communication parameters.

Harvey Specter
Posted at 18:38 May 20, 2021
Simon
Reply
Author

Hi, I’m using in uart mode and I’m getting an empty action after every action I expect, is this normal? I’m also getting 3 status messages directly after each other, is there a way I can limit this to 1?

    Harvey Specter
    Posted at 03:27 May 21, 2021
    Owner
    Reply
    Author

    Hi. The problem is not clear. Please, open an issue on github and attach screenshots with your settings, logs, etc.

Harvey Specter
Posted at 14:24 May 13, 2021
Peter
Reply
Author

Hi, I created UART communication between CC2530 and Arduino nano. It communicates via json. Here is an example what I send and receive:
sending data:
topic: zigbee2mqtt//set/action
payload: {’tilt_corr2′:20}

receiving data:
topic: zigbee2mqtt//action
payload: {“pos1″:0,”pos2″:0,”pos3″:0,”speed”:700,”op_pos1″:0,”op_pos2″:0,”op_pos3″:0,”tilt_corr1″:0,”tilt_corr2″:20,”tilt_corr3″:0}

It works well about 80% of time. But sometimes instead of json string I get just a bunch of numbers:
topic: zigbee2mqtt//action
payload: 10,123,34,112,111,115,49,34,58,48,44,34,112,111,115,50,34,58,48,44,34,112,111,115,51,34,58,48,44,34,115,112,101,101,100,34,58,55,48,48,44,34,111,112,95,112,111,115,49,34,58,48,44,34,111,112,95,112,111,115,50,34,58,48,44,34,111,112,95,112,111,115,51,34,58,48,44,34,116,105,108,116,95,99,111,114,114,49,34,58,48,44,34,116,105,108,116,95,99,111,114,114,50,34,58,50,48,44,34,116,105,108,116,95,99,111,114,114,51,34,58,48,125

Do you have any idea what could be the issue ?

    Harvey Specter
    Posted at 03:34 May 14, 2021
    Owner
    Reply
    Author

    Hi! This data packet contains a non-printable character (10). The converter cannot encode it to string.

      Harvey Specter
      Posted at 21:51 May 15, 2021
      Peter
      Reply
      Author

      Thanks for the answer. I’ve played with the line ending settings to be specifically the same and it started to work fine. Now I just need to figure out why is a random character in string missing sometimes, especially with high traffic. But it looks like Arduino -> CC5230 issue..

Harvey Specter
Posted at 19:41 April 11, 2021
Pavel
Reply
Author

Somehow I am not getting anywhere.
I am trying to use CC2035 with a 4 relay.
The relays switch with:
turn_on_action:
– uart.write: [0xA0, 0x01, 0x01, 0xA2]
turn_off_action:
– uart.write: [0xA0, 0x01, 0x00, 0xA1]

i can’t figure out how to set these commands with mqtt.

Output1 -> P02 -> UART
Output2 -> P03 -> UART

    Harvey Specter
    Posted at 03:57 April 12, 2021
    Owner
    Reply
    Author

    Hi Pavel. Where do you execute the “uart.write” command?

    Please, look here, how to send data using zigbee2mqtt
    https://ptvo.info/zigbee-configurable-firmware-features/uart/

    You should select “Packet end: none” in the UART settings in your case.

      Harvey Specter
      Posted at 13:14 April 12, 2021
      Pavel
      Reply
      Author

      This one example was from ESPHOME, and it worked fine. I want to replase esp01 with cc2530 like here: https://modkam.ru/?p=1551
      After flashing it was integrated into z2m and over mqtt I try to send this commands like:
      [0xA0, 0x01, 0x01, 0xA2]
      [0xA0, 0x01, 0x00, 0xA1]

        Harvey Specter
        Posted at 13:28 April 12, 2021
        Owner
        Reply
        Author

        I’ve sent you a link where you can see the corresponding example. In your case, a payload will look like this:

        1
        2
        {“action”: [4, 160, 1, 1, 162]}
        {“action”: [4, 160, 1, 0, 161]}
          Harvey Specter
          Posted at 13:34 April 12, 2021
          Pavel
          Author

          ok, I have to convert hex code into the number. This was the point. Thank you!

Harvey Specter
Posted at 11:54 April 9, 2021
Roland
Reply
Author

Thanks, did some testing but now I can’t get any UART data out, could be I’m making an error somewhere. I’m using a CC2531 USB dongle, this is the config:
/====
Board type: CC2530 (without external oscillator, like ??2531 dongle or Sonoff BasicZBR3)
Device type: Router
Transmit enable (TXEN): P12Receive enable (RXEN): P14
Update firmware’s timestamp : 2021-04-09
Status LED: P11, Periodic (every 5 seconds)
Set default reporting interval (s): 10

Output pins:
P00: Output 2, GPIO, External pull-up
P02: Output 5, UART (Baud rate: 9600, Packet end: 0x0D)

Input pins:
P12: Input 1, GPIO, External pull-up
====/
I do see that’s it is using TXEN and RXEN but there is no RF amp on the board and I can’t configure this in the main control panel when CC2531 is selected.
The board does pair ok, the LED works, only the UART does not.
Do I need a custom converter for the UART functions?

    Harvey Specter
    Posted at 12:27 April 9, 2021
    Owner
    Reply
    Author
      Harvey Specter
      Posted at 14:35 April 9, 2021
      Roland
      Reply
      Author

      I have a logic analyzer and connect that to P0.3 on the header. That’s where I’m expecting the serial data. I have found that P0.3 is TX and P.02 is RX. Did not do any testing with RX yet. Would like to use that as well in the future. USB is only for power in this configuration. I find the USB dongle a nice board because it has the leds and voltage regulator already on it. I use node red to send and recieve data to the board.

        Harvey Specter
        Posted at 08:36 April 10, 2021
        Owner
        Reply
        Author

        How do you test TX data? If you use Z2M in the middle, you should have a log file there. Maybe, it contains some messages or errors related to your device.

Harvey Specter
Posted at 17:47 April 6, 2021
Roland
Reply
Author

Done some testing with the UART, I got sending a string to work using the topic “zigbee2mqtt//l2/set/action”. Your example command does not contain the output number. If I leave this out I get a publish error. The second example (sending bytes) does not work. Can you give a more detailed example. What should I inject in the node? I did try a string, a JSON line but nothing works.
Thanks!

    Harvey Specter
    Posted at 03:49 April 7, 2021
    Owner
    Reply
    Author

    Did you try a firmware released 2021-04-05? I’ve fixed this problem there. Or you may configure UART on Output 1.

    Harvey Specter
    Posted at 14:12 April 10, 2021
    Roland
    Reply
    Author

    Started with a clean configuration with only the status led on P11 and UART P02 on output 1, and now I have some serial data on pin P03. I think I had a false combination of inputs/outputs that prevented the UART from working. To get the RX portion working do I need to configure P03?
    I bought you a coffee as a thank you for your support.

      Harvey Specter
      Posted at 06:02 April 11, 2021
      Owner
      Reply
      Author

      The old version of the firmware supported UART on Output 1 only. You need to configure only one pin, P02 or P03. The latest version supports UART on any output. Thank you for the coffee :).

Leave a Reply to Owner
Cancel Reply