GithubHelp home page GithubHelp logo

jimmyh / besim Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 3.0 115 KB

A simulator for the cloud server the BeSMART thermostat/wifi box connects to

License: GNU General Public License v3.0

Python 99.75% Dockerfile 0.25%

besim's Introduction

BeSIM

A simulator for the cloud server the BeSMART thermostat/wifi box connects to.

Note that this project is not affiliated to Riello SpA which produces and sells the BeSMART products.

Meteorological data is kindly provided by: The Norwegian Meteorological Institute

What is BeSMART?

BeSMART allows you to connect multiple thermostats to your boiler and control them from your tablet or smartphone.

What is BeSIM?

A way you can control the BeSMART thermostat from within your own home, without having to use the original cloud server.

It consists of two components:

  • A UDP Server which handles the messaging to/from the BeSMART wifi box.
  • A REST API which allows you to get/set parameters from the BeSMART thermostats.

A few ways you can control the thermostat:

Caveats

This project is currently only a proof-of-concept implementation. Use at your own risk.

It does not yet support:

  • Multiple thermostats
  • OpenTherm parameters when connected via OT
  • There is no authentication on the rest api

Note: that CORS (Cross-origin resource sharing) headers are set on the server.

Note: that currently when you modify a value the API may return the old value for up to 40s (the thermostat sends periodic status reports every 40s).

How do I use BeSIM?

BeSIM can either be run as a standalone python3 script (tested on python3.12 only).

  • It is recommended to run from a virtual environment, and you can install the dependencies from requirements.txt pip install -r requirements.txt.
  • To start the server, just run 'python app.py'.

Or run as a container from docker/podman:

  • docker build . -t besim:latest
  • docker run -it -p 80:80 -p 6199:6199/udp besim:latest

To have the server get the weather at the server location, you need to set your location using environment variables eg:

  • docker run -it -e LONGITUDE=1.234 -e LATITUDE=-1.234 -p 80:80 -p 6199:6199/udp besim:latest

The server logs the thermostat status in an sqlite3 database. You can make this persistent by using a docker volume, eg:

  • docker run -it -e LONGITUDE=1.234 -e LATITUDE=-1.234 -e BESIM_DATABASE=/database/besim.db -v besim_database:/database -p 80:80 -p 6199:6199/udp besim:latest

The BeSMART thermostat connects:

  • api.besmart-home.com:6199 (udp)
  • api.besmart-home.com:80 (tcp, http get)
  • www.cloudwarm.com:80 (tcp, http post)

To redirect the traffic to BeSIM you need to do one of the following:

  • Configure your NAT router to redirect outgoing traffic with destination api.besmart-home.com to your BeSIM instance. You will probably also need to flush the connection tracking state in the router so it picks up the new destination.
  • Update DNS on your router to change the IP address for api.besmart-home.com to your BeSIM instance. You will probably need to reboot the BeSMART wifi box so it picks up the new IP address.

You should then see traffic arriving on BeSIM from your BeSMART device.

You can then use the rest api to query the state, for example (replace 192.168.0.10 with the IP address of your BeSIM instance):

  • Get a list of connected devices: curl http://192.168.0.10/api/v1.0/devices
  • Get a list of rooms (thermostats) from the device: curl http://192.168.0.10/api/v1.0/devices/<deviceid>/rooms
  • Get the state of the thermostat: curl http://192.168.0.10/api/v1.0/devices/<deviceid>/rooms/<roomid>
  • Set T3 temperature (to 19.2degC): curl http://192.168.0.10/api/v1.0/devices/<deviceid>/rooms/<roomid>/t3 -H "Content-Type: application/json" -X PUT -d 192
  • ...

besim's People

Contributors

jimmyh avatar

Stargazers

 avatar Stefano Busceti avatar

Watchers

 avatar  avatar Stefano Busceti avatar

besim's Issues

BeSmart wifi

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

No connection when cloud in state "network busy"

Hi, did you also notice that wifibox wont send any udp message if cloud connection with besmart-home.com is broken?
I installed your server, redirect all traffic from wifibox to server's instance but nothing appens; wifibox continue to do loop 53(dns) requests to api.besmart-home.com. (I tried also with my kotlin server but it do the same).
I also tried to change dns resolution for api.besmart-home.com to IP of internal server, nothing changes..

Did you experience the same problem?

(how can I contact you in private?)

Information about reverse engineering

Hi, congratulations for this very good job!
I have a question about the process of reverse engineering:
in udpserver.py I noticed this section
mode = byte2>>4
or
sensorinfluence = (byte3>>3) & 0xf

the question is: how did you understand that we need to do a right shift to extract the data?
Why shift right by 3, then 2 then 1 ?
How did you understand what data need to be shifted?
Why after shift operation, there is an & operation ?

thanks

different way to setup besmart modem, few extra bytes decoded

Hello, did you try to update modem settings to point to your server? (Other Setting/Server Address on besmart modem web page)
In the firmware there is a hardcoded password, just search for "admin" string.... ;)

also I started to sniff packets some time ago and found out few bytes that your code is not decoding yet;)
(indexes are referring to udp payload bytes.)

temp_map = {'tempOutside' : 240, 'tempSupply': 234, 'tempSuplyCWS': 238} #read two bytes
boiler_running = message[228] & 32 != 0
hot_water_heating = boiler_running and (message[228] & 64 != 0)
central_heating = boiler_running and not (message[228] & 64 != 0)

I didn't try to play with your project yet, but I'm amazed by amount of work you did :) (my sniffer is just a few lines ugly packets decoder)
I heard from instalator that this platform may by turned off soon, so it will be awesome to have local alternative :)

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.