Skip to content

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jan 28, 2021
1 parent 35e81c9 commit 03c41e7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
42 changes: 42 additions & 0 deletions bh1750-mqtt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/python3

# Import required Python libraries
import paho.mqtt.client as mqtt
import board
import adafruit_bh1750
import time
import ssl

time.sleep(25)

# set the variables
broker='FQDN / IP Adresse'
port=8883
publish_topic="house/pi-bh1750"
clientid='python-mqtt-bh1750'
username='mosquitto'
password='password'
insecure=True
qos=1
retain_message=True

# do the stuff
# define BH1750
i2c = board.I2C()
lightsensor = adafruit_bh1750.BH1750(i2c)

#MQTT Connection
client=mqtt.Client(clientid)
client.username_pw_set(username, password)
client.tls_set(cert_reqs=ssl.CERT_NONE) #no client certificate needed
client.tls_insecure_set(insecure)
client.connect(broker, port)
client.loop_start()

#print("%.2f Lux" % lightsensor.lux)
client.publish("{}/lux".format(publish_topic),"{:.2f}".format(lightsensor.lux),qos,retain_message)

time.sleep(2)
client.disconnect()
client.loop_stop()

8 changes: 8 additions & 0 deletions bh1750.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/python3
import board
import adafruit_bh1750

i2c = board.I2C()
sensor = adafruit_bh1750.BH1750(i2c)

print("%.2f Lux" % sensor.lux)

0 comments on commit 03c41e7

Please sign in to comment.