absalom-muc / MHI-AC-Ctrl

Reads and writes data (e.g. power, mode, fan status etc.) from/to a Mitsubishi Heavy Industries (MHI) air conditioner (AC) via SPI controlled by MQTT
MIT License
253 stars 58 forks source link

MHI SRK20MA-S model #188

Closed MrC0nst closed 1 month ago

MrC0nst commented 2 months ago

Good day, everyone! I am trying to connect my AC to mqtt. But faced with some problems.

To Reproduce Name of my AC: MHI SRK20MA-S (indoor unit) / SRC20MA-S (outdoor unit) Used MHI-AC-Ctrl HW: Wemos D1 mini (8266), ESP32 Devkit. With and without level shifter (4 channels, bi-directional. Same as in BOM file) Used MHI-AC-Ctrl SW: MHI-AC-Ctrl v2.8

Describe the bug The AC board initially did not have CNS connector but this was easily resolved with iron: board_bottom board_top

All componets from bottom side of PCB are on place. Motherboard almost same as https://github.com/absalom-muc/MHI-AC-Ctrl/issues/149

First problem is low SCK frequency 2720Hz

Starting MHI-AC-Ctrl v2.8
CPU frequency[Hz]=80000000
ESP.getCoreVersion()=3.1.2
ESP.getSdkVersion()=2.2.2-dev(38a443e)
ESP.checkFlashCRC()=1
Measure frequency for SCK, MOSI and MISO pin
SCK frequency=2720Hz (expected: >3000Hz) out of range!
MOSI frequency=392Hz (expected: <SCK frequency) o.k.
MISO frequency=0Hz (expected: ~0Hz) o.k.

The second problem is that I cannot control the air conditioner, but only receive data from it mqtt

Some debug logs: console_framesize20.txt console_framesize33.txt mhi-ac-trace.txt spi_logger.txt

Additional devices available:

Technical manual for my AC: Technical_Manual_srk20mas.pdf

glsf91 commented 2 months ago

Only try first framesize 20. You have already a lot of errors there (but with 33 a lot more). Take a look with the logic analyser if the frames/bytes looks right. Here you can find a description of the timings: https://github.com/absalom-muc/MHI-AC-Trace/blob/main/SPI.md

If you use saleae Logic software, add an SPI analyzer and you can use the following settings: spi1

The settings for MOSI, MISO and Clock are depending on your channel connection with the board of course. In the picture you see the first 3 bytes of the frame. I use 200kHz sampling.

MOSI is coming from AC. MISO is created by the mhi-ac-ctrl board/software. Try to capture from the start of the software (hold reset, start capture and release reset after a few seconds) . Also capture debug logging at the same time. Hopefully it will pickup the first frame at the right point. It takes sometime some retries :-) It will take some time before the MISO shows up. And then a lot of scrolling to take a look :-)

MrC0nst commented 2 months ago

I acquired this AC in spring 2014, but this is year 2011 model (based on motherboard labels and technical documentation from 1st post). Maybe protocol in this AC is a test | draft version and not all attributes and values are encoded-decoded right? logic

I noticed that when setting the fan speed using the IR remote control, the data is almost instantly displayed in the MQTT. But if you change other settings, there may be a delay of up to 6 seconds to update values.

log1.log log1.sal.txt log2.log log2.sal.txt

glsf91 commented 2 months ago

Please compile for a CPU frequency of 160MHz instead of 80 MHz and try again. Do not use a ESP32 if this is the case. Check if the SCK frequency is not out of range anymore or there are less -4 errors.

Do you also use the PCB from Hardware.md ? If no, please show a picture of your "PCB".

I see the timings are a bit different then my AC (SRK xx ZS-W). A time ago some stuff with sending MISO has changed. So you can also give V2.6 with the old MISO sending stuff a try if this will do a better job for you.

MrC0nst commented 2 months ago

CPU frequency is 160MHz now but SCK is still low 2560

Starting MHI-AC-Ctrl v2.6
CPU frequency[Hz]=160000000
ESP.getCoreVersion()=3.1.2
ESP.getSdkVersion()=2.2.2-dev(38a443e)
ESP.checkFlashCRC()=1
Measure frequency for SCK, MOSI and MISO pin
SCK frequency=2560Hz (expected: >3000Hz) out of range!
MOSI frequency=368Hz (expected: <SCK frequency) o.k.
MISO frequency=0Hz (expected: ~0Hz) o.k.

Wires length is about 20 cm between AC and ESP, colored wires are connected to logic analyzer (12 cm wires max). esp_b esp_f

I am still facing with loop errors -4, -2 and -1. I added additional debug output to the code. This example below shows that there was a delay of almost 20 seconds when pressing the power button on the remote control:

 Current millis is 97083
  [DB0]  0100 1001 
  [DB1]  0000 0000 
  [DB2]  0011 1100 
  [DB3]  1010 1000 
  [DB4]  0000 0000 
  [DB5]  0000 0000 
  [DB6]  1000 1000 
  [DB7]  0000 0000 
  [DB8]  1111 1111 
  [DB9]  1111 1111 
  [DB10] 1111 1111 
  [DB11] 1111 1111 
  [DB12] 1111 1111 
  [DB13] 0000 0001 
  [DB14] 0000 0000 
status=64 topic=Power payload=on
mhi_ac_ctrl_core.loop error: -4
mhi_ac_ctrl_core.loop error: -4
mhi_ac_ctrl_core.loop error: -4
mhi_ac_ctrl_core.loop error: -4
mhi_ac_ctrl_core.loop error: -4
mhi_ac_ctrl_core.loop error: -4
mhi_ac_ctrl_core.loop error: -4

 Current millis is 115813
  [DB0]  0100 1001 
  [DB1]  0000 0000 
  [DB2]  0011 1100 
  [DB3]  1010 0101 
  [DB4]  0000 0000 
  [DB5]  0000 0000 
  [DB6]  1000 1000 
  [DB7]  0000 0000 
  [DB8]  1111 1111 
  [DB9]  1111 1111 
  [DB10] 1111 1111 
  [DB11] 1111 1111 
  [DB12] 1111 1111 
  [DB13] 0000 0001 
  [DB14] 0000 0000 

I also checked the main modes of the air conditioner and they completely coincide with the described protocol. But the air conditioner control doesn't work ;-((( states.txt

 Current millis is 115222
  [DB0]  0100 1000 
  [DB1]  0000 0000 
  [DB2]  0011 1100 
  [DB3]  1010 1000 
  [DB4]  0000 0000 
  [DB5]  0000 0000 
  [DB6]  1000 1000 
  [DB7]  0000 0000 
  [DB8]  1111 1111 
  [DB9]  1111 1111 
  [DB10] 1111 1111 
  [DB11] 1111 1111 
  [DB12] 1111 1111 
  [DB13] 0000 0000 
  [DB14] 0000 0000 
MQTT_subscribe_callback, topic=MHI-AC-Ctrl/set/Mode payload=heat payload_length=4
status=64 topic=cmd_received payload=o.k.

 Current millis is 115332
  [DB0]  0100 1000 
  [DB1]  0000 0000 
  [DB2]  0011 1100 
  [DB3]  1010 0111 
  [DB4]  0000 0000 
  [DB5]  0000 0000 
  [DB6]  1000 1000 
  [DB7]  0000 0000 
  [DB8]  1111 1111 
  [DB9]  1111 1111 
  [DB10] 1111 1111 
  [DB11] 1111 1111 
  [DB12] 1111 1111 
  [DB13] 0000 0000 
  [DB14] 0000 0000 

 Current millis is 115387
  [DB0]  0100 1000 
  [DB1]  0000 0000 
  [DB2]  0011 1100 
  [DB3]  1010 1000 
  [DB4]  0000 0000 
  [DB5]  0000 0000 
  [DB6]  1000 1000 
  [DB7]  0000 0000 
  [DB8]  1111 1111 
  [DB9]  1111 1111 
  [DB10] 1111 1111 
  [DB11] 1111 1111 
  [DB12] 1111 1111 
  [DB13] 0000 0000 
  [DB14] 0000 0000 

 Current millis is 115553
  [DB0]  0100 1000 
  [DB1]  0000 0000 
  [DB2]  0011 1100 
  [DB3]  1010 1001 
  [DB4]  0000 0000 
  [DB5]  0000 0000 
  [DB6]  1000 1000 
  [DB7]  0000 0000 
  [DB8]  1111 1111 
  [DB9]  1111 1111 
  [DB10] 1111 1111 
  [DB11] 1111 1111 
  [DB12] 1111 1111 
  [DB13] 0000 0000 
  [DB14] 0000 0000 
glsf91 commented 1 month ago

That's a pitty. It is better to use a level shifter on MISO, MOSI and SCK lines. Adding this print debug can cause more errors because of the timing by the way.

The ESP is following the SCK line to determine the MOSI byte (and create the MISO byte). The -4 error indicates it is not detecting an expected falling edge on the SCK line on time in the frame. That means the SCK is detected "damaged". Maybe there is some noise on the SCK line. Maybe you can see this with an Oscilloscope.

In the logic analyzer file from previous post I saw the SCK is a lot if times only 5 uS low. With my AC this is 15-20uS. So maybe this is too critical. Detecting the SCK frequency at boot is done with interrupts (different from normal operation). When I look into your logic analyzer file you should see a SCK freq of about 2880 Hz. So you are missing rising edges because of noise or timing to critical.

MrC0nst commented 1 month ago

Hi glsf91

It is better to use a level shifter on MISO, MOSI and SCK lines. I redesigned the board and added back the level shifter: board also mute function was added (I'll check later). Moved back to v2.8

Currently data exchange only works in one direction from AC to ESP. If I try to change the air conditioner settings through the Home Assistant, nothing happens. Only an error appears in the MQTT mqtt How to determine whether the request reaches the air conditioner or not? Which module responds with error cmd_received = invalid parameter?

glsf91 commented 1 month ago

Error means your mqtt command is not right. In this case fan_only is not allowed. See sw_configutation.md

On Sat, May 25, 2024, 00:11 Constantine @.***> wrote:

Hi glsf91

It is better to use a level shifter on MISO, MOSI and SCK lines. I redesigned the board and added back the level shifter: board.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/ea5a9911-686c-45fa-a507-fb8ea537fa5d also mute function was added (I'll check later). Moved back to v2.8

Currently data exchange only works in one direction from AC to ESP. If I try to change the air conditioner settings through the Home Assistant, nothing happens. Only an error appears in the MQTT mqtt.png (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/03a87534-283e-4976-b2c0-ced17259ff04 How to determine whether the request reaches the air conditioner or not? Which module responds with error 221 cmd_received = invalid parameter?

— Reply to this email directly, view it on GitHub https://github.com/absalom-muc/MHI-AC-Ctrl/issues/188#issuecomment-2130429403, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH6YXS5R634GAUWISRXJYILZD63IJAVCNFSM6AAAAABH6QGH4OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZQGQZDSNBQGM . You are receiving this because you commented.Message ID: @.***>

MrC0nst commented 1 month ago

Oscilograms:

SCK

sck_1 sck_2 sck_3 sck_4

MOSI

mosi_1 mosi_2 mosi_3

MISO

miso_1 miso_2 miso_3 miso_4

SCK (1-Y) and MOSI(2-G)

sck_mosi_1 sck_mosi_2

SCK(1-Y) and MISO(2-G)

sck_miso_1 sck_miso_2 sck_miso_3 sck_miso_4

Seems like MISO from AC side is pulled to 3v because unconnected pin HV2 has 5V from ESP8266 side. I need to find out whether the air conditioner receives signal packets from the ESP. Is there any way to create a deliberately incorrect packet so that the air conditioner reports an error in any way?

glsf91 commented 1 month ago

As far as I know the ac will not report an error when sending a wrong packet. What do you mean with an unconnected hv2 pin? According to the hardware design there is no unconnected pin.

On Sat, May 25, 2024, 13:57 Constantine @.***> wrote:

Oscilograms: SCK

sck_1.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/af575dd5-f301-49d4-91f9-d01584061aa7 sck_2.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/06546694-a9e1-4343-88df-5ce278b15a54 sck_3.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/5275f93b-3af4-45e3-8d43-54a07b42a34c sck_4.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/0ee4f746-e756-4bf6-8ebc-8e35406331d5 MOSI

mosi_1.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/33baee50-fbea-410a-b541-743a60dce468 mosi_2.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/cc3f1d96-0359-4be0-8ee6-164f174c37c4 mosi_3.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/eecd15c9-9dd5-4d53-a50e-15889f49838b MISO

miso_1.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/86cc3cb7-d22a-4540-ba39-9a3c80803685 miso_2.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/fa8f57da-0e72-4b90-94c5-64dc5d5a865b miso_3.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/aa458ca4-b698-4a54-95aa-3eb2525e8056 miso_4.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/e321bd95-c01e-4a28-b16c-98924e63b62e SCK (1-Y) and MOSI(2-G)

sck_mosi_1.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/06656c85-eb51-4067-84a5-91601aad4d77 sck_mosi_2.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/8840d842-2596-416f-960b-cd7d81b34f06 SCK(1-Y) and MISO(2-G)

sck_miso_1.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/3b521eb0-1d54-486a-a58a-25063e4b1243 sck_miso_2.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/744d7ab7-fc8d-4b7a-b40c-3c085823e42a sck_miso_3.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/6c43814e-00d0-4155-93ae-9cfbb7712b88 sck_miso_4.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/bb4ad48f-49c4-4322-9542-32bead69e459

Seems like MISO from AC side is pulled to 3v because unconnected pin HV2 has 5V from ESP8266 side. I need to find out whether the air conditioner receives signal packets from the ESP. Is there any way to create a deliberately incorrect packet so that the air conditioner reports an error in any way?

— Reply to this email directly, view it on GitHub https://github.com/absalom-muc/MHI-AC-Ctrl/issues/188#issuecomment-2131229742, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH6YXS3J66MBCIPCTAQV6JLZEB4A3AVCNFSM6AAAAABH6QGH4OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZRGIZDSNZUGI . You are receiving this because you commented.Message ID: @.***>

MrC0nst commented 1 month ago

What do you mean with an unconnected hv2 pin? If you cut wire X1-2_J2.2 at the red mark, then at pin J2.2 there will be a signal with an amplitude of 5 volts. Or connect J1.6 to JP1.5 with a blue marked wire and take measurements at pin J2.6 (Connected it to make sure the level shifter is working correctly) new_schematic

With default circuit i have MISO amplitude of 3 volts only. Measured at MSIO PIN on X1 Connector (X1-2) miso_2

MrC0nst commented 1 month ago

After switching to the level shifter using an optocoupler, the voltage amplitude now reaches 5 volts. But the air conditioner does not follow commands. What additional steps can be taken to establish two-way communication?

SCK(1-Y) and MISO(2-G) sck_miso_5 sck_miso_6

glsf91 commented 1 month ago

what happens if the ac is turned on bij de rc and you send the power off command to mqtt? Also check the topic cmd_received says ok after command to make sure your command is ok. Or check debug log.

On Sun, May 26, 2024, 08:56 Constantine @.***> wrote:

After switching to the level shifter using an optocoupler, the voltage amplitude now reaches 5 volts. But the air conditioner does not follow commands. What additional steps can be taken to establish two-way communication?

SCK(1-Y) and MISO(2-G) sck_miso_5.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/cb2f2335-bb6e-496e-995c-61963649c9b7 sck_miso_6.jpg (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/9369f7e9-0900-466a-9b25-48806eb0e080

— Reply to this email directly, view it on GitHub https://github.com/absalom-muc/MHI-AC-Ctrl/issues/188#issuecomment-2132093745, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH6YXSYWVO24WQXUIHBWYMLZEGBQDAVCNFSM6AAAAABH6QGH4OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZSGA4TGNZUGU . You are receiving this because you commented.Message ID: @.***>

MrC0nst commented 1 month ago

what happens if the ac is turned on bij de rc and you send the power off command to mqtt? Nothing changes. The air conditioner continues to operate, the command status is cmd_received = o.k. mqtt_on mqtt_off

glsf91 commented 1 month ago

hmmm. maybe because your ac is that old and had no connector on the pcb, it has no option to receive commands. Or has a different MISO. Normally you take another MHI device and take a look with a logic analyzer. But thats is not possible here.

On Sun, May 26, 2024, 10:23 Constantine @.***> wrote:

what happens if the ac is turned on bij de rc and you send the power off command to mqtt? Nothing changes. The air conditioner continues to operate, the command status is cmd_received = o.k. mqtt_on.png (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/4d3d06bc-42c8-463a-a8c8-c1d1af66619d mqtt_off.png (view on web) https://github.com/absalom-muc/MHI-AC-Ctrl/assets/75075223/88beaad1-d4c5-40f9-b282-03cbe0c1eb5e

— Reply to this email directly, view it on GitHub https://github.com/absalom-muc/MHI-AC-Ctrl/issues/188#issuecomment-2132133192, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH6YXS6M7KJOP2KUD6PATZ3ZEGLYLAVCNFSM6AAAAABH6QGH4OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZSGEZTGMJZGI . You are receiving this because you commented.Message ID: @.***>

MrC0nst commented 1 month ago

I think the issue can be closed. Data can only be read from the air conditioner. I will control my AC by sending a signal directly to the TSOP data pin. PS: IR protocol is not reverse engineered yet. Well known are RKX502A001C remote (88 bit) and RLA502A700B remote (152 bit) https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_MitsubishiHeavy.h Mine is 106 bit