probleme python 3
Publié : 07 févr. 2020, 22:07
salut à tous,
j'ai donc tout reinstallé suite à mon crash, je suis sous raspbian buster sur pi3 b+
je rencontre un soucis avec mes mi flora,
j'ai donc installer à partir d'ici
https://www.domoticz.com/wiki/Mi_Flora_Bluetooth_LE
dans putty quand je lance
j'ai comme retour
à savoir que j'ai bien le retour de mes miflora, enfin d'un, le 2eme ne veut pas, mais je ne sais pas si c'est lié.....
en tout cas les info remonte bien dans DZ
voilà le script
j'ai donc tout reinstallé suite à mon crash, je suis sous raspbian buster sur pi3 b+
je rencontre un soucis avec mes mi flora,
j'ai donc installer à partir d'ici
https://www.domoticz.com/wiki/Mi_Flora_Bluetooth_LE
dans putty quand je lance
Code : Tout sélectionner
/usr/bin/python3 /home/pi/domoticz/scripts/python/miflora/domoticz.pyCode : Tout sélectionner
/home/pi/domoticz/scripts/python/miflora/domoticz.py:25: DeprecationWarning: encodestring() is a deprecated alias since 3.1, use encodebytes()
base64string = base64.encodestring(('%s:%s' % (domoticzusername, domoticzpassword)).encode()).decode().replace('\n', '')en tout cas les info remonte bien dans DZ
voilà le script
Code : Tout sélectionner
import urllib.request
import base64
import time
from miflora.miflora_poller import MiFloraPoller, \
MI_CONDUCTIVITY, MI_MOISTURE, MI_LIGHT, MI_TEMPERATURE, MI_BATTERY
# Settings for the domoticz server
# Forum see: http://domoticz.com/forum/viewtopic.php?f=56&t=13306&hilit=mi+flora&start=20#p105255
domoticzserver = "127.0.0.1:8080"
domoticzusername = ""
domoticzpassword = ""
# So id devices use: sudo hcitool lescan
# Sensor IDs
# Create 4 virtual sensors in dummy hardware
# type temperature
# type lux
# type percentage (moisture)
# type custom (fertility)
base64string = base64.encodestring(('%s:%s' % (domoticzusername, domoticzpassword)).encode()).decode().replace('\n', '')
def domoticzrequest (url):
request = urllib.request.Request(url)
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib.request.urlopen(request)
return response.read()
def update(address,idx_moist,idx_temp,idx_lux,idx_cond):
poller = MiFloraPoller(address)
# reading error in poller (happens sometime, you go and bug the original author):
#
# 26231 fertility
# 136% moisture
# 4804.2 temperature
# 61149 lux
loop = 0
try:
temp = poller.parameter_value("temperature")
except:
temp = 201
while loop < 2 and temp > 200:
print("Patched: Error reading value retry after 5 seconds...\n")
time.sleep(5)
poller = MiFloraPoller(address)
loop += 1
try:
temp = poller.parameter_value("temperature")
except:
temp = 201
if temp > 200:
print("Patched: Error reading value\n")
return
global domoticzserver
print("Mi Flora: " + address)
print("Firmware: {}".format(poller.firmware_version()))
print("Name: {}".format(poller.name()))
print("Temperature: {}°C".format(poller.parameter_value("temperature")))
print("Moisture: {}%".format(poller.parameter_value(MI_MOISTURE)))
print("Light: {} lux".format(poller.parameter_value(MI_LIGHT)))
print("Fertility: {} uS/cm?".format(poller.parameter_value(MI_CONDUCTIVITY)))
print("Battery: {}%".format(poller.parameter_value(MI_BATTERY)))
val_bat = "{}".format(poller.parameter_value(MI_BATTERY))
# Update temp
val_temp = "{}".format(poller.parameter_value("temperature"))
domoticzrequest("http://" + domoticzserver + "/json.htm?type=command¶m=udevice&idx=" + idx_temp + "&nvalue=0&svalue=" + val_temp + "&battery=" + val_bat)
# Update lux
val_lux = "{}".format(poller.parameter_value(MI_LIGHT))
domoticzrequest("http://" + domoticzserver + "/json.htm?type=command¶m=udevice&idx=" + idx_lux + "&svalue=" + val_lux + "&battery=" + val_bat)
# Update moisture
val_moist = "{}".format(poller.parameter_value(MI_MOISTURE))
domoticzrequest("http://" + domoticzserver + "/json.htm?type=command¶m=udevice&idx=" + idx_moist + "&svalue=" + val_moist + "&battery=" + val_bat)
# Update fertility
val_cond = "{}".format(poller.parameter_value(MI_CONDUCTIVITY))
domoticzrequest("http://" + domoticzserver + "/json.htm?type=command¶m=udevice&idx=" + idx_cond + "&svalue=" + val_cond + "&battery=" + val_bat)
time.sleep(1)
# format address, moist (%), temp (°C), lux, fertility
print("\n1:plante salon")
update("C4:7C:8D:65:E5:8D","5386","530","140","5384")
print("\n2: plante etage")
update("C4:7C:8D:65:D2:6F","5387","532","52","5385")