Thank you for the great project base!
I have a similar odd desk.
I am embarrassed to be still very confused about the wiring to the ESP dongle between desk and the controller, and how the UART wires should be.
The cable itself has 10 pins, which i counted after ordering the expanders from Aliexpress with 8 pins But i discarded the outermost ones that control the 12 Volts, and it almost works, it fits to the base nicely and i can use the inner 8.
But here are the problems:
- When inserting WHITE to TX on ESP32, i can get the binary sensors (pressed button up, button down, etc)
- When inserting WHITE to RX on ESP32, i can get the table to move with buttons
- Modified your cpp code to expose more public functions for testing, so i can move it up or down.
void move_to_from(const float height_in_cm, const float current_height);
void move_to(const float height_in_cm);
void stop();
void move_up();
void move_down();
void move_to_memory_1();
void move_to_memory_2();
- But never have I got the desk height
- Not have I got the dongle to work together with the physical controller. The display just says 888. and buttons dont work.
So about wiring:
- should I keep the existing connection between table and controller, and add my wires for ESP just in the middle?
- or remove the existing WHITE and BLACK to just go through my ESP32?
- i have 2 uart buses configured, where do the wires go? exactly?
- id: remote_bus
tx_pin: 1 # when WHITE - allows to control the desk
rx_pin: 3 # when WHITE - reads sensor data from controller
# together they break
- id: desk_bus
rx_pin: 17 # no combo does anything
tx_pin: 16 # no combo does anything
I’m ashamed to have spent too much time on this, and now I just want to finish it out of spite.
Tried the uart_mitm component for no avail.
So I almost hacked out the height from desk, logging and reading the hex data, parsing it to numbers (without proper wiring):
debug:
direction: BOTH
dummy_receiver: true
after:
delimiter: "\xA5"
sequence:
- lambda: |-
UARTDebug::log_hex(direction , bytes, ','); //Still log the data
auto uart_direction = "IDK";
if (direction = uart::UART_DIRECTION_TX ){
uart_direction = "TX: ";
}
else if (direction = uart::UART_DIRECTION_RX ){
uart_direction = "RX_ ";
}
auto bytes_size = bytes.size();
std::string log_message = uart_direction;
for(int i = 0; i < bytes_size; ++i){
char buffer[4];
sprintf(buffer, "%02x ", bytes[i + bytes_size - 1 ]);
log_message += buffer;
}
if ( bytes_size >= 5){
ESP_LOGW("desk_bus", "%s", log_message.c_str());
}
else {
ESP_LOGI("desk_bus", "%s", log_message.c_str());
}
even got this far as to read the height value out of the uart buffer, somewhat semi-consistently:
script:
- id: get_debug_height
mode: single
then:
- lambda: |-
// provided map gives error on "4" // data[2] is data2 = EDGE CASE if contain 4 (74, 84, 94, 104, 114, 124)
// static const int SEGMENT_MAP[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x67, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
// 0 1 2 3 4 5 6 7 8 9
static const int SEGMENT_MAP[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x67, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
//0x66
uint8_t data[5];
while (id(desk_uart).available() >= 5) {
id(desk_uart).read_array(data, 5);
if (data[0] != 0x5A) {
ESP_LOGE("seisuk", "[0] %02x must be 0x5A, [3] is %02x", data[1], data[3]);
//break;
continue;
}
if ((data[1] | data[2] | data[3]) == 0x00) {
ESP_LOGD("seisuk", "null height");
//break;
continue;
}
int data0 = -1, data1 = -1, data2 = -1;
for (int i = 0; i < 10; i++) {
if (data[1] == SEGMENT_MAP[i]) data0 = i;
if (data[2] == SEGMENT_MAP[i]) data1 = i;
if (data[3] == SEGMENT_MAP[i]) data2 = i;
}
float got_height = 0.0;
if (data0 < 0 || data1 < 0 || data2 < 0) {
if (data0 < 0 ) {
ESP_LOGE("data", "data0: %02x", data[1] ); // if ( data[1] != 0x00 ) { }
}
if (data1 < 0 ) {
// true for values above 100, false for below 100
ESP_LOGW("data", "data1: %02x", data[2] ); // if ( data[2] != 0x00 ) { }
}
if (data2 < 0 ) {
ESP_LOGW("seisuk", "data2: %02x", data[3] );
}
//break;
continue;
}
// get decimal
int decimal = ((~data[4] + 256) % 256) / 10;
// sum if up
got_height = data0 * 100 + data1 * 10 + data2 + decimal * 0.1;
add decimal
//if (got_height >= 100.0){
// got_height += decimal * 0.1;
//}
// If belo 3 digis, e.g 100
// INVERT HEIGHT FOR BELOW ZERO
if (data[2] & 0x80 && data1 < 0) {
got_height = got_height / 10 + 10;
float under_99 = ( ( ~data[4] + 256 ) % 256 );
if (under_99 > 100 ){
//under_99 /= 10;
}
float inverted = ( ( data[4] + 256 ) % 256); // + 100;
if (inverted > 100 ){
//inverted /= 10;
}
float reinverted = ( ( data[4] ) % 256) / 2; // + 100;
if (reinverted < 10 ){
//reinverted *= 10;
}
if (under_99 < 101 && under_99 > 65 ){ // && under_99 != 68.00
ESP_LOGI("under_99", "%.2f", under_99 );
}
if (inverted < 101 && inverted > 65 ){
ESP_LOGW("inverted", "%.2f", inverted );
}
if (reinverted < 101 && reinverted > 65 ){ // && reinverted != 100.00
ESP_LOGE("reinverted", "%.2f", reinverted );
}
if (data1 < 0 ) {
// ESP_LOGE("data1", "%02x", data[2] ); // if ( data[2] != 0x00 ) { }
}
if (under_99 <= 100 && under_99 > 66 ){
//got_height = under_99;
//ESP_LOGI("got_height", "%.2f", under_99);
}
if (got_height <= 100 ){
ESP_LOGI("lt100", " %.1f", got_height );
}
}
// IF BELOW 100, divide by 10, get decimal place
ESP_LOGW("height", "data[2]: %02x, data1: %d", data[2], data1);
// IF ALL IS CORRECT, PUBLISH VALUES, DO STUFF
if (got_height <= id(max_height) && got_height >= id(min_height) ){
ESP_LOGI("height", "%.1f ", got_height );
id(uart_height).publish_state(got_height);
id(height) = got_height;
}
if (got_height >= id(max_height) || got_height <= id(min_height) ){
id(seisuk).stop();
}
}