atxbyea / samsungrac

Home Assistant Climate Device for controlling (not only) Samsung AC
60 stars 18 forks source link

Obtain Token #4

Open thadius83 opened 3 years ago

thadius83 commented 3 years ago

Wondering if you had any luck with getting the token guide?

I've got a MIM-H03 wifi unit, runs on port 8888, however none of the scripts out there seem to work for obtaining the token, I get nothing back.

Able to connect it to the SmartThings App etc, but I'm after local control.

atxbyea commented 3 years ago

I'll try to make a guide when I get some free time, I did it almost two years ago, so need to look into it @thadius83

thadius83 commented 3 years ago

If it makes any difference, the MIM-H03 is connected to a central system rather than the wall mount reverse cycle systems.

I can send curl commands and receive invalid token when querying data but the acdc method and the server8889 and curl request with a token id of xxxxxxxx return nothing

I guess the question here is has anyone got this working with a central system rather than the typical wall mount reverse cycle?

ishioni commented 3 years ago

I have a script that I picked up from someone, I could polish it up and include it + some simple docs on how to use it, it should then spit out the token painlessly for people

atxbyea commented 3 years ago

nice @ishioni I was thinking of building a docker container with the correct dependencies for it, but if you already have something working that'll be grand.

thadius83 commented 3 years ago

I have a script that I picked up from someone, I could polish it up and include it + some simple docs on how to use it, it should then spit out the token painlessly for people

That would be fantastic

I'm starting to wonder if it's because I'm using a central air unit rather than a split system. But I would have thought it's the MIM that provides the tokens

I get multicast SSDP traffic from the MIM unit, containing generic info, but when using the server/request script and even acdc nothing but black.

atxbyea commented 3 years ago

any update on your progress @ishioni ?

ishioni commented 3 years ago

Hey sorry for the delay. I couldn't find the time, and now because of a stupid mistake i burned my swl-qc51 module :( (by applying 12V to the reset line) I'll get a replacement around February unless someone points me to a trusted european source

atxbyea commented 3 years ago

Great, thanks for the feedback @ishioni

ascl00 commented 3 years ago

Any chance you could post the raw script in the mean time? I have the same MIM-H03 and have not found a way to get the auth token, and am happy to dig through a messy script to find the answers.

jjprz commented 3 years ago

here you can get the token: https://account.smartthings.com/tokens

ishioni commented 3 years ago

No, that's ^ not the one you need

@atxbyea I'm attaching what I more-or-less used and what I wanted to integrate into my pysamsungrac library. You need to run the curl in the comment, then run this script, then turn on the AC unit (or off/on if it was on). I only verified it with 8888 devices. However, I'll be abandoning the project completely, since not only did I burn my wifi module, but I'm moving from my house where it's installed, and I certainly am not taking it with me, and I'll aim to never buy an unsupported-ootb AC unit again ;)

Sorry to disappoint. I wanted to make a new integration and a personal project out of this, but life is a bitch and family is a full-time job :)

from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl

"""
curl -X POST -d -v -k --cert ac14k_m.pem --insecure https://10.1.2.3:8888/devicetoken/request
"""

class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        request_path = self.path

        print("\n----- Request Start ----->\n")
        print("Request path:", request_path)
        print("Request headers:", self.headers)
        print("<----- Request End -----\n")

        self.send_response(200)
        self.send_header("Set-Cookie", "foo=bar")
        self.end_headers()

    def do_POST(self):
        request_path = self.path

        print("\n----- Request Start ----->\n")
        print("Request path:", request_path)

        request_headers = self.headers
        content_length = request_headers.get('Content-Length')
        length = int(content_length) if content_length else 0
        #body = self.body

        print("Content Length:", length)
        print("Request headers:", request_headers)
        print("Request payload:", self.rfile.read(28))
        print("Body:", self)
        print("<----- Request End -----\n")

        self.send_response(200)
        self.end_headers()

    do_PUT = do_POST
    do_DELETE = do_GET

def main():
    port = 8889
    print('Listening on localhost:%s' % port)
    server = HTTPServer(('', port), RequestHandler)
    server.socket = ssl.wrap_socket(server.socket, certfile='pysamsungrac/ac14k_m.pem', server_side=True)
    server.serve_forever()

if __name__ == "__main__":
    main()
ascl00 commented 3 years ago

Thanks for posting this, I'll give it a shot at some point, although it looks pretty similar to what I have previously tried. I'm totally with you on not buying a supported AC again. I'm very disappointed with this crappy wifi control unit.

ishioni commented 3 years ago

@ascl00 If someone wants to move this forward, feel free to start from this https://github.com/ishioni/pysamsungrac

jjprz commented 3 years ago

I can't get the token, it doesn't seem to listen to anything on port 8889. What is the use of the token I returned at https://account.smartthings.com/tokens?

I have a MIM-H03N device and it seems that from the API I can only turn the device on or off, I cannot access the settings of the indoor unit.

Screenshot_20210312-002816_opt MIM-H03N

Screenshot_20210312-002825_opt indoor unit where you can choose temperature and various settings

if I make a call with the smartthings token to https: //api.smartthings.com/v1/devices/XXXX-XXXX-XX ... it returns me. As you can see, everything is null except the switch

{ "components": { "main": { "refresh": {}, "airConditionerMode": { "supportedAcModes": { "value": null, "timestamp": "2021-03-08T09:52:20.895Z" }, "airConditionerMode": { "value": null, "timestamp": "2021-03-08T09:52:20.895Z" } }, "execute": { "data": { "value": null, "data": {}, "timestamp": "2021-03-08T09:52:20.877Z" } }, "airQualitySensor": { "airQuality": { "value": null, "unit": "CAQI", "timestamp": "2021-03-08T09:52:12.679Z" } }, "switch": { "switch": { "value": "off", "timestamp": "2021-03-11T22:00:56.411Z" } }, "ocf": { "st": { "value": null, "timestamp": "2021-03-08T10:12:49.838Z" }, "mndt": { "value": null, "timestamp": "2021-03-08T10:12:48.117Z" }, "mnfv": { "value": null, "timestamp": "2021-03-08T10:12:39.375Z" }, "mnhw": { "value": null, "timestamp": "2021-03-08T10:12:36.834Z" }, "mnsl": { "value": null, "timestamp": "2021-03-08T10:11:53.306Z" }, "dmv": { "value": "res.1.1.0,sh.1.1.0", "timestamp": "2021-03-08T09:52:12.174Z" }, "n": { "value": "A/A Salón", "timestamp": "2021-03-08T15:13:21.042Z" }, "mnmo": { "value": "MIM-H03N", "timestamp": "2021-03-08T09:52:12.174Z" }, "mnmn": { "value": "Samsung Electronics", "timestamp": "2021-03-08T09:52:12.174Z" }, "mnml": { "value": null, "timestamp": "2021-03-08T10:11:50.068Z" }, "mnpv": { "value": null, "timestamp": "2021-03-08T10:11:49.512Z" }, "mnos": { "value": null, "timestamp": "2021-03-08T10:09:42.182Z" }, "pi": { "value": "shp", "timestamp": "2021-03-08T10:09:41.775Z" }, "icv": { "value": "core.1.1.0", "timestamp": "2021-03-08T09:52:12.174Z" } }, "odorSensor": { "odorLevel": { "value": null, "timestamp": "2021-03-08T10:12:49.983Z" } }, "airConditionerFanMode": { "fanMode": { "value": null, "timestamp": "2021-03-08T09:58:58.710Z" }, "supportedAcFanModes": { "value": null, "timestamp": "2021-03-08T09:58:58.710Z" } }, "custom.disabledCapabilities": { "disabledCapabilities": { "value": [ "airConditionerMode", "airConditionerFanMode", "temperatureMeasurement", "thermostatCoolingSetpoint", "airQualitySensor", "dustSensor", "odorSensor" ], "timestamp": "2021-03-08T09:52:12.215Z" } }, "samsungce.driverVersion": { "versionNumber": { "value": 20090701, "timestamp": "2021-03-08T09:52:12.215Z" } }, "temperatureMeasurement": { "temperature": { "value": null, "timestamp": "2021-03-08T09:58:58.100Z" } }, "dustSensor": { "dustLevel": { "value": null, "unit": "μg/m^3", "timestamp": "2021-03-08T09:52:23.600Z" }, "fineDustLevel": { "value": null, "unit": "μg/m^3", "timestamp": "2021-03-08T09:52:23.600Z" } }, "thermostatCoolingSetpoint": { "coolingSetpoint": { "value": null, "timestamp": "2021-03-08T09:52:12.642Z" } } } } }

Does anyone know how I can access the settings of the indoor unit? I have to get the token that you indicate?

Poncharello commented 3 years ago

I can't get the token, it doesn't seem to listen to anything on port 8889. What is the use of the token I returned at https://account.smartthings.com/tokens?

I have a MIM-H03N device and it seems that from the API I can only turn the device on or off, I cannot access the settings of the indoor unit.

Screenshot_20210312-002816_opt MIM-H03N

Screenshot_20210312-002825_opt indoor unit where you can choose temperature and various settings

if I make a call with the smartthings token to https: //api.smartthings.com/v1/devices/XXXX-XXXX-XX ... it returns me. As you can see, everything is null except the switch

{ "components": { "main": { "refresh": {}, "airConditionerMode": { "supportedAcModes": { "value": null, "timestamp": "2021-03-08T09:52:20.895Z" }, "airConditionerMode": { "value": null, "timestamp": "2021-03-08T09:52:20.895Z" } }, "execute": { "data": { "value": null, "data": {}, "timestamp": "2021-03-08T09:52:20.877Z" } }, "airQualitySensor": { "airQuality": { "value": null, "unit": "CAQI", "timestamp": "2021-03-08T09:52:12.679Z" } }, "switch": { "switch": { "value": "off", "timestamp": "2021-03-11T22:00:56.411Z" } }, "ocf": { "st": { "value": null, "timestamp": "2021-03-08T10:12:49.838Z" }, "mndt": { "value": null, "timestamp": "2021-03-08T10:12:48.117Z" }, "mnfv": { "value": null, "timestamp": "2021-03-08T10:12:39.375Z" }, "mnhw": { "value": null, "timestamp": "2021-03-08T10:12:36.834Z" }, "mnsl": { "value": null, "timestamp": "2021-03-08T10:11:53.306Z" }, "dmv": { "value": "res.1.1.0,sh.1.1.0", "timestamp": "2021-03-08T09:52:12.174Z" }, "n": { "value": "A/A Salón", "timestamp": "2021-03-08T15:13:21.042Z" }, "mnmo": { "value": "MIM-H03N", "timestamp": "2021-03-08T09:52:12.174Z" }, "mnmn": { "value": "Samsung Electronics", "timestamp": "2021-03-08T09:52:12.174Z" }, "mnml": { "value": null, "timestamp": "2021-03-08T10:11:50.068Z" }, "mnpv": { "value": null, "timestamp": "2021-03-08T10:11:49.512Z" }, "mnos": { "value": null, "timestamp": "2021-03-08T10:09:42.182Z" }, "pi": { "value": "shp", "timestamp": "2021-03-08T10:09:41.775Z" }, "icv": { "value": "core.1.1.0", "timestamp": "2021-03-08T09:52:12.174Z" } }, "odorSensor": { "odorLevel": { "value": null, "timestamp": "2021-03-08T10:12:49.983Z" } }, "airConditionerFanMode": { "fanMode": { "value": null, "timestamp": "2021-03-08T09:58:58.710Z" }, "supportedAcFanModes": { "value": null, "timestamp": "2021-03-08T09:58:58.710Z" } }, "custom.disabledCapabilities": { "disabledCapabilities": { "value": [ "airConditionerMode", "airConditionerFanMode", "temperatureMeasurement", "thermostatCoolingSetpoint", "airQualitySensor", "dustSensor", "odorSensor" ], "timestamp": "2021-03-08T09:52:12.215Z" } }, "samsungce.driverVersion": { "versionNumber": { "value": 20090701, "timestamp": "2021-03-08T09:52:12.215Z" } }, "temperatureMeasurement": { "temperature": { "value": null, "timestamp": "2021-03-08T09:58:58.100Z" } }, "dustSensor": { "dustLevel": { "value": null, "unit": "μg/m^3", "timestamp": "2021-03-08T09:52:23.600Z" }, "fineDustLevel": { "value": null, "unit": "μg/m^3", "timestamp": "2021-03-08T09:52:23.600Z" } }, "thermostatCoolingSetpoint": { "coolingSetpoint": { "value": null, "timestamp": "2021-03-08T09:52:12.642Z" } } } } }

Does anyone know how I can access the settings of the indoor unit? I have to get the token that you indicate?

Same here. I have a MIM-H03 wifi controller and it seems impossible to get the token, with actest.py I get no answer on port 8889. This token is driving me crazy.

ascl00 commented 3 years ago

I need to do a packet capture from the A/C after restarting it and sending a token request, but it's annoying to have to go outside, flip the fuse to reboot the A/C! Definitely cuts down on my drive to solve this.

thadius83 commented 3 years ago

I need to do a packet capture from the A/C after restarting it and sending a token request, but it's annoying to have to go outside, flip the fuse to reboot the A/C! Definitely cuts down on my drive to solve this.

Can you confirm that you have a central aircon / zone based Samsung aircon / in roof cassette with the condenser and fans outside, and a hardwired wall controller like the following

And you get the correct token by power cycling the OUTDOOR unit ? Not the wall controller? (Of course via wireshark - that's all fine)

A in roof setup like the bottom photo (without the wall mounted outlet)

Because if that's the case I feel like a right idiot as that's the only thing I didn't do - power cycle the condenser and fan unit outside.

image

image

ascl00 commented 3 years ago

Well, I wouldn't take my comments as anything gospel about anything, as I am also unable to get a token. That said, yes, I have the setup as you describe. From the wiring diagram, the controller should be powered by the in-roof unit, so should be powered by the same fuse as the outside unit. I guess it is possible this isn't the case in your setup, but I believe it is for me (I have 3 phase power, with a dedicated phase for the A/C -- although now you have flagged this, I will actually test this theory, be kinda silly if this assumption screwed me over!).

You are correct in that power-cycling the outdoor unit should make no difference what-so-ever, it should be power cycling the control unit that matters. I did try using the reset button inside the control unit but couldn't get that working either, although maybe I'll revisit that one as it is much easier than going outside to the fuse box!

valdenny commented 3 years ago

Hi, I don't know if it can be useful to you. I had obtained my MIM-H03 token following a thread on the OpenHub forum. I report it here "copy and paste" of the text: P..S. Before step 1 Power off the AC and MIM-H03 from differential magnetothermic At step 3 Power on from differential magnetothermic (mim-h03 needs to reboot)

  1. step: python3 server.py
  2. step: another terminal: python3 actest.py
  3. step: power on the Samsung AC

From: https://community.openhab.org/t/newgen-samsung-ac-protocol/33805/22

ascl00 commented 3 years ago

Hitting the reset button does appear to cause a reboot of the device. Doing a packet capture I see it re-negotiating its IP address via DHCP, and registering with api.smartthings.com.... but sending the port 8888 request just does nothing. The request succeeds with an HTTP 200, but there is no outbound traffic from the A/C controller.

I wonder if this a firmware version thing?

atxbyea commented 3 years ago

Unfortunatly I only have a 2878 device, so I have never tried to get any other device to work, just forked the existing product, that used to work with those other products atleast...

Poncharello commented 3 years ago

Hi, I don't know if it can be useful to you. I had obtained my MIM-H03 token following a thread on the OpenHub forum. I report it here "copy and paste" of the text: P..S. Before step 1 Power off the AC and MIM-H03 from differential magnetothermic At step 3 Power on from differential magnetothermic (mim-h03 needs to reboot)

  1. step: python3 server.py
  2. step: another terminal: python3 actest.py
  3. step: power on the Samsung AC

From: https://community.openhab.org/t/newgen-samsung-ac-protocol/33805/22

This is what I have done: 1) From the original actest.py I got this error:

/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:1013: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.178.127'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

warnings.warn(

so I added to the file the following lines (to skip ssl warnings):

import certifi import urllib3 urllib3.disable_warnings()

2) after that it seemed to work, I powered ON the differential magnetothermic, but after a while I always get a "connection refused" error:

MBP-di-Mattia:downloads macbookprodimattia$ python3 actest.py Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 169, in _new_conn conn = connection.create_connection( File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 96, in create_connection raise err File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 86, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 382, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn conn.connect() File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 353, in connect conn = self._new_conn() File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 181, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x105533250>: Failed to establish a new connection: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen retries = retries.increment( File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 574, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.178.127', port=8888): Max retries exceeded with url: /devicetoken/request (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x105533250>: Failed to establish a new connection: [Errno 61] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/macbookprodimattia/Downloads/actest.py", line 7, in resp = s.post("https://192.168.178.127:8888/devicetoken/request", data={"DeviceToken":"xxxxxxxxxxx"}, headers=headers, stream=True, verify=False, cert='cert.pem') File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 590, in post return self.request('POST', url, data=data, json=json, kwargs) File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 655, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='192.168.178.127', port=8888): Max retries exceeded with url: /devicetoken/request (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x105533250>: Failed to establish a new connection: [Errno 61] Connection refused'))

On the server.py terminal no sign of activity (obviously). I'm quite running out of ideas.

EDIT: I got the same "connection refused error" also with the original actest.py file

ascl00 commented 3 years ago

The connection refused will happen while the controller is starting up, before it is ready to accept connections, that is, I think, expected (or at least not unusual for a device starting up). You may need to delay the start actest.py or increase the number of retries.

I have been experimenting a bit with various URLs and capturing packets, and I am quite suspicious that I am using the correct URL. If I send a POST request to, say, https://192.168.xxx.xxx:8888/devicetoken/foo I get a 200 OK response. Any POST request that starts with '/devicetoken' returns 200 OK regardless of what follows, and any PUT request establishes a connection and just waits, and any GET request I either get 404 (file not found) or 401 (unauthorised). Nothing I have done has triggered the controller to attempt a connection anywhere (although I do see it talking to the smart things servers on startup).

Poncharello commented 3 years ago

Thanks for your reply @ascl00 I tried to start the actest.py with various delays after power ON, but still no success. Maybe it's a firmware version "issue", as you have suggested before. The label says that my MIM-H03 was manufactured 2019/10, but no info regarding the FW version is reported. On the box there's a label stating "Samsung SmartThings support", so I guess that the FW is quite recent. Maybe the communication on ports 8888/8889 is no longer working with SmartThings compatibility...

valdenny commented 3 years ago

Try to hard reset MIM-H03 by holding down the AP key of the MIM-H03 for more than 3 seconds. I too have had difficulties and have made dozens of attempts. then miraculously it worked.

Poncharello commented 3 years ago

Hi @valdenny, I made it!!! I pushed the reset button (after trying with the AP key with no success) on the device, waited about 10 seconds and then hit enter to start actest.py After the device reboot, the led "AP" was flashing and at this point I got the response on server.py!!!

Schermata 2021-03-23 alle 19 57 05

Now the climate control is working, but I can only set one out of two consoles (I own 2 floor consoles connected to the wifi controller). During the A/C installation, I set up 2 different addresses for the consoles by adjusting the RMC switch. Soooo my last question is: how to control the second console?

From the SmartThings app I can see (and adjust) both consoles independently.

Thank you guys, your help was really precious to me.

EDIT: from the HA log I found that console "1" ID is 032001000, console "2" ID is 032001001 Do I need to edit mim-h03_heatpump.yaml file? My idea is to create a 2nd yaml file with ID 032001001, and then add to configuration.yaml another "climate_ip" section pointing to it to create a 2nd entity to control console 2.

valdenny commented 3 years ago

@Poncharello Great!!! Now you can do one thing for the community: Describe exactly the steps you took for the MIM-H03 so that @atxbyea can document it and take another step towards closing this issue! :) About your situation, I refer you to another issue that I had opened. https://github.com/atxbyea/samsungrac/issues/13 At the bottom of thread you find my file mim-h03-v3.0.25.yaml.txt

jjprz commented 3 years ago

@Poncharello marvelous!! Can you describe the steps you did? When performing these steps do you have to re-link the device in Smartthings app?

Poncharello commented 3 years ago

I would be happy to help the community :) These are the steps I performed: 1) step: python3 server.py on 1st terminal window 2) I tried to hold down for a few seconds the AP key (as suggested by @valdenny), but the device did not reset. The wifi LED turned off and AP LED turned on. I really don't know if this step is related to the final result, but actest.py timed out with no response on port 8889 3) At this point I tried to focus on the reset button of the device, so I pushed it and I counted to 10 in my mind to allow time for reboot 4) step: python3 actest.py on 2nd terminal window 5) after reboot, I noticed that AP LED was blinking, wifi LED was off (from MIM-H03 user manual, this means "requesting a token - AP mode") 6) I looked at server.py terminal and I noticed the response with the token (please note that in the actest.py window I got a timeout error anyway!)

@valdenny I forgot to say that I am already using your modified yaml file @jjprz no, I didn't have to re-link the device in Smartthings, it is still working

valdenny commented 3 years ago

Great. To manage the two consoles you need to create 2 different mim-h03-v3.0.25.yaml files. The difference between the files is only in the ID of the indoor unit: "032001000" and "032001001" Then enter this line in the configuration.yaml: e.g.

climate:

ascl00 commented 3 years ago

@Poncharello that's interesting, so you held down the AP key, which I think should reset the device to "Access Point" mode and not connect to wifi, but then you hit reset and it connected to wifi?

It's great you got it working, and also good to know that hitting reset is enough and powercycling is unnecessary. I tried your sequence of events without luck, but it gives me some hope :)

ascl00 commented 3 years ago

OMG! 14:09:30.390522 IP 192.168.2.90.56862 > 192.168.2.1.8889: Flags [S], seq 1834935374, win 5840, options [mss 1460,sackOK,TS val 715007 ecr 0,nop,wscale 2], length 0 14:09:30.390797 IP 192.168.2.1.8889 > 192.168.2.90.56862: Flags [R.], seq 0, ack 1834935375, win 0, length 0

Finally! I see packets sent to the right port! Now using the script I can capture a device token!

The key was definitely pressing the AP button. It seems inconsistent and unreliable, but resetting and calling the devicetoken request URL, and hitting the AP button resulted in this working for me. I had to try pressing the AP button and calling the device token request over a few times after resetting.

Thanks everyone in this thread. Key take-aways for me:

Note the lights on the controller. I think having the AP light flash indicates you need to press the AP button.

{ "Device": { "ConfigurationLink": { "href": "/devices/0/configuration" }, "InformationLink": { "href": "/devices/0/information" }, "Operation": { "dhwPower": "Off", "power": "Off", "ventilationPower": "Off" }, "Temperatures": [ { "desired": 0, "id": "0", "increment": 1, "unit": "Celsius" } ], "description": "DisableTempIncrement", "id": "0", "name": "Wifi-kit", "resources": [ "Alarms", "Operation", "Temperatures", "Information", "Configuration" ], "type": "Air_Conditioner", "uuid": "C0000000-0000-0000-0000-000000000000" } Been a long time to get here :D

Poncharello commented 3 years ago

@ascl00 I'm glad you did it too! So it seems that the AP mode is mandatory to get the token. @valdenny Thank you! In that way I can control both consoles (I only have a little issue on one of them, but I'm pretty sure it's caused by a wrong addressing. I'll check the internal switch next weekend).

thadius83 commented 3 years ago

OMG!

`14:09:30.390522 IP 192.168.2.90.56862 > 192.168.2.1.8889: Flags [S], seq 1834935374, win 5840, options [mss 1460,sackOK,TS val 715007 ecr 0,nop,wscale 2], length 0

14:09:30.390797 IP 192.168.2.1.8889 > 192.168.2.90.56862: Flags [R.], seq 0, ack 1834935375, win 0, length 0

`

Finally! I see packets sent to the right port! Now using the script I can capture a device token!

The key was definitely pressing the AP button. It seems inconsistent and unreliable, but resetting and calling the devicetoken request URL, and hitting the AP button resulted in this working for me. I had to try pressing the AP button and calling the device token request over a few times after resetting.

Thanks everyone in this thread. Key take-aways for me:

  • power cycling is not required. Pressing reset is enough

  • pressing the AP button was necessary (maybe only if you use reset vs power cycling?) for me

Note the lights on the controller. I think having the AP light flash indicates you need to press the AP button.

`{

"Device": {

"ConfigurationLink": {

  "href": "/devices/0/configuration"

},

"InformationLink": {

  "href": "/devices/0/information"

},

"Operation": {

  "dhwPower": "Off",

  "power": "Off",

  "ventilationPower": "Off"

},

"Temperatures": [

  {

    "desired": 0,

    "id": "0",

    "increment": 1,

    "unit": "Celsius"

  }

],

"description": "DisableTempIncrement",

"id": "0",

"name": "Wifi-kit",

"resources": [

  "Alarms",

  "Operation",

  "Temperatures",

  "Information",

  "Configuration"

],

"type": "Air_Conditioner",

"uuid": "C0000000-0000-0000-0000-000000000000"

}

`

Been a long time to get here :D

No way.

So, reset controller to AP mode, join laptop to the AP.

Run script, reset AP if required?

And token provided?

I'll attempt this over the weekend and confirm, I must admit this is one sequence I haven't tried

ascl00 commented 3 years ago

No full reset to AP mode. I think what happens is there are two different methods to get a device token according to the SDK documentation. An "Easy" mode which does not require user intervention, but has to happen after a restart, and a normal registration mode that requires the user to press the AP button to "prove" they are local to the device. Most of the guides suggest using the former registration method, but I could never get that working.

So, I suspect that sending the devicetoken request to the device might make the AP light flash, which I think is indicating that user intervention is required for proof of locality. This is mostly theory at this point, but for at least a few of us in this thread something along these lines has worked. Doing a reboot (via reset button push) before messing around should put you in a clean state. I ended up sending multiple requests and pushing the button multiple times, so I'm not sure on the exact order, but it doesn't seem to matter if you do either multiple times.

Poncharello commented 3 years ago

@ascl00 please note that in my sequence I did not press the AP button after reset. I pressed it only before.

ascl00 commented 3 years ago

@Poncharello - good to know, I thought I saw that behaviour as well, but wasn't sure.

erkexzcx commented 1 year ago

How to get it from AC that uses port 2878. Simple Golang application, tested with go version go1.20 linux/amd64:

package main

import (
    "crypto/tls"
    "fmt"
    "io"
    "log"
    "strings"
)

func main() {
    conn, err := tls.Dial("tcp", "192.168.0.123:2878", &tls.Config{
        MinVersion:         tls.VersionTLS10,
        InsecureSkipVerify: true,
    })
    if err != nil {
        log.Fatal(err)
    }

    _, err = io.WriteString(conn, "<Request Type=\"GetToken\" />\r\n")
    if err != nil {
        log.Fatal("client write error:", err)
    }
    if err = conn.CloseWrite(); err != nil {
        log.Fatal(err)
    }

    for {
        buf := make([]byte, 256)
        n, err := conn.Read(buf)
        if err != nil && err != io.EOF {
            log.Fatal(err)
        }
        msg := strings.TrimSpace(string(buf[:n]))
        if len(msg) > 0 {
            fmt.Println(msg)
        }
    }
}

Example output:

go run main.go
DRC-1.00
<?xml version="1.0" encoding="utf-8" ?><Update Type="InvalidateAccount"/>
<?xml version="1.0" encoding="utf-8" ?><Response Type="GetToken" Status="Ready"/>
<?xml version="1.0" encoding="utf-8" ?><Update Type="GetToken" Status="Completed" Token="xxxxxx-xxxxxxxxxx-xxxxxx-xxxxxxxxxxx-xxxxxx"/>
^Csignal: interrupt

Before executing, you should turn off your AC. Then start this script, then wait until you get Response Type="GetToken" Status="Ready"/ in the output. After this message you have 20s to turn on your AC.

If successful, you will get your token like shown in the example output

rgogada commented 1 year ago

I got mine too. I will try my best to describe the process below that worked for me.

1) first of all you need one of the older python3 environments. the latest ones don't work. I created a quick docker container for that. passed the required files (server.py and ac14k_m.pem) into it with a volume (mimh03).

docker run -itd -v /root/docker/mimh03:/srv --name=mim --network=host angchen/python3.3-with-pip

2) now docker execute into it twice (you need two windows)

docker exec -it mim bash

3) now press the reset button briefly. this should restart the dhcp/token negotiation. (it it will not reset the existing network setup). Anyway make sure you do the next two steps immediately after this.

4) now run the server.py as below in the first window. it should say "Listening on localhost xxxxxxxx:xxxx". it will hang like that for token response. leave it like that.

python3 /srv/server.py

5) in the second window paste the below lines (after replacing IP with your mim-h03 ip) and hit enter. the key part is YOU DO THIS REPEATEDLY again and again. it will error out initially with the error "Failed to Connect" while the mimh03 negotiating. But in a few seconds the mim-h03 boots up and it will not error out and you will see the AP light starts blinking on the mimh03.

curl -k -H “Content-Type: application/json” -H “DeviceToken: xxxxxxxxxxx” --cert /srv/ac14k_m.pem --insecure -X POST https://IP:8888/devicetoken/request

6) Immediately hit the AP button briefly and you should see your token in the FIRST window.

good luck.