-->
Page 1 of 1

Request https with esp8266

PostPosted: Thu Jun 18, 2020 6:01 pm
by szevlin
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 https part and the tutorials I found weren't working or I couldn't understand.
I already have a link that if I open(ifttt), it sends an email but I have trouble with making the esp8266 opening the link.
Can someone help me what do I need in the if loop 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);}}