-
Notifications
You must be signed in to change notification settings - Fork 27
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
Stream server component (serial-over-wifi) #660
Comments
I like this, if it's useful for you then it should be useful for other people. The thing being so generic leads to lot of issues, but this might be considered for advanced users, or something like that, that's why Otto recommended this being a custom_component / cookbook thing, so anybody could modify it quickly. For example your implementation allows for several clients connecting simultaneously to the bridge, this might not be what other people needs, then there will come the "option" to allow one connection and stick to it even if other connection arrives or another "option" to discard the active connection and the last request will win. Initially I'd like it to be implemented as a cookbook thing, it is really useful because it explains how stuff works and allows you to start from tested code, see e.g. the Arduino Port Expander Then there is the new There were a few messages exchanged with Otto, Brandon and other users, Otto is trying to make ESPHome more like HA where many contributors are easily allowed to add their own stuff and "take responsibility" of it, but nothing come out just yet. Anyway thanks for sharing the code! |
This request might be related to #688 = Request for "ESPHome support on Sonoff ZBBridge as a remote Zigbee adapter for Home Assistant's ZHA component via its zigpy and bellows libraries". As I understand that ##688 would depend on some kind of stream server for Serial or UART over Wi-Fi. Though while related I would not say that #660 replaced #688 and their ultimate goals are different. |
I would LOVE (yes capitals) this feature to be added to ESPHome. I'm building many different automation hardware for Home Assistant based on ESPHome, and this is something I really mis. Adding a second ESP only to use esp-link next to ESPHome is such a waste... |
I can confirm this custom component works with the new Sonoff ZBBridge and the ZHA intergation. esphome:
name: zigbee
platform: ESP8266
board: esp01_1m
includes:
- stream_server.h
- stream_server.cpp
wifi:
ssid: "HASSos"
password: "***"
ap:
ssid: "Zigbee Fallback Hotspot"
password: "***"
captive_portal:
logger:
baud_rate: 0
api:
password: "***"
ota:
password: "***"
uart:
id: uart_bus
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 115200
custom_component:
- lambda: |-
auto stream_server = new StreamServerComponent(id(uart_bus));
return {stream_server}; ZHA dosent resolve .local adresses so just use the IP. It would be awesome if this could be added to ESPHome. |
Nice! Is that the same as this one? https://gist.github.com/phha/651a2eeb30c6d6ca0937b3394e2bd9e6 |
Yes, that's exactly the same code, someone forked it but made no changes for some reason. |
Ah ok! I didn't saw the link in your first message, so I Googled it and found this one... found yours now :) |
Confirmed :) esphome:
name: p1test
platform: ESP8266
board: d1_mini
includes:
- stream_server.h
- stream_server.cpp
wifi:
ssid: "***"
password: "***"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "P1Test Fallback Hotspot"
password: "***"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
uart:
id: uart_bus
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 115200
custom_component:
- lambda: |-
auto stream_server = new StreamServerComponent(id(uart_bus));
return {stream_server}; Works like a charm! |
I like this too, but i have beginner problems with compiling it: So i searched ESPAsyncTCP.h but i found on github only a version for ESP 8266 (https://github.com/me-no-dev/ESPAsyncTCP or i must use an other one?) and for ESP32 i found only AsyncTCP.h (https://github.com/me-no-dev/AsyncTCP/tree/master/src). Can you give me considerations how can i let compile this custom_component for ESP32? |
@Harald-P Try adding this:
(note that this version is for ESPHome 1.14.5, newer/older versions might need a different version). Usually this library is already included by the |
hmmm, the version is 1.14.5 and i use i tryed adding your consideration, but i recive now:
i use hass.io and compile it over the esphome-dashboard in home assistant on a Raspberry pi... |
@Harald-P Oh, I didn't see that you were on ESP-32. I haven't tried it with an ESP-32 personally. Can you try replacing |
@oxan
The compilation concludet than without error, but now my ESP32 its not more working... So i look tomorrow if i can install the old immage to bring the ESP32 back online... |
I'm also on esp32 (m5stickc) did you get any further with this? edit: tried it myself still crashes on esp32. Hook it up to serial to see 9 boot attempts:
after which it proceeds to safe mode |
@MaartenKleijwegt Can you try inserting EDIT: Or actually, try this first: add before line 36 of
|
Thanks for the reply will try. was already looking into how esphome calls the app.setup loop. Figured it was setting up immediately after uart before wifi was setup. this #espressif/arduino-esp32#3467 hinted I was trying to setup some wifi component before wifi was initialized Could you point to where I can read up on esphome setup priority and such? haven't been able to find much in the last hour EDIT; tested and doesn't crash anymore. Able to connect through web server telnet (putty) and ESPHome the fix was:
didnt't try the other |
Ok, great! I've updated the gist to incorporate this fix.
The code, I guess. |
Would it be apreciated/an idea for me to open a pull request to update https://esphome.io/custom/custom_component.html with this example? that's where I would expect it and actually searched for it |
@MaartenKleijwegt the |
Works like a charm with ESP32 and CC2530 (zigbee2mqtt) ! |
thanks for your project,but when I use this for xiaomi zigbee button |
This is great, thank you! I can see that this will work perfectly for my Texecom Premier alarm, as a replacement for their COM-IP or COM-WiFi devices. All I will need to add is a level converter. It would be great if it was possible to customise the listening port in the configuration, though. Or should I just update the source? Also, how would I go about limiting this to a single concurrent connection? In theory, more than one concurrent connection should not happen, but in practice, it would probably cause havoc if it did, so it's probably worth while preventing it! Turns out that is simple enough, just add the following lines into the
So, my ultimate objective is to create an "intelligent" device, not purely a simple serial passthrough to allow for the Texecom app to do its own configuration/analytics/etc. Ideally, this device will implement enough of the Texecom SIMPLE protocol to allow it to interact with the panel, activate/deactivate zones, activate/deactivate the alarm itself, and report zone activations/violations both when the alarm is not set, and when it is. All of this would be available via the API, or via MQTT (I still need to figure out how the API works!) The plan is to have the component interacting with the UART until a new TCP connection comes in, at which point the component will cleanly disconnect from the panel, and allow the external program exclusive access. Once the TCP connection disconnects, the component will resume interaction with the panel, reporting back to HA or any other MQTT subscriber. Does this sound reasonable? I guess I should move this to a new issue, as it is far beyond a simple TCP-UART server now! |
I can confirm too that is working like charm with ESP8266+CC2530 and remote zigbee2mqtt. Thank you! |
Tip is also to check out Tube's Zigbee Gateways open-source hardware by @tube0013 which runs ESPHome firmware by default. Based on WT32-ETH01 (Wireless-Tag) ESP32 board which has wired Ethernet that makes for a much more stable serial connection. He designed two variants; one has a Silicon Labs EFR32 Series 2 module and one that has a Texas Instruments CC2652P module. https://github.com/tube0013/tube_gateways |
I've made my custom component available as a new external component for ESPHome v1.18+ under my GitHub account:
|
Hi all, Setup is: I have flashed the C2530 with Koenkk´s When Zigbee2MQTT's Herdsman tries to connect, I can see that in the ESPHome log, but it finally fails after 20 seconds:
The corresponding Z2M log looks like this:
May I ask some questions here to help me debug this:
Many thanks! :D |
Z2M configuration side at least looks correct so guess is that the issue probably is in wiring between ESP8266 and CC2530: https://www.zigbee2mqtt.io/guide/adapters/flashing/connecting_cc2530.html https://www.zigbee2mqtt.io/advanced/zigbee/05_create_a_cc2530_router.html#result I primarily use ZHA in HA and CC2652P myself (and not Zigbee2MQTT) so can not really help but can suggest posting here: https://github.com/Koenkk/zigbee2mqtt/discussions PS: Regardless, strongly recommend that buy CC2652P based module/adapter since CC2530 and CC2531 are really obsolete now (both very old hardware with limited resources and old "Z-Stack Home 1.2" firmware that is end-of-life by Texas Instruments). https://github.com/Koenkk/Z-Stack-firmware/blob/master/coordinator/Z-Stack_3.x.0/bin/README.md |
FYI, could test basic socat connection to CC2530x with zigpy-znp (Python script) which CLI commands for some tools like backup: https://github.com/zigpy/zigpy-znp/blob/dev/TOOLS.md |
That's really strange and interesting, as I'm experiencing the same error but via direct USB connection: Koenkk/zigbee2mqtt#2997 |
You could also enable ESPHome serial logging, so that you can see what the dongle receives and responds. Alternatively, logging on the TCP side of the stream-server, to reduce the number of lines of log output. I modified my stream_server.cpp with the following:
and
Just added logging lines. |
Great point! While not recommended for "production" for developers it can be a good idea to try Z-Stack 3 on CC2530/CC2531: https://github.com/Koenkk/Z-Stack-firmware/tree/master/coordinator Note that it is only this hacked/back-ported Z-Stack_3.0.x (and not Z-Stack_3.x.0) FW which can be used on CC2530 and CC2531: https://github.com/Koenkk/Z-Stack-firmware/tree/master/coordinator/Z-Stack_3.0.x/bin Note the comment "Zigbee 3.0 firmwares are not recommended for the CC2530 and CC2531 (since those are not powerful enough)". Again, not recommended but can be used by developers for lab or test purposes if do not yet have access to CC2652 hardware. |
Tip is to place pre-order for a few new inexpensive "SONOFF Zigbee 3.0 USB Dongle Plus" (CC2652P based adapter/stick by ITead): https://itead.cc/product/sonoff-zigbee-3-0-usb-dongle-plus/ https://sonoff.tech/product/diy-smart-switch/sonoff-dongle-plus/ At least board inside it look to have exposed TX and RX pads for serial so can probably also be used as a Zigbee serial module(?). |
Alternatively, you can try to order "RFSTAR RF-BM-2652P2" and/or "Ebyte E72-2G4M20S1E" which are CC2652P serial modules: https://www.szrfstar.com/product/237-en.html https://www.ebyte.com/en/product-view-news.html?id=1002 Thought due to the current silicon chip shortages it is well known that those modules can be hard to get a hold of at this time. Another alternative serial module is "RFSTAR RF-TI1352B1" which uses CC1352P which is like CC2652P but 2.4GHz + 1Ghz-sub too: https://www.szrfstar.com/product/188-en.html These can be ordered from example Aliexpress or Alibaba and will usually have much longer shipping times. Example: https://rf-star.aliexpress.com/store/910711003 https://www.aliexpress.com/item/1005001677721370.html https://www.aliexpress.com/item/1005003527541390.html https://www.aliexpress.com/item/1005003527468693.html https://www.aliexpress.com/item/1005001265532720.html |
Ah, thanks for your extensive input. Great! |
FYI, there is also a few ESP32 + CC2652P based open-source hardware gateway/bridge projects you can buy pre-assembled: ZigStar LAN Gateway (ships from Germany I believe) https://zig-star.com/projects/zigbee-gw-lan/ https://github.com/mercenaruss/zigstar_gateways Tube's Zigbee Gateways (ships from Australia or New Zealand I believe) https://www.tubeszb.com/shop/2 https://github.com/tube0013/tube_gateways Gio-dot Z-Bee Duo with CC2652P (ships from China I believe) https://github.com/Gio-dot/Z-Bee-Duo cyijun OpenZ3Gateway (ESP8266 only and ships from China I believe) https://github.com/cyijun/OpenZ3Gateway PS: Note that all those projects rely on the above mentioned TI CC2652P radio modules from RFSTAR and Ebyte/CDEbyte. |
By the way, another related feature request for ESPHome is using mDNS DNS record(s) for ZHA automatic network discovery (and the passing of configurations) of Zigbee coordinator bridges/gateways (Ethernet/WiFi network adapters) that support Zeroconf: FYI, ZHA integration Zeroconf network discovery of ESPHome based Tube's Gateways is already partially supported, see: https://www.home-assistant.io/integrations/zha#discovery-via-usb-or-zeroconf PS: ZHA automatic network discovery of ESPHome based Zigbee LAN adapters is a simple but awesome feature for new HA users. |
Can we move the discussion about Zigbee bridges/gateways somewhere else (i.e. a separate issue or a GitHub discussion)? It's fairly off-topic here and the many link-filled posts make this issue hard to read. |
Thanks again for all your valuable input. @oxan is right: This is an issue report / feature request that should not be bloated with off topic discussions. I will digest all your input and create a corresponding topic in the HA forum. Will leave a link here when its done. But please give me some time to work on it all. Many thanks again. |
You could maybe also continue relevant Zigbee related discussions in these other feature requests depending on specific topic subject -> https://github.com/esphome/feature-requests/issues?q=zigbee (Zigbee can be used in many different ways and that is why there are so many separate feature requests with slightly different topics/subjects). FYI, the specific idea around using ESPHome as a serial stream server to remotely access a Zigbee UART module from a computer is discussed in #688 |
Is there an official alternative now? https://github.com/oxan/esphome-stream-server is very unreliable with ESPHome > 2021.9, the connection resets every few hours. we are now ~10 version past this and a lot of newer esphome functionality is missed if relying on the stream-server custom component. |
Is it same issue in https://github.com/syssi/esphome-zb-gw03 as https://github.com/tube0013/tube_gateways ESPHome images? Alternativly, while not official wondering if it is possible to use ESPHome serial server component by @thegroove if better? https://github.com/thegroove/esphome-serial-server It is used as a custom component in his ESPHome for ITead Sonoff Zigbee Bridge (based on ESP8266/ESP8285): https://github.com/thegroove/esphome-zbbridge https://github.com/thegroove/esphome-zbbridge/tree/main/custom_components/serial_server PS: He also started the development of a Zeroconf custom component for ESPHome that can be used with it: https://github.com/thegroove/esphome-zeroconf https://github.com/thegroove/esphome-zha-ezsp-zeroconf https://github.com/thegroove/esphome-zha-ezsp-zeroconf/tree/main/custom_components/zeroconf |
All of these are derived off of the original code in https://github.com/oxan/esphome-stream-server so they all suffer the same thing. ESPHome-2022.8.3 seems much more stable and cc2652 connections are stable. EFR32 is still unstable. I've tested the same esp32 with alternate non-esphome fw and it is capable of steady reliant connection, a new component or a re-write of the original custom component is needed for this to be reliable. |
@tube0013 thanks for testing and clarifying. |
FYI, tube0013 has forked oxan's esphome stream server and got it working reliably with ESPHome versions newer than 2021.10: |
Describe the problem you have/What new integration you would like
A server that allows bidirectional communication with a serial port over WiFi. Now, I know this has been requested and rejected before (#213, #415, #619, #638), but I disagree with the given reasoning (and I have a patch :)):
acer_projector
,alarmdecoder
,arduino
,aurora_abb_powerone
,dsmr
,edl21
,elv
,enocean
, etc.Stream
abstraction implemented by the UART interface. Thus, the backend is already there, and we only need a frontend to expose a Stream over TCP.Please describe your use case for this integration and alternatives you've tried:
See above. I want to hookup both a serial port and some other sensors (or switches, etc) to a single ESP integrated in Home Assistant.
Alternatives are various different ESP firmwares (ESPEasy, ESPLink); but neither of those allows me to easily integrate a sensor in HA.
External component
For now I've implemented this as a external component, which is available here. It creates a TCP server listening on port 6638, and relays all data between the connected clients and the serial port. It doesn't support any control sequences, telnet options or RFC 2217, just raw data (I don't think the fancy stuff is actually useful, very few devices require it and they aren't actually wired on the common ESP modules).
However, I think it'd be nice if this was available in ESPHome by default. I can create a PR to rework my custom component to integrate it in ESPHome itself (including configuration etc.) if you agree to accept this functionality.
The text was updated successfully, but these errors were encountered: