Notify Slack if the temperature is too high.
Contents
Make things
Notify Slack when the room temperature goes over 35℃ with a temperature sensor.
Materials
- obniz Board
- temperature sensor(MCP9701)
- Slack account
How to make
Hardware connection
Connect a temperature sensor(MCP9701) to an obniz Board like the table and the image below by referring to the temperature sensor(MCP9701) Library.
obniz | temperature sensor (MCP9701) |
---|---|
0 | GND |
1 | OUTPUT |
2 | Vcc |
Software
Run the program every hour. Notify Slack if the room temperature goes over 35℃.
Setting up Slack
First, get a Webhook URL to send a message to Slack from here. Select the channel you want to send your message to, and then note the Webhook URL.
Replace the WEBHOOK_URL_HERE
(code.js line11) with the Webhook URL.
The program calls Webhook URL using ajax of jQuery in the below part of the sendToSlack function.
Please read jQuery.ajax() | jQuery API Documentation for details about ajax.
$.ajax({ type: "POST", dataType: "json", url: url, processData: false, data: "payload=" + dataJson }).then( function(data) {}, function(XMLHttpRequest, textStatus, errorThrown) { console.log("post to bot"); } );
Setting Serverless Events
Setting up a serverless event, you can run the program automatically on a regularly.
First, save the program at your repository of developer’s console. Then, if you click on “Create New,” you will reach this page like below.
Event Name. | (favorite name) |
---|---|
WebApp to run | The program you just saved. |
Trigger | Select Repetition This time, select to run it every hour. |
When you have completed the above, click the “Create” button to finish.
The program will now run every hour and notify Slack if it is over 35℃.