Aircoookie / WLED

Control WS2812B and many more types of digital RGB LEDs with an ESP8266 or ESP32 over WiFi!
https://kno.wled.ge
MIT License
14.24k stars 3.03k forks source link

KNX connector Implementation (usermod) #2568

Open Alex0176 opened 2 years ago

Alex0176 commented 2 years ago

Is your feature request related to a problem? Please describe. The featurerequest is primary for use WLED via KNX Bus or better the Presets for KNX Group Addresses.

Describe the solution you'd like There is a git project for use KNX and can be used for set the KNX Address and send and receive data from/to KNX Bus with a ,,Bus Koppler" (bus coupling unit, i.e. a bus connector). In this Video (german) you see whats needed for KNX and the wireing: https://www.youtube.com/watch?v=KtBNI-xF23w

the KNX lib can be downloaded here: https://knx-user-forum.de/filedata/fetch?id=1549797

Describe alternatives you've considered In WLED is needed to:

Values: Send to KNX: actual preset, on/off WLED (for Powersupply) Receive from KNX: set preset, set % value (for special effects)

Additional context Add any other context or screenshots about the feature request here.

Thank you for your ideas for making WLED better!

Maintainer update KNX seems to be a standard bus for industrial sensors and actuator (similar to I2C, but bigger, longer cables, etc) for building automation systems. Ready made libraries to handle the low-level communication are availeable.

According to wikipedia https://en.m.wikipedia.org/wiki/KNX

KNX devices are commonly connected by a twisted pair bus and can be modified from a controller.

KNX is not based on a specific hardware platform and a network can be controlled by anything from an 8-bit microcontroller to a PC, according to the demands of a particular building. The most common form of installation is over twisted pair medium.

A KNX installation always consists of a set of devices connected to the bus or network. Device models vary according to node roles, capabilities, management features and configuration modes, and are all laid down in the profiles. There are also general-purpose device models, such as for bus coupling units (BCUs) or bus interface modules (BIMs).

Devices may be identified and subsequently accessed throughout the network either by their individual address, or by their unique serial number, depending on the configuration mode. (Unique serial numbers are allocated by the KNX Association Certification Department.) Devices can also disclose both a manufacturer specific reference and functional (manufacturer independent) information when queried.

KNX can link up to 57,375 devices using 16-bit addresses.

Aircoookie commented 2 years ago

This is a good idea and would be best implemented as a WLED usermod by a knowledgable user with a KNX system :)

Alex0176 commented 2 years ago

i think the parts todo: ( i can read C/C++, but i have no knowlage in this)

if (knx ==true) {
    KnxTpUart knx(&Serial1, "x.x.x"); // "x.x.x" should be the stored physical adress in cfg.cpp
    Serial1.begin(19200, SERIAL_8E1)
    knx.uartReset();
}

bool success = knx.groupWriteBool("x/x/x", index); .....



in the settings.html add the line:
`<form action="/settings/knx"><button type="submit">KNX Setup</button></form>`

add a new settings_knx.html file (only for the enable and physical adress or with group address settings to write or read) 
it depends if everything with knx should be on one point. I dont know how to read out the existing presents, so i can not make a example. 

The html_settings.h have to be autogenerated again.
Alex0176 commented 2 years ago

Today i had 2 hours time and check out the usermod v2 example and i make a few things, but i dont know how i can add config fields to define the group address directly at the presents in the webinterface (for now i make a possibility of 50 presets hardcorded and i dont know how to compile the staff.

i get everytime a missing

include

                   ^

compilation terminated.

In Visual Studio with PlatformIO

Can anyone compile it for me or help me with my questions?

extract this to the usermod directory:

compile options: -D USERMOD_KNX

in the usermods_list.cpp you have to add:

ifdef USERMOD_KNX

include "../usermods/KNX-Presents/knx-presents.h"

endif

: KNX-Presents.zip

void registerUsermods() {

ifdef USERMOD_KNX

usermods.add(new KNXPreset());

endif

: :

Alex0176 commented 2 years ago

i got now a link error, but i'am not able to fix this. i think there is a issue with casting the serial port to a stream.

Can anyone help me in this case?

/../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\d1_mini\src\usermods_list.cpp.o: in function `_GLOBAL__sub_I_physicalAddress':
usermods_list.cpp:(.text.startup._GLOBAL__sub_I_physicalAddress+0x2b): undefined reference to `KnxTpUart::KnxTpUart(Stream*, String)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\d1_mini\firmware.elf] Error 1

KNX-Presents-a0.0.2.zip

blazoncek commented 2 years ago

Please use WLED forum or Discord for help and support questions.

h1ghb1rd commented 1 year ago

@Alex0176 Have you made any progress on this?

Alex0176 commented 1 year ago

@h1ghb1rd Have you made any progress one this?

i dont know why it does not compile ... and noone like to help me in this case.

softhack007 commented 1 year ago

Today i had 2 hours time and check out the usermod v2 example and i make a few things

Welcome to the world of WLED development :-) Not to spread frustration, but I'd encourage you to spend more time on the task. 2 hours is surely to little time to even understanding the basic.


include

^ compilation terminated. undefined reference to `KnxTpUart::KnxTpUart(Stream*, String)' collect2.exe: error: ld returned 1 exit status

This looks like platformIO cannot find a library that provides KnxTpUart.h. which library do you want to use?

This library looks similar to what is missing: https://github.com/majuss/KnxTpUart

To use it, add a line majuss/KnxTpUart to global lib_deps https://github.com/Aircoookie/WLED/blob/74156b7ed8a1449ed459baeb7934debb53a19665/platformio.ini#L149-L160


add the information into the preset.cpp (for save/load the settings) add enable knx and physical adress to cfg.cpp modify the html templates

Actually you don't need to fiddle with set.cpp + cfg.cpp and html templates, if you want to add your own usermod settings section. This can be done from inside the usermod, using the standard JSON API.

https://github.com/Aircoookie/WLED/blob/74156b7ed8a1449ed459baeb7934debb53a19665/usermods/EXAMPLE_v2/usermod_v2_example.h#L187-L197

If you need a full example, take a look at the boblight usermod https://github.com/Aircoookie/WLED/blob/74156b7ed8a1449ed459baeb7934debb53a19665/usermods/boblight/boblight.h#L307-L351

Alex0176 commented 1 year ago

KnxTpUart.h

Hi, the libs are included in the ZIP File, and i dont get this kind of compile error.

I get in the Version KNX-Presents-a0.0.2.zip the error /../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\d1_mini\src\usermods_list.cpp.o: in function_GLOBALsub_I_physicalAddress': usermods_list.cpp:(.text.startup._GLOBALsub_I_physicalAddress+0x2b): undefined reference to KnxTpUart::KnxTpUart(Stream*, String)' collect2.exe: error: ld returned 1 exit status *** [.pio\build\d1_mini\firmware.elf] Error 1

So its not a libary problem, more a linker or add cpp problem. i dont know - i am not a c programmer, so its hard for me to figure out whats exacly the problem right now.

softhack007 commented 1 year ago

So its not a libary problem, more a linker or add cpp problem. i dont know - i am not a c programmer,

Actually it is a library problem, as the linker does not find the library where the class KnxTpUart is implemented.

This typically happens in platformIO if you manage to feed it with a header file, but did not use the proper way of importing an external library into platformIO. The usual way to do so, is by using lib_deps and pointing to a github repository that provides the library. Please try to understand my above answer fully, as I already explained how it might be solved.

Alex0176 commented 1 year ago

i dont know how i can configure this - so i hope anyone other with C knowlege can work on it. i can tast and help with the logic

PaoloTK commented 10 months ago

i dont know how i can configure this - so i hope anyone other with C knowlege can work on it. i can tast and help with the logic

I'm working on a KNX TP integration myself. I have switch groups working but that's it for now. I was wondering, other than listening and writing to groups that you would expect from a light (on/off, brightness, effect, etc.) is there any other feature you think makes sense to have?

Alex0176 commented 10 months ago

i think the power on/off for the powersully will be a good idea to have. So you can power the ESP via KNX and switch the powersupply via KNX group. The other effects you find on the typical switch solution, like MDT have on his glas panals. https://www.youtube.com/watch?v=cx85Y5eTSHQ

did you have already a usemod or custom firmware?

PaoloTK commented 10 months ago

i think the power on/off for the powersully will be a good idea to have. So you can power the ESP via KNX and switch the powersupply via KNX group. The other effects you find on the typical switch solution, like MDT have on his glas panals. https://www.youtube.com/watch?v=cx85Y5eTSHQ

did you have already a usemod or custom firmware?

The power supply should switch on automatically when the light is turned on in WLED, why would you add the relay to a separate switch group?

You can find the usermod code in my repos, WLED/KNX. But it's too early to submit it, needs a lot more work done.

Alex0176 commented 10 months ago

yes, but if you make this with ESP32 than you have to switch the 230V relay, but if you have this already on KNX, you can use this switch. This make sense i think.

PaoloTK commented 10 months ago

yes, but if you make this with ESP32 than you have to switch the 230V relay, but if you have this already on KNX, you can use this switch. This make sense i think.

I have already implemented a light feedback group. If you have an actuator that controls the light power supply, add its switch group to the light feedback group. When you turn the light on in WLED it will send a "TRUE" to the group, turning on the actuator.

Is this what you were looking for?

PaoloTK commented 10 months ago

@Alex0176 I have made some further progress and added basic instructions on getting my usermod up and running. I want to stress this is super early and there will be bugs, but if you want to try it I've got basic functionality (on/off, absolute and relative dimming) working. You can find the instructions and code here, but you will have to custom compile. I haven't tested the usermod with free and 2-level group style, so it won't probably work unless you use 3-level style.

https://github.com/PaoloTK/WLED/tree/KNX/usermods/KNX

If you have any questions or have troubles getting this up and running, let me know.

KlausHans commented 10 months ago

Very interesting idea! Tasmota has this feature already, the integration in Wled would be perfect. @PaoloTK I would like to test but i only have a knx interface, no router. I think i will change that in the future, but for now i can not test it. Edit: i just saw that you dont use Knx Ip.

PaoloTK commented 10 months ago

Very interesting idea! Tasmota has this feature already, the integration in Wled would be perfect. @PaoloTK I would like to test but i only have a knx interface, no router. I think i will change that in the future, but for now i can not test it. Edit: i just saw that you dont use Knx Ip.

The interface will work fine too, the WLED devices communicate over twisted pair.

michael-blue2 commented 3 months ago

@Alex0176 I have made some further progress and added basic instructions on getting my usermod up and running. I want to stress this is super early and there will be bugs, but if you want to try it I've got basic functionality (on/off, absolute and relative dimming) working. You can find the instructions and code here, but you will have to custom compile. I haven't tested the usermod with free and 2-level group style, so it won't probably work unless you use 3-level style.

https://github.com/PaoloTK/WLED/tree/KNX/usermods/KNX

If you have any questions or have troubles getting this up and running, let me know.

Hey @PaoloTK I have been trying to compile your code to test it. But I do always get an error that (PackageException: Package version 2.2.0+sha.a68a18c doesn't satisfy requirements ~2.0.7 based on PackageMetadata) Any chance you can share the compiled file (.bin file)? And have you made any process from the first time you uploaded your code? as its been 7 months.

michael-blue2 commented 3 months ago

I got around that error and just compiled the bin file. I will start right now the test with the bus system. I will be using some abb bus couplers ( a bit over priced) but I already had them around.

PaoloTK commented 3 months ago

@Alex0176 I have made some further progress and added basic instructions on getting my usermod up and running. I want to stress this is super early and there will be bugs, but if you want to try it I've got basic functionality (on/off, absolute and relative dimming) working. You can find the instructions and code here, but you will have to custom compile. I haven't tested the usermod with free and 2-level group style, so it won't probably work unless you use 3-level style. https://github.com/PaoloTK/WLED/tree/KNX/usermods/KNX If you have any questions or have troubles getting this up and running, let me know.

Hey @PaoloTK I have been trying to compile your code to test it. But I do always get an error that (PackageException: Package version 2.2.0+sha.a68a18c doesn't satisfy requirements ~2.0.7 based on PackageMetadata) Any chance you can share the compiled file (.bin file)? And have you made any process from the first time you uploaded your code? as its been 7 months.

Hi, glad you got it compiled, let me know how it works. As for progress on the code, I got stuck due to performance issues when trying to support 600+ groups (all settings for each segment for max amount of segments), so I started a complete rewrite with a more efficient memory handling but got kinda stuck and been busy with work. Not sure if it's worth the effort since I doubt most people use that amount of segments.

Alex0176 commented 3 months ago

i dont get it up and running right now - so i wait for a working image or something like this, where we can configure the knx stuff via webinterface. . . than i will add the knx stuff to my wled installations here.