The reason behind this is that these two guys were having health problems.
One had shell disease and another caught a cold(or more professionally, respiratory infection). It was fall and the room temp was changing rapidly (I also caught a cold one morning). So I would have to separate them and keep the environment at a steady temperature. The cheap heater is not so reliable and I wanted to monitor the water temperature.
I used a DS18B20 sensor to detect the temperature.
Since the three-pinned sensor is not waterproof, I also purchased the water-resistant wire and solder the pins so that they could be used underwater (super ugly though).
(Always remember to change the mirror source if something needs to be downloaded or installed…)
AZURE IoT doc reference:
If you want to use your own device, remember to adjust the code:
#replace with your own
CONNECTION_STRING = "xxxxxxxxxxxxxxxxxxxx"
# Define the JSON message to send to IoT Hub.
MSG_TXT = '{{"temperature": {temperature}}}'
#replace with your own device(sensor)
deviceNum = "xxxxxxxxxx"
deviceFile = '/sys/bus/w1/devices/' + deviceNum + '/w1_slave'
def readTempFile():
f = open(deviceFile,'r')
lines = f.readlines()
f.close()
return lines
def readTemp():
lines = readTempFile()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = readTempFiles()
tempInx= lines[1].find('t=')
if tempInx != -1:
temp = lines[1][tempInx + 2:]
tempC = float(temp)/1000.0
return tempC