Skip to content

Instantly share code, notes, and snippets.

@polluxlabs
Last active September 15, 2020 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polluxlabs/1f5bdb816e549fdb4f041a4c02005044 to your computer and use it in GitHub Desktop.
Save polluxlabs/1f5bdb816e549fdb4f041a4c02005044 to your computer and use it in GitHub Desktop.
Dash Button with Telegram and ESP8266
/*
Dash Button mit Telegram und ESP8266 - polluxlabs.net
*/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
// Deine WLAN-Zugangsdaten
const char* ssid = "DEIN WLAN-NETZWERK";
const char* password = "DEIN PASSWORT";
// Den Telegram-Bot initialisieren
#define botToken "DEIN TOKEN" // den Bot-Token bekommst du vom Botfather)
//Deine User ID
#define userID "DEINE USER ID"
WiFiClientSecure client;
UniversalTelegramBot bot(botToken, client);
// Zustand des Buttons
int switchState = 0;
void setup() {
Serial.begin(115200);
client.setInsecure();
// Verwendete Pins
pinMode(13, INPUT); //Button
pinMode(15, OUTPUT); //LED
// Verbindung zum WLAN
Serial.print("Verbinde mich mit: ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("Verbunden!");
bot.sendMessage(userID, "Bot gestartet", "");
}
void loop() {
switchState = digitalRead(13);
Serial.println(switchState);
if (switchState) {
bot.sendMessage(userID, "Button!", "");
digitalWrite(15, HIGH);
delay(200);
digitalWrite(15, LOW);
delay(200);
digitalWrite(15, HIGH);
delay(200);
digitalWrite(15, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment