DS18B20 + IFTTT

Odpovědět
Phil0
Příspěvky: 3
Registrován: 13 bře 2020, 00:42
Reputation: 0

DS18B20 + IFTTT

Příspěvek od Phil0 » 14 bře 2020, 15:09

Dobrý den, jsem úplný nováček a potřebuji radu :( mám Wemos D1 mini + DS18B20 a chtěl bych měřit teplotu v akváriu.
Při překročení teploty bych chtěl poslat request pomocí IFTTT a osedlat notifikaci na telefon. Nemám ale páru jak napsat podmínku pro překročení teploty a poslání toho requestu na IFTTT.
Nyní používám tento program pro sledování teploty na webu. Ten bych případně chtěl zanechat ale přidat k němu tu notifikaci, dokážete mne nakopnout správným směrem? Děkuji

/*********
Rui Santos
Complete project details at https://RandomNerdTutorials.com
*********/

// Import required libraries
#ifdef ESP32
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#else
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#endif
#include <OneWire.h>
#include <DallasTemperature.h>

//Static IP address configuration

// config static IP
IPAddress ip(192, 168, 0, 111); // where xx is the desired IP Address
IPAddress gateway(192, 168, 0, 1); // set gateway to match your network
IPAddress subnet(255, 255, 255, 0); // set subnet mask to match your network


// Data wire is connected to GPIO 4
#define ONE_WIRE_BUS 4

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

// Replace with your network credentials
const char* ssid = "TP-LINK_Phil0";
const char* password = "xxxxxxx";

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

String readDSTemperatureC() {
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);

if(tempC == -127.00) {
Serial.println("Failed to read from DS18B20 sensor");
return "--";
} else {
Serial.print("Teplota vody: ");
Serial.println(tempC);
}
return String(tempC);
}

String readDSTemperatureF() {
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
float tempF = sensors.getTempFByIndex(0);

if(int(tempF) == -196){
Serial.println("Failed to read from DS18B20 sensor");
return "--";
} else {
Serial.print("Teplota vody: ");
Serial.println(tempF);
}
return String(tempF);
}

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<style>
html {
font-family: Arial;
display: inline-block;
margin: 0px auto;
text-align: center;
}
h2 { font-size: 3.0rem; }
p { font-size: 3.0rem; }
.units { font-size: 1.2rem; }
.ds-labels{
font-size: 1.5rem;
vertical-align:middle;
padding-bottom: 15px;
}
</style>
</head>
<body>
<h2>Akvarium </h2>
<p>
<i class="fas fa-thermometer-half" style="color:#059e8a;"></i>
<span class="ds-labels">Teplota vody</span>
<span id="temperaturec">%TEMPERATUREC%</span>
<sup class="units">&deg;C</sup>
</p>
<p>
<i class="fas fa-thermometer-half" style="color:#059e8a;"></i>
<span class="ds-labels">Teplota vody</span>
<span id="temperaturef">%TEMPERATUREF%</span>
<sup class="units">&deg;F</sup>
</p>
</body>
<script>
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperaturec").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/temperaturec", true);
xhttp.send();
}, 10000) ;
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperaturef").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/temperaturef", true);
xhttp.send();
}, 10000) ;
</script>
</html>)rawliteral";

// Replaces placeholder with DHT values
String processor(const String& var){
//Serial.println(var);
if(var == "TEMPERATUREC"){
return readDSTemperatureC();
}
else if(var == "TEMPERATUREF"){
return readDSTemperatureF();
}
return String();
}

void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
Serial.println();

// Start up the DS18B20 library
sensors.begin();

// Connect to Wi-Fi
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
Serial.print(F("Setting static ip to : "));
Serial.println(ip);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();

// Print ESP Local IP Address
Serial.println(WiFi.localIP());

// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html, processor);
});
server.on("/temperaturec", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readDSTemperatureC().c_str());
});
server.on("/temperaturef", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readDSTemperatureF().c_str());
});
// Start server
server.begin();
}

void loop(){

}

Phil0
Příspěvky: 3
Registrován: 13 bře 2020, 00:42
Reputation: 0

Re: DS18B20 + IFTTT

Příspěvek od Phil0 » 16 bře 2020, 07:08

Takže jsem to nakonec nějak vyřešil :)

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 10 hostů