The use of the ESP8266 in the world of IoT

User avatar
By nimaaryamehr
#68733 I would like to use this code to use the BotTelgram notifier, but it makes a mistake when compiling؟؟؟

Source:http://telegramiotbot.com/
Code: Select all#include <Arduino.h>

#include <ESP8266WiFi.h>

#include <ESP8266HTTPClient.h>

const byte interruptPin = 2;

const char[] SSID="YOUR WIFI SSID";
const char[] PASSWORD="YOUR WIFI PASSWORD";

const char[] BASEURI="http://telegramiotbot.com/api/notify?token=";

const char[] TOKEN_NOTIFY="YOUT TOKEN";


bool interrupted=false;
/*
    interrupt handler
*/
void inputChanged(){
    interrupted=true;
}

void notify(const char* token){
    HTTPClient http;

    Serial.print("[HTTP] begin...\n");
    http.begin(BASEURI+token);

    Serial.print("[HTTP] GET...\n");
    int httpCode = http.GET();
    if(httpCode) {
        Serial.printf("[HTTP] GET... code: %d\n", httpCode);
    } else {
        Serial.print("[HTTP] GET... failed, no connection or no HTTP server\n");
    }
}

bool connect(){
    WiFi.begin(SSID,PASSWORD);
    Serial.print("[Connecting]");
    int tries=0;
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
        tries++;
        if (tries > 30){
            Serial.println();
            Serial.print("[connecting failed]");
            Serial.println();
            return false;
        }
    }
    Serial.print("You're connected to the network");
    Serial.println();
    return true;
}


void setup() {
    Serial.begin(115200);
    conect();

    pinMode(interruptPin, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(interruptPin), inputChanged, FALLING);
}

void loop() {
    if(interrupted){
        if((WiFi.status() == WL_CONNECTED)) {
            notify(TOKEN_NOTIFY);
            interrupted=false;
        }
    }
}
User avatar
By schufti
#68737 try this. I don't know if it works but it compiles ...
Code: Select all#include <Arduino.h>

#include <ESP8266WiFi.h>

#include <ESP8266HTTPClient.h>

const byte interruptPin = 2;

const char* SSID="YOUR WIFI SSID";

const char* PASSWORD="YOUR WIFI PASSWORD";

const char* BASEURI="http://telegramiotbot.com/api/notify?token=";

const char* TOKEN_NOTIFY="YOUT TOKEN";


bool interrupted=false;
/*
    interrupt handler
*/
void inputChanged(){
    interrupted=true;
}

void notify(const char* token){
    HTTPClient http;

    Serial.print("[HTTP] begin...\n");
    http.begin(String(BASEURI) + token);

    Serial.print("[HTTP] GET...\n");
    int httpCode = http.GET();
    if(httpCode) {
        Serial.printf("[HTTP] GET... code: %d\n", httpCode);
    } else {
        Serial.print("[HTTP] GET... failed, no connection or no HTTP server\n");
    }
}

bool connect(){
    WiFi.begin(SSID,PASSWORD);
    Serial.print("[Connecting]");
    int tries=0;
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
        tries++;
        if (tries > 30){
            Serial.println();
            Serial.print("[connecting failed]");
            Serial.println();
            return false;
        }
    }
    Serial.print("You're connected to the network");
    Serial.println();
    return true;
}


void setup() {
    Serial.begin(115200);
    connect();

    pinMode(interruptPin, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(interruptPin), inputChanged, FALLING);
}

void loop() {
    if(interrupted){
        if((WiFi.status() == WL_CONNECTED)) {
            notify(TOKEN_NOTIFY);
            interrupted=false;
        }
    }
}