jimmyH / BeSIM

A simulator for the cloud server the BeSMART thermostat/wifi box connects to
GNU General Public License v3.0
2 stars 3 forks source link

BeSmart wifi #4

Open 111lisu opened 12 months ago

111lisu commented 12 months ago

After redirecting the api.besmart-home.com: connection to docker (docker run -it -e LONGITUDE=49.xxx -e LATITUDE=22.xxx -p 80:80 -p 6199:6199/udp besim:latest) and reconfiguring the BeSmart wifi, the configuration was successful.

BeSIM# docker run -it -p 80:80 -p 6199:6199/udp besim:latest
[2023-12-03 19:52:54,863 database.py->check_migrations():57] WARNING: Initialising Database to version 1
 * Serving Flask app 'restapi'
 * Debug mode: off
[2023-12-03 19:52:55,060 udpserver.py->run():413] INFO: UDP server is running
[2023-12-03 19:52:55,076 _internal.py->_log():96] INFO: WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:80
 * Running on http://172.17.0.2:80
[2023-12-03 19:52:55,083 _internal.py->_log():96] INFO: Press CTRL+C to quit
[2023-12-03 19:53:52,255 _internal.py->_log():96] INFO: 192.168.184.162 - - [03/Dec/2023 19:53:52] "GET /api/v1.0/devices HTTP/1.1" 200 -
[2023-12-03 19:53:54,803 _internal.py->_log():96] INFO: 192.168.184.162 - - [03/Dec/2023 19:53:54] "GET /api/v1.0/devices HTTP/1.1" 200 -
[2023-12-03 19:53:55,078 _internal.py->_log():96] INFO: 192.168.184.162 - - [03/Dec/2023 19:53:55] "GET /api/v1.0/devices HTTP/1.1" 200 -
[2023-12-03 19:53:55,244 _internal.py->_log():96] INFO: 192.168.184.162 - - [03/Dec/2023 19:53:55] "GET /api/v1.0/devices HTTP/1.1" 200 -
[2023-12-03 19:54:46,849 _internal.py->_log():96] INFO: 192.168.184.162 - - [03/Dec/2023 19:54:46] "GET /api/v1.0/devices HTTP/1.1" 200 -
[2023-12-03 20:08:06,139 _internal.py->_log():96] INFO: 192.168.184.162 - - [03/Dec/2023 20:08:06] "GET /api/v1.0/devices HTTP/1.1" 200 -
[2023-12-03 20:08:06,789 _internal.py->_log():96] INFO: 192.168.184.162 - - [03/Dec/2023 20:08:06] "GET /api/v1.0/devices HTTP/1.1" 200 -
[2023-12-03 20:08:07,006 _internal.py->_log():96] INFO: 192.168.184.162 - - [03/Dec/2023 20:08:07] "GET /api/v1.0/devices HTTP/1.1" 200 -

However, no devices are visible

http://192.168.182.72/api/v1.0/devices
[]

where to find some logic etc

jimmyH commented 12 months ago

Looks like the UDP packets on port 6199 are not being received by docker container. When it receives a packet from the BeSmart device it will print something like:

[2023-12-04 18:18:33,639 udpserver.py->run():420] INFO: From ('10.42.1.1', 55333) 264 bytes : FA D4 FC 00 43 ...

You may need to use a packet sniffer (wireshark/tcpdump etc) to work out why the traffic is not getting redirected.

111lisu commented 12 months ago

Thanks for the tip, I'll check the network route

111lisu commented 12 months ago
  Home Assistant URL:       http://homeassistant.local:8123
  Observer URL:             http://homeassistant.local:4357
[core-ssh ~]$ 
[core-ssh ~]$ nc -v -u -z -w 3 192.168.182.72 6199
192.168.182.72 (192.168.182.72:6199) open
[core-ssh ~]$ 

lisu@lisu:~$ nslookup api.besmart-home.com 192.168.8.100
Server:     192.168.8.100
Address:    192.168.8.100#53

Non-authoritative answer:
Name:   api.besmart-home.com
Address: 192.168.182.72

lisu@lisu:~$ nslookup www.cloudwarm.com 192.168.8.100
Server:     192.168.8.100
Address:    192.168.8.100#53

Non-authoritative answer:
Name:   www.cloudwarm.com
Address: 192.168.182.72

Everything seems to be OK with the connection, I'll sniff it on the spot, maybe another port?

111lisu commented 12 months ago

It took a while because the VPN server was working, but it connected.

# curl http://192.168.182.72/api/v1.0/devices
[597171176]
# curl http://192.168.182.72/api/v1.0/devices/597171176/rooms
[79556623, 35458646, 747586758, 3936447694]
# curl http://192.168.182.72/api/v1.0/devices/597171176/rooms/79556623
{"days": {"0": [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 33, 34, 34, 34, 18, 17, 17, 17, 17, 17, 17, 17], "1": [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 33, 34, 34, 34, 18, 17, 17, 17, 17, 17, 17, 17], "2": [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 33, 34, 34, 34, 18, 17, 17, 17, 17, 17, 17, 17], "4": [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 33, 34, 34, 34, 18, 17, 17, 17, 17, 17, 17, 17], "3": [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 33, 34, 34, 34, 18, 17, 17, 17, 17, 17, 17, 17], "5": [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 33, 34, 34, 34, 18, 17, 17, 17, 17, 17, 17, 17], "6": [17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 33, 34, 34, 34, 18, 17, 17, 17, 17, 17, 17, 17]}, "heating": 0, "temp": 206, "settemp": 30, "t3": 196, "t2": 180, "t1": 70, "maxsetp": 400, "minsetp": 400, "mode": 5, "tempcurve": 8, "heatingsetp": 5, "sensorinfluence": 5, "units": 0, "advance": 0, "boost": 0, "cmdissued": 0, "winter": 1, "lastseen": 1701946156, "fakeboost": 0}
jimmyH commented 12 months ago

Great.

Note: You can get some of the OpenTherm parameters from the devices/597171176 endpoint.

111lisu commented 12 months ago

This is a cool server, thanks for your work. You will tell us how to do it on/off via curl?

# curl http://192.168.182.72/api/v1.0/devices/597171176/rooms/3936447694/t3 -H "Content-Type: application/json" -X PUT -d 195
{"message": "OK"}`

# curl http://192.168.182.72/api/v1.0/devices/597171176/rooms/3936447694/heating -H "Content-Type: application/json" -X PUT -d 1
<!doctype html>
<html lang=en>
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>

# curl http://192.168.182.72/api/v1.0/devices/597171176/rooms/3936447694/heating -H "Content-Type: application/json" -X PUT -d 0
<!doctype html>
<html lang=en>
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
# 
jimmyH commented 12 months ago

The heating endpoint is readonly. You should just need to increase T3 0.5degC (assuming default hysteresis settings) above the current room temperature for the heating to start.

Note:

111lisu commented 11 months ago

Thanks for the information, the driver can still be used via wireguard, etc.

111lisu commented 11 months ago

Yesterday the controller disconnected. the red LED was on. My friend connected again. The idea controller connected again. However, it does not display the ID. Have you had this problem with your controller?

Zrzut ekranu z 2023-12-13 08-14-13

jimmyH commented 11 months ago

lastseen from curl http://192.168.182.72/api/v1.0/devices/597171176 will tell you the last time the server received a message from the BeSmart device. It looks like the traffic is no longer reaching the server.

I have had to restart my BeSmart device a few times because it loses Wifi. However, it has been very reliable the last few months.

111lisu commented 11 months ago

The connection UDP should be working fine. I don't know if the driver sends keepalive? We will try to connect it again several times.

Zrzut ekranu z 2023-12-13 13-18-17


[core-ssh ~]$ curl http://192.168.182.72/api/v1.0/devices/597171176/rooms
[]