Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timing problem on disconnect #14

Merged
merged 4 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The proxy mode means your SF Hub will still report some device data to Zendure's

To gather telemetry data you will need to run the BT manager tool as a service on a BT-enabled device (such as a Raspberry Pi) within range of your hub. The BT manager will continously collect telemetry data and report it to MQTT for you.

*Note:* I've been using this mode for some time and it worked mostly flawless. From time to time I had the bluetooth connection drop (using a Raspberry Pi Zero W) and it wouldn't reconnect to the hub. I either had to force drop the BT connection on the RasPi or on the hub by briefly diconnecting it from the WiFi (kickin it out of my Access Point)
*Note:* I've been using this mode for some time and it worked mostly flawless. From time to time I had the bluetooth connection drop (using a Raspberry Pi Zero W) and it wouldn't reconnect to the hub. I either had to force drop the BT connection on the RasPi or on the hub by briefly diconnecting it from the WiFi (kickin it out of my Access Point)

### Getting Basic Information
To get basic information about the hub (without performing any changes) run the script with the -i option only:
Expand Down Expand Up @@ -92,7 +92,7 @@ You can use that data for any other integration (e.g. Homeautomation systems etc
E.g. my [Solarflow Statuspage](https://github.com/reinhard-brandstaedter/solarflow-statuspage) is now also using this data instead of the cloud data.

> [!NOTE]
> While the bluetooth connection is enabled, the hub ONLY reports telemetry via BT! There will be no data sent in parallel to the Zendure Cloud broker. As a consequence you will not see any data in the mobile app. You can still control the hub though via the app.
> While the bluetooth connection is enabled, the hub ONLY reports telemetry via BT! There will be no data sent in parallel to the Zendure Cloud broker. As a consequence you will not see any data in the mobile app. You can still control the hub though via the app.

### Disconnecting the hub from the cloud
You can completely disconnect the hub from the Zendure cloud and have it report to a local MQTT broker. It will then not send any data to the cloud but you will also not be able to change any settings with the app. From that point on you can only control the hub via your local MQTT broker. This gives you full control but is for advanced usage (e.g. setting the output limit to any arbitrary value)
Expand All @@ -104,15 +104,20 @@ Disconnecting works by reinitializing the hubs network connection (WiFi) and tel
(eventually you need to change the WiFi first to another network before joining the target network)

```
$ pip3 install -r requirements.txt
$ export WIFI_PWD="your_wifi_password"
$ export SF_DEVICE_ID="your_sf_deviceid"
# your_sf_productid is 73bkTV for Hub1200 or A8yh63 for Hub2000
$ export SF_PRODUCT_ID="your_sf_productid"
$ python3 solarflow-bt-manager.py -d -w <WiFi SSID> -b <local MQTT broker>
```

example:
```
$ pip3 install -r requirements.txt
$ export WIFI_PWD="Sup3rS3cret!"
$ export SF_DEVICE_ID="5ak8yGU7"
$ export SF_PRODUCT_ID="73bkTV"
$ python3 solarflow-bt-manager.py -d -w SuperWiFi -b 192.168.1.245
```

Expand All @@ -139,6 +144,7 @@ Yoy can reconnect to hub back to Zendure's cloud again. This might be necessary
```
$ export WIFI_PWD="your_wifi_password"
$ export SF_DEVICE_ID="your_sf_deviceid"
$ export SF_PRODUCT_ID="73bkTV"
$ python3 solarflow-bt-manager.py -c -w <WiFi SSID>
```

Expand Down
2 changes: 1 addition & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bleak
paho-mqtt
paho-mqtt==1.6.1
4 changes: 2 additions & 2 deletions src/solarflow-bt-manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def on_connect(client, userdata, flags, rc):
log.error("Failed to connect, return code %d\n", rc)

def local_mqtt_connect(broker, port):
client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, client_id="solarflow-bt")
client = mqtt_client.Client(client_id="solarflow-bt")
if mqtt_user is not None and mqtt_pwd is not None:
client.username_pw_set(mqtt_user, mqtt_pwd)
client.connect(broker,port)
Expand Down Expand Up @@ -92,7 +92,7 @@ async def set_IoT_Url(client,broker,port,ssid,deviceid):
log.exception("Setting WiFi Mode failed")

if mq_client:
mq_client.publish(f'iot/{SF_PRODUCT_ID}/{deviceid}/register/replay',reply)
mq_client.publish(f'iot/{SF_PRODUCT_ID}/{deviceid}/register/replay', reply, retain=True)


def handle_rx(BleakGATTCharacteristic, data: bytearray):
Expand Down