davidb24v / meross-powermon

Simple command line interface for local operation of Meross energy monitoring plugs
14 stars 5 forks source link

Not able to config Meross on Linux #3

Open apfelflo89 opened 4 years ago

apfelflo89 commented 4 years ago

So I tried my best, 2 Linux systems with 3 installs with no success. What I did was: sudo apt install python3 sudo apt install python3-pip sudo apt install python3-argcomplete wget https://github.com/davidb24v/meross-powermon/archive/master.zip unzip master.zip cd meross-powermon-master sudo python3 setup.py install sudo pip3 install meross_iot==0.1.4.3 sudo ./meross init --user pi --ssid _SSID_ --password _PASSWORD_ --interface wlan0 ./meross init --server _IP_ --port 8883 --ca-cert /home/pi/mqtt_ca.crt sudo ./meross setup name My /home/pi/.config/meross_powermon/config.json looks like this:

{ "server": "_IP_", "port": 8883, "ca_cert": "/home/pi/mqtt_ca.crt", "user": "pi", "ssid": "_encryptedSSID_", "password": "_encryptedPASSWORD_", "interface": "wlan0" }

And I end up like this:

`ip link set dev wlan0 up OK Looking for Meross device..... Found Meross_SW_16C4 iwconfig wlan0 ap 48:E1:E9:19:16:C4 essid Meross_SW_16C4 key off OK ip addr add 10.10.10.100/24 dev wlan0 OK ip addr del 10.10.10.100/24 dev wlan0 OK ip link set dev wlan0 down OK Traceback (most recent call last): File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw) File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 80, in create_connection raise err File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 70, in create_connection sock.connect(sa) OSError: [Errno 113] No route to host

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 354, in _make_request conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.7/http/client.py", line 1244, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/lib/python3.7/http/client.py", line 1290, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/lib/python3.7/http/client.py", line 1239, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib/python3.7/http/client.py", line 1026, in _send_output self.send(msg) File "/usr/lib/python3.7/http/client.py", line 966, in send self.connect() File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 181, in connect conn = self._new_conn() File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 168, in _new_conn self, "Failed to establish a new connection: %s" % e) urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x75e0f2f0>: Failed to establish a new connection: [Errno 113] No route to host

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send timeout=timeout File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen _stacktrace=sys.exc_info()[2]) File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='10.10.10.1', port=80): Max retries exceeded with url: /config/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x75e0f2f0>: Failed to establish a new connection: [Errno 113] No route to host'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "./meross", line 21, in subcommands[opts.subcommand].go(opts) File "/home/pi/meross-powermon-master/meross_powermon/setup.py", line 52, in go dev0 = get_device_data() File "/home/pi/meross-powermon-master/meross_powermon/setup.py", line 121, in get_device_data return send(URL + "/config/", data) File "/home/pi/meross-powermon-master/meross_powermon/setup.py", line 109, in send r = requests.post(url, json=data) File "/usr/lib/python3/dist-packages/requests/api.py", line 116, in post return request('post', url, data=data, json=json, kwargs) File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request return session.request(method=method, url=url, kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request resp = self.send(prep, send_kwargs) File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send r = adapter.send(request, kwargs) File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.10.10.1', port=80): Max retries exceeded with url: /config/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x75e0f2f0>: Failed to establish a new connection: [Errno 113] No route to host'))`

lukegg commented 3 years ago

I realise this is ~6 months down the road from your query, but did you find a fix for this in the end? I'm running into the same issue now.

kusannaghi commented 3 years ago

I am at the same point. I run and it fails to import its own libraries.

Traceback (most recent call last): File "./meross", line 12, in import meross_powermon.command_line as command_line File "/home/pi/meross_powermon/command_line.py", line 12, in from meross_powermon import config, delete, init, monitor, setup File "/home/pi/meross_powermon/config.py", line 9, in from meross_powermon.modified_device import Mss310 File "/home/pi/meross_powermon/modified_device.py", line 15, in from meross_iot.supported_devices.power_plugs import (Device, ClientStatus) ModuleNotFoundError: No module named 'meross_iot.supported_devices'

I don't know how to do it anymore. This is my second linux installation.

Thx

blsky339 commented 2 years ago

My problem was that powermon could not select the meross wifi AP (It's a chromebook with ubuntu). I also tested on Ubuntu wsl2 (Windows 10). So, I manually connected to meross AP, and commented all lines in meross_powermon/setup.py that did it as below (Now I should set one device at a time).

    #wifi_up(interface)
    print("Looking for Meross device...", end="")

...

#            content = iwlist.scan()
#            cells = iwlist.parse(content)
#            for cell in cells:
#                if cell["essid"].startswith("Meross_"):
            if True:  # added this line
                    #print("\nFound {}".format(cell["essid"]))

                    #associate(cell, interface)
                    #add_ip(interface)

                    # Get initial device data
                    dev0 = get_device_data()

Also, the URL does not work on all devices. You need to change the following in get_device_data(), set_server_details() and set_wifi_details().

#    return send(URL + "/config/", data)
     return send(URL + "/config", data)

In order to connect with MQTT server and the device, you also need to the key and uuid. The key is used to compute the sign as in described here.

I forced the key as empty in set_server_details() to avoid having to copy/paste it from the logs:

#    key = mangle(opts.name)
    key = '' 

I added the following in send() to show uuid and other infos:

 def send(url, data):
     r = requests.post(url, json=data)
     print("========= url and data")
     print("url  "+str(url))
     print("data "+str(data))

     if r.status_code != 200:
         print("status: ", r.status_code)
         sys.exit("error sending request to device: {}".format(url))
     print(" RX: "+str(r.json()))
     return r.json()