erdose / xiaomi-mi-lywsd03mmc

Xiaomi Mi BLE Temperature & Humidity Sensor
MIT License
26 stars 7 forks source link

Data not appearing in Domoticz #13

Open MennoLabs opened 2 years ago

MennoLabs commented 2 years ago

I don't see the "INFO The request is http://192.168.178.23:8080/json.htm?type=command&param=udevice&idx=1053&nvalue=0&svalue=28.72;66;1&battery=74" line in my log file. No data appearing in Domoticz. When I use curl to post the data myself, I see it appear in Domoticz, so the error seems to be on the side of the script, not on the Domoticz side.

menno@quokka:~$ curl 'http://192.168.178.23:8080/json.htm?type=command&param=udevice&idx=1053&nvalue=0&svalue=20.0;66;1&battery=74' { "status" : "OK", "title" : "Update Device" }

Havym commented 12 months ago

It worked for me untill domoticz updated. No data appearing in Domoticz. When i use the request http://192.168.1.10:8080/json.htm?type=command&param=udevice&idx=215&nvalue=0&svalue=24.69;75;3&battery=74, domoticz is updated.

The log file.. when crontab did his work.

2023-08-19 18:00:12 INFO     TH_IDX:215
2023-08-19 18:00:12 INFO     TH_IDX:215
2023-08-19 18:00:12 ERROR    Failed to connect to peripheral A4:C1:38:37:9F:97, addr type: public
2023-08-19 18:00:12 INFO     TH_IDX:216
2023-08-19 18:00:25 INFO     Temp: 24.69
2023-08-19 18:00:25 INFO     Hum: 75
2023-08-19 18:00:25 INFO     Voltage: 2.842
2023-08-19 18:00:25 INFO     Battery level: 74
2023-08-19 18:00:25 INFO     Comfort type: 3
2023-08-19 18:00:25 INFO     The request is http://192.168.1.10:8080/json.htm?type=command&param=udevice&idx=215&nvalue=0&svalue=24.69;75;3&battery=74
2023-08-19 18:00:25 INFO     The response is <Response [401]>
2023-08-19 18:00:25 INFO     TH_IDX:216
2023-08-19 18:00:25 ERROR    Failed to connect to peripheral A4:C1:38:79:23:A5, addr type: public
2023-08-19 18:00:26 INFO     Temp: 23.31
2023-08-19 18:00:26 INFO     Hum: 80
2023-08-19 18:00:26 INFO     Voltage: 2.767
2023-08-19 18:00:26 INFO     Battery level: 67
2023-08-19 18:00:26 INFO     Comfort type: 3
2023-08-19 18:00:26 INFO     The request is http://192.168.1.10:8080/json.htm?type=command&param=udevice&idx=216&nvalue=0&svalue=23.31;80;3&battery=67
2023-08-19 18:00:26 INFO     The response is <Response [401]>

When i run the script manually...

~/xiaomi-mi-lywsd03mmc $ ./xiaomiBleLywsd03mmc.py
Traceback (most recent call last):
  File "./xiaomiBleLywsd03mmc.py", line 2, in <module>
    import config
  File "/home/pi/xiaomi-mi-lywsd03mmc/config.py", line 14
    TEMPERATURE_PREC = 2
                     ^
SyntaxError: invalid syntax
MennoLabs commented 12 months ago

Error 401 means unauthorized. I had the same problem since the update. For some reason Trusted IP addresses does not work. What did work was adding credentials to the script.

Havym commented 12 months ago

Can you tell me how you did that? I'm not a scripter. I put my credentials in top of the config.py and it still doesnt work. Maybe i'm doing something wrong.

When i execute the file drectly i get this error..

cd /home/pi/xiaomi-mi-lywsd03mmc && timeout -k 10 60 sudo python3 xiaomiBleLywsd03mmc.py
Traceback (most recent call last):
  File "xiaomiBleLywsd03mmc.py", line 2, in <module>
    import config
  File "/home/pi/xiaomi-mi-lywsd03mmc/config.py", line 14
    TEMPERATURE_PREC = 2
                     ^
SyntaxError: invalid syntax
MennoLabs commented 12 months ago

I am not much of a programmer either, but this isn't too hard ;-) Edit the script's configuration (with vi(m), nano or tilde) in the file config.py:

domoticz configuration

DOMOTICZ_SERVER_IP = "192.168.178.23" DOMOTICZ_SERVER_PORT = "8080" DOMOTICZ_USERNAME = "" DOMOTICZ_PASSWORD = ""

In the last two lines, put username and password of a user you defined in Domoticz.

When you run the script directly, do you run it as user, or with sudo? For me it only works with root privilege.

I am running a script that calls this script from root's crontab:

!/bin/bash

sudo service bluetooth restart sleep 10 sudo timeout -k 10 120 python3 /home/pi/domoticz/scripts/xiaomi-mi-lywsd03mmc/xiaomiBleLywsd03mmc.py

That worked better for me than calling the script directly. Maybe because I'm also using a plugin to read a Xiami Flowermate over Bluetooth.

Havym commented 12 months ago

Ok, so i did it right but it still doenst work. See the error above. Any idea's?

MennoLabs commented 12 months ago

See the update to my post, maybe try this script.

Havym commented 12 months ago

Still the same syntax error

sudo ./xiaomi03mmc
Traceback (most recent call last):
  File "/home/pi/xiaomi-mi-lywsd03mmc/xiaomiBleLywsd03mmc.py", line 2, in <module>
    import config
  File "/home/pi/xiaomi-mi-lywsd03mmc/config.py", line 14
    TEMPERATURE_PREC = 2
                     ^
SyntaxError: invalid syntax
MennoLabs commented 12 months ago

That's weird. I have exact the same line on line 14, I don't get a syntax error. Sorry, I'm afraid I'm not enough of a programmer to be able to help you further.

luizrrocha commented 11 months ago

Did you check the "/home/pi/xiaomi-mi-lywsd03mmc/xiaomiBleLywsd03mmc.py" file for proper end of line or end of file termination ?

There can be a false alert for line 14 caused by a previous error.

Luiz

On Wed, Aug 23, 2023 at 8:56 PM MennoLabs @.***> wrote:

That's weird. I have exact the same line on line 14, I don't get a syntax error. Sorry, I'm afraid I'm not enough of a programmer to be able to help you further.

— Reply to this email directly, view it on GitHub https://github.com/erdose/xiaomi-mi-lywsd03mmc/issues/13#issuecomment-1690552748, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7AKMBIJOBPIDKZ45ZB57DXWZN5HANCNFSM5FVJNUDA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Havym commented 11 months ago

Euh, no I haven't. I'm not a scripter. How should it look like?

luizrrocha commented 11 months ago

Something like this:

[image: image.png]

Pay attention to opening and closing quotes and the open and close brackets for each sensor line and also the open and close brackets for the whole pack of sensors. Also note that the last line of the file ends with an Enter, so the prompt will appear in a separate line. If it does not have the end-of-line, the prompt will be merged with the last line of the file on the same line..

On Thu, Aug 24, 2023 at 5:15 PM Havym @.***> wrote:

Euh, no I haven't. I'm not a scripter. How should it look like?

— Reply to this email directly, view it on GitHub https://github.com/erdose/xiaomi-mi-lywsd03mmc/issues/13#issuecomment-1692003235, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7AKMF6JG5GF3B5D3QUBDDXW543ZANCNFSM5FVJNUDA . You are receiving this because you commented.Message ID: @.***>

Havym commented 11 months ago

I deleted all the files en downloaded new files from github, filled in the data but still the same error. Could someone check the files here? I messaged the author here and on domoticz forum. Still no responce.