So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By szevlin
#87590 I made a temperature sensor that sends sends the temperature to Thingspeak and I also want it to send and email if the temperature is more than 28 degrees, but I dont know how to do the website part and the tutorials I found weren't working or I couldn't understand.
I already have a link that if I open(with IFTTT), it sends an email but I have trouble with making the esp8266 open the link.
Can someone help me what do I need in the if loop at the end or am I doing it completely wrong?
Thanks for any help.

Code: Select all#include <DallasTemperature.h>
#include <OneWire.h>
#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
#define ONE_WIRE_BUS 5
#define TEMPERATURE_PRECISION 10
unsigned long myChannelNumber = 1;
const char * myWriteAPIKey="xxxxx";
const char* ssid= "xxxxx";
const char* password= "xxxxx";
const char* host = "maker.ifttt.com";
int fieldStart = 1;
int status = WL_IDLE_STATUS;
WiFiClient  client;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int numberOfDevices;
DeviceAddress tempDeviceAddress;
void setup() {
 Serial.begin(115200);
  delay(100);
  Serial.println();
  Serial.println();
  pinMode(A0,INPUT);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password); 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");}
  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  ThingSpeak.begin(client);
  sensors.begin();
  numberOfDevices = sensors.getDeviceCount();
  Serial.print("Locating devices...");
  Serial.print("Found ");
  Serial.print(numberOfDevices, DEC);
  Serial.println(" devices.");
  Serial.print("Parasite power is: ");
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  for(int i=0;i<numberOfDevices; i++)
  {if(sensors.getAddress(tempDeviceAddress, i)){
    Serial.print("Found device ");
    Serial.print(i, DEC);
    Serial.print(" with address: ");
    printAddress(tempDeviceAddress);
    Serial.println();   
    Serial.print("Setting resolution to ");
    Serial.println(TEMPERATURE_PRECISION, DEC);
    sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);   
    Serial.print("Resolution actually set to: ");
    Serial.print(sensors.getResolution(tempDeviceAddress), DEC);
    Serial.println();  }else{
    Serial.print("Found ghost device at ");
    Serial.print(i, DEC);
    Serial.print(" but could not detect address. Check power and cabling");}}}
void printAddress(DeviceAddress deviceAddress)
{for (uint8_t i = 0; i < 8; i++){
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);}}
void loop() {
  sensors.requestTemperatures();
  for (int i=0; i<=(numberOfDevices - 1); i++){
    float temp=sensors.getTempCByIndex(i);
    ThingSpeak.setField(i+fieldStart,temp);
    Serial.println("Sensor #:");
    Serial.println(i);
    Serial.println("Temperature:");
    Serial.println(temp);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    Serial.println("Data sent to ThinkSpeak");
    if(temp>28){



         
      }
    delay(15000);}}
User avatar
By Bonzo
#87594 Why not get Thingspaek to send the email?

ThingSpeak now offers email alerts!


I have not checked the exact details but it is worth looking into.