Connecting the temperature sensor to the Raspberry Pi to measure the water temperature. The current value is then published to https://io.adafruit.com/ using the internet connection provided by Hologram Nova Cellular USB Modem.
ImplementationAnd here goes the implementation:
First I bought 2 ds18b20 temperature sensors already waterproofed sealed. I've added them like this:
- 4.7 k resistor between pin 1 and pin 7
- Sensor 1: red (VCC) on pin 2, yellow (SIGNAL) on pin 7, black (GND) on pin 6
- Sensor 2: red on pin 4, yellow on pin 7, black on 9
- Hologram Nova on USB port
On system side I switched off HDMI output, adding:
/usr/bin/tvservice -o
to "/etc/rc.local" and disabled the on-board LED. Adding:
# Disable the ACT LED on the Pi Zero.
dtparam=act_led_trigger=none
dtparam=act_led_activelow=on
to "/boot/config.txt".
The CodeI wrote a little Python script to read the sensors and send them to Hologram Cloud and route them further to AT&T M2X:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
temps = []
try:
# 1-Wire Slave-Liste lesen
file = open('/sys/devices/w1_bus_master1/w1_master_slaves')
w1_slaves = file.readlines()
file.close()
# Fuer jeden 1-Wire Slave aktuelle Temperatur auslesen
idx = 0
for line in w1_slaves:
# 1-wire Slave extrahieren
w1_slave = line.split("\n")[0]
try:
# 1-wire Slave Datei lesen
name = '/sys/bus/w1/devices/' + str(w1_slave) + '/w1_slave'
file = open(name)
filecontent = file.read()
file.close()
# Temperaturwere auslesen und konvertieren
print(filecontent)
stringvalue = filecontent.split("\n")[1].split(" ")[9]
print(stringvalue)
temperature = float(stringvalue[2:]) / 1000
#Temperatur ausgeben
print(str(w1_slave) + ': %6.2f °C' % temperature)
temps.append(temperature)
except:
print(name + ' does not exist.')
idx = idx + 1
time.sleep(1)
except:
print('w1_master_slaves not found.')
from Hologram.HologramCloud import HologramCloud
hologram = HologramCloud(dict(), network='cellular')
result = hologram.network.connect()
if result == False:
print(' Failed to connect to cell network')
for idx in range(0, len(temps)):
print('%6.2f °C' % temps[idx])
result = hologram.sendMessage('{"temperature": %6.2f}' % temps[idx], ["Zernsee" + str(idx+1)])
print(result)
time.sleep(10)
hologram.network.disconnect()
A cronjob is executing this command every hour:
0 */1 * * * python /home/pi/send-cellular-message.py >> /home/pi/cron.log
A big battery pack is added to supply the necessary energy. The whole stuff is now placed inside a case, sealed well and put on a anchor, swimming on the lake.
Results from remeasuring can be observed on this public dashboard: https://m2x.att.com/dashboards/shared/d8d782f8fd25c56696216544125bd2c3
Outlook: Since the Raspberry Pi is never going to power off even during idle times and the Hologram Nova USB stick is powered all the time, the power consumption is quite high. Therefore a nice addition would be a little Arduino device which controls power supply for the Raspberry Pi and therefore the Hologram Nova USB stick using a MOSFET transistor (like the IRLZ44 or similar). The Arduino would got to deep sleep, awake every hour, power up the Rasberry Pi which does the measurement and sends the data using the Hologram Nova USB stick. After 2 minutes the Arduino would switch off power to the Raspberry Pi and go back to deep sleep.
Comments