Skip to content

Instantly share code, notes, and snippets.

@TakehikoShimojima
Last active July 24, 2018 01:36
Show Gist options
  • Select an option

  • Save TakehikoShimojima/21eaf5f57e9d8f5c1978f2e20a721288 to your computer and use it in GitHub Desktop.

Select an option

Save TakehikoShimojima/21eaf5f57e9d8f5c1978f2e20a721288 to your computer and use it in GitHub Desktop.
const Obniz = require("obniz");
const ambient = require('ambient-lib');
const obniz = new Obniz("obniz-ID");
const channelId = 100;
const writeKey = 'writeKey';
// 熱中症の危険度判定
// 0: 注意、1: 警戒、2: 厳重警戒、3: 危険
// 日本生気象学会「日常生活における熱中症予防指針」Ver.3を元に作成
// http://seikishou.jp/pdf/news/shishin.pdf
const WBGTlevel = (humid, temp) => {
if (temp > (humid * (-12.0 / 70.0) + 40.0 + 36.0 / 7.0)) {
return 3;
}
if (temp > humid * (-13.0 / 80.0) + 25.0 + 130.0 / 8.0) {
return 2;
}
if (temp > humid * (-3.0 / 20.0) + 37.0) {
return 1;
}
return 0;
}
const get_data_send = async (bme280, led) => {
const val = await bme280.getAllWait();
console.log(val);
ambient.send({d1: val.temperature, d2: val.humidity, d3: val.pressure}, (err, res, body) => {
if (err) {
console.log(err);
}
console.log(res.statusCode);
});
const level = WBGTlevel(val.humidity, val.temperature);
console.log('level: ' + level);
if (level >= 2) {
led.on();
} else {
led.off();
}
}
obniz.onconnect = async () => {
const bme280 = obniz.wired("BME280", {vio:6, vcore:5, gnd:4, csb:3, sdi: 2, sck: 1, sdo:0 });
await bme280.applyCalibration();
const led = obniz.wired("LED", {anode:11, cathode:10});
ambient.connect(channelId, writeKey);
get_data_send(bme280, led);
setInterval(() => {
get_data_send(bme280, led);
}, 300 * 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment