Since it uses a 1-wire sensor, add the following to / etc / modules of Raspberry Pi
w1-gpio
w1-therm
Add the following to /boot/config.txt
dtoverlay=w1-gpio-pullup
Sensor connection
--Pin 1 (GND) of the sensor is pin 6 (GND) of Raspberry Pi --Pin 2 (DQ) of the sensor is pin 7 (GPIO4) of Raspberry Pi --Sensor pin 3 (VDD) is Raspberry Pi pin 1 (3.3V)
To The 2nd and 3rd pins of the sensor are connected by a pull-up resistor. Reference: http://blog.livedoor.jp/victory7com/archives/33399310.html
Use the lsmod command to check the connection. If the connection is successful, it will be as follows.
cmd
pi@raspberrypi:~/Documents/work$ lsmod | grep w1
w1_therm 6401 0
w1_gpio 4818 0
wire 32619 2 w1_gpio,w1_therm
The acquired temperature is written to "/ sys / bus / w1 / devices / 28-XXXXXXXX / w1_slave". (XXXX of 28-XXXXXXXX changes depending on the terminal you are using)
cmd
pi@raspberrypi:~/Documents/work$ cat /sys/bus/w1/devices/28-00000723fabd/w1_slave
b1 01 4b 46 7f ff 0f 10 8d : crc=8d YES
b1 01 4b 46 7f ff 0f 10 8d t=27062
The current temperature is the value of "t =" divided by 1000.
Go to IFTTT and create a recipe from My Applet.
Set "this" to "Webhooks" and "that" to "line"
After setting, go to https://ifttt.com/services/maker_webhooks/settings and go to the URL provided to enable the key.
--event is the event name set when setting Webhooks --value is the value you want to send to LINE
By executing the curl command following "You can also try it with curl from a command line.", It will be sent to the set LINE destination.
With RaspberryPi, get the temperature with python, request the URL of the Webhooks set with IFTTT, and send the room temperature to LINE.
Install the library to get the temperature
cmd
pip install w1thermsensor
Get and send with the following code
python
from w1thermsensor import W1ThermSensor
import urllib.request, json
sensor = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, "(Sensor device name)")
temperature_in_celsius = sensor.get_temperature()
url = "https://maker.ifttt.com/trigger/(Webhooks event name)/with/key/(Webhooks key)"
method = "POST"
headers = {"Content-Type" : "application/json"}
obj = {"value1" : temperature_in_celsius}
json_data = json.dumps(obj).encode("utf-8")
request = urllib.request.Request(url, data=json_data, method=method, headers=headers)
with urllib.request.urlopen(request) as response:
response_body = response.read().decode("utf-8")
Match THERM_SENSOR_DS18B20 with the model number of the sensor you are using. The device name of the sensor is the XXXX part of 28-XXXXXXXX. After that, if you set this to Coulomb etc., you can get the room temperature regularly.
Recommended Posts