SHT10 Sensor


#1

Hello,
I provide information about how to run the SHT10 Sensor with Cayenne dashboard:

Wiring the SHT10 Sensor:

Red Wire - to 3.3V
Green Wire - to GND
Blue Wire(Data) to PIN23
Yellow Wire(Clock) to PIN24

Important: Use 10K pullUp resistor from VCC(Red Wire) to DATA(Blue Wire).

Install Library:

I use this library:

pip3 install pi-sht1x

if there is error, you have to uprade the pip3 with the following command:
sudo easy_install3 -U pip

Also before start writing your python code, you have to install paho-mqtt for python3

sudo pip3 install paho-mqtt

Go to Cayenne Dashboard -> Add New -> Devices & Widgets and press the big blue button Add Your Own Thing

Then copy your MQTT Username, MQTT Password and Cliend ID to the following places in the code:

import paho.mqtt.client as mqtt
import time
import sys
from time import sleep
from pi_sht1x import SHT1x
import RPi.GPIO as GPIO
import datetime

#time.sleep(60) #Sleep to allow wireless to connect before starting MQTT

mqttc = mqtt.Client(client_id="YOUR CLIENT ID")
mqttc.username_pw_set("YOUR USERNAME", password="YOUR PASSWORD")
mqttc.connect("mqtt.mydevices.com", port=1883, keepalive=60)
topic_sht10_temp = "v1/YOUR USERNAME/things/CLIENT ID/data/1"
topic_sht10_humidity = "v1/YOUR USERNAME/things/CLIENT ID/data/2"
while True:
        try:
                with SHT1x(23, 24, gpio_mode=GPIO.BCM) as sensor:
                    temp11 = sensor.read_temperature()
                    humidity11 = sensor.read_humidity(temp11)
                if temp11 is not None:
                        temp11 = "temp,c=" + str(temp11)
                        mqttc.publish(topic_sht10_temp, payload=temp11, retain=True)
                if humidity11 is not None:
                        humidity11 = "rel_hum,p=" + str(humidity11)
                        mqttc.publish(topic_sht10_humidity, payload=humidity11, retain=True)
                        sleep(5)
                time.sleep(5)
        except (EOFError, SystemExit, KeyboardInterrupt):
                mqttc.disconnect()
                sys.exit()

Save and run the file using:

sudo python3 yourfilename.py

That’s it!


#2

Maybe @adam or @rsiegel can tell more about the new icon in the Humidity! I have seen that when I try to change the number of floating points decimals and then hit SAVE, the icon is automatically changed? Is this a bug or?

Thank you!


#3

Great work!


#4

thumbs up!


#5

I use some of @adam work that he do for DHT11 sensor and just adapt his code to work with SHT10 Sensor.


#6

New icons are coming. If you don’t modify the widget you’ll keep the water drop but unfortunately if you need to update something there is no way to keep that icon.


#7

Sounds great :slight_smile: I want to help you with the design if you need :slight_smile:


#8

Hello,
I am posting update of the code that have to be used for connection with Cayenne. The previous version has problems with “Going Offline” after some time of work. This code is tested in 10 Hours continuous work.

import cayenne.client as cayenne
import time
import Adafruit_DHT
from pi_sht1x import SHT1x
import RPi.GPIO as GPIO

time.sleep(60) #Sleep to allow wireless to connect before starting MQTT

MQTT_USERNAME  = "YOUR_USERNAME"
MQTT_PASSWORD  = "YOUR_PASSWORD"
MQTT_CLIENT_ID = "YOUR_CLIENTID"

client = cayenne.CayenneMQTTClient()
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)

timestamp = 0

while True:
    client.loop()
    if (time.time() > timestamp + 5):
        with SHT1x(23, 24, gpio_mode=GPIO.BCM) as sensor:
            temp11 = sensor.read_temperature()
            humidity11 = sensor.read_humidity(temp11)
        if temp11 is not None:
            client.virtualWrite(1, temp11, cayenne.TYPE_TEMPERATURE, cayenne.UNIT_CELSIUS)
        if humidity11 is not None:
            client.virtualWrite(2, humidity11, cayenne.TYPE_RELATIVE_HUMIDITY, cayenne.UNIT_PERCENT)
        timestamp = time.time()

#9

Hey, I was going through code,

I need to ask that have you also worked on mesh network communications between sensor and Cayenne Platform ?

I am using wireless temp sensor which consist of SHT25 and have code from here and I was able to monitor the readings using raspberry pi and was trying to implement process by connecting the zigbee communication with Cayenne platform which help to send the readings of sensor to Cayenne server and display the readings on dashboard through smart phones

But as beginner I am searching for best suggestion which help to make it possible.

Any kind of suggestion from you for this process will be much helpful.


#10

once you get data reading from the sensor it is easy to send this data to cayenne using https://github.com/myDevicesIoT/Cayenne-MQTT-Python