Hinweis: Aktuell funktioniert dieses Projekt nicht, wie es soll. Wir arbeiten an einer Lösung und entfernen diesen Hinweis, wenn es so weit ist. 🙂
In diesem Projekt baust du eine Art Intercom. Allerdings beschränkt sich dieses nicht auf ein Gebäude, sondern kann Nachrichten von daheim auf dein Smartphone senden – und auch von dort Nachrichten empfangen und auf einem OLED-Display anzeigen.
Konkret besteht das Projekt aus zwei Buttons, die zwei unterschiedliche Emojis an den Telegram-Bot senden. Von dort kannst du ebenfalls mit zwei vordefinierten Emojis antworten, die dann auf dem Display des Projekts erscheinen.
Die Wahl der Emojis liegt natürlich bei dir. Wir haben uns jedoch folgendes Szenario ausgedacht: Ein Kind kommt von der Schule heim und drückt einen der beiden Buttons, je nachdem wie es sich fühlt. Der grüne sendet ein 🙂 – der rote ein 🙁
Du empfängst dieses Emoji auf deinem Smartphone und kannst reagieren mit einem 🙂 – um zu sagen, dass alles gut ist. Oder mit einem

Dieses Projekt ist der fünfte und letzte Teil einer Serie und baut auf die Vorgängerprojekte auf. In diesem Artikel findest du alles zum Aufbau und den passenden Sketch; wir besprechen jedoch nicht alle Teile des Codes. Wenn du mehr Details erfahren möchtest, wirf bitte einen Blick in die folgenden Projekte:
- Ein stiller Alarm mit Telegram und einem ESP8266
- Überwache die Temperatur mit Telegram und einem ESP8266
- Die aktuelle Temperatur per Telegram abfragen
- Das Licht ein- und ausschalten mit Telegram
Falls du noch kein Projekt mit Telegram gebaut hast, lerne zunächst, wie du einen Telegram-Bot erstellst.
Anfänger
1 – 2 Stunden
ca. 15 €
Für dieses Projekt benötigst du (Mengen s. Beschreibung):
Der Aufbau des Projekts
Du benötigst für dieses Projekt deinen ESP8266, zwei Buttons, ein OLED-Display (128×64 Pixel), ein Breadboard und Kabel. Orientiere dich beim Aufbau an folgendem Schema:

Wie du siehst, ist jeweils ein Pin der Buttons mit GND verbunden. Die anderen Pins hängen an deinem ESP8266 an den Pins D5 und D6.
Das OLED-Display kommuniziert mit deinem ESP8266 über I²C. Schließe die 4 Pins deshalb wie folgt an:
OLED-Display | ESP8266 |
GND | GND |
VCC | 3v3 |
SCL | D1 |
SDA | D2 |
Der Sketch
Öffne den Sketch über den folgenden Link, kopiere ihn in deine Arduino IDE, ergänze deine Daten und lade ihn auf deinen ESP8266. Du findest den Sketch auch ganz am Ende dieses Projekts.
Was ist neu in diesem Sketch?
Zunächst hast du in diesem Projekt ein neues Bauteil verbaut: das OLED-Display. Hierfür benötigst du zwei weitere Bibliotheken, die du bereits zu Beginn dieses Kurses installiert hast. Wenn nicht, schaue dir noch einmal den Abschnitt Bibliotheken installieren an.
Du bindest also die beiden Bibliotheken für das Display zu Beginn deines Sketchs ein:
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Anschließend definierst du die Größe des Displays und initialisierst es:
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
In der Setup-Funktion prüfst du, ob das Display richtig angeschlossen ist (ähnlich wie in den vorangegangenen Projekten mit dem Sensor BMP180). Danach stellst du sicher, dass beim Start des Sketchs alles vom Display gelöscht wird, was darauf noch zu sehen sein könnte:
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { //Display-Adresse: 0x3C
Serial.println(F("Display nicht gefunden. Checke die Verbindung."));
for (;;);
}
display.clearDisplay();
display.display();
Die Buttons
Die beiden Buttons funktionieren so ähnlich wie der Bewegungsmelder im ersten Projekt: Werden sie gedrückt, wird per Interrupt eine Callback-Funktion ausgelöst, die eine Variable auf true setzt. Dein Loop erkennt dies, sendet die entsprechende Nachricht an deinen Telegram-Bot und setzt die Variable wieder auf false.
if (button1pressed == true) {
bot.sendMessage(userID, "\xF0\x9F\x98\x8A", "");
Serial.println("Button 1");
button1pressed = false;
}
Alle Konstanten, Variablen und Funktionen hierfür (du benötigst jeweils zwei, da du zwei Buttons hast) definierst du zu Beginn des Sketchs:
const int button1 = 14; //Am ESP8266 Pin D5
const int button2 = 12; //Am ESP8266 Pin D6
bool button1pressed = false;
bool button2pressed = false;
// Callback-Funktion für Button 1
void IRAM_ATTR button1Pressed() {
button1pressed = true;
}
// Callback-Funktion für Button 2
void IRAM_ATTR button2Pressed() {
button2pressed = true;
}
In der Setup-Funktion definierst du dann noch die pinModes für die Buttons. INPUT_PULLUP bedeutet, dass du den internen Pullup-Widerstand deines ESP8266 verwendest. Würdest du das nicht tun, würden die Buttons kein zuverlässiges Signal geben und immer zwischen true und false hin- und herspringen.
Fehlt noch für jeden Button die Funktion attachInterrupt() – hier legst du fest, welche der obigen Callback-Funktion das Drücken des jeweiligen Buttons auslösen soll. Wenn du mehr über Interrupts lernen möchtest: In der Arduino-Referenz erfährst du weitere Details.
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button1), button1Pressed, RISING);
attachInterrupt(digitalPinToInterrupt(button2), button2Pressed, RISING);
Die Funktion handleNewRequests()
Auch hier bleibt vieles gleich, eine Sache ist jedoch neu: Statt Befehle wie /lichtEin verwendest du hier Emojis. Diese kannst du leider nicht direkt in deinen Sketch eintragen, sondern musst sie in UTF-8 codieren. Glücklicherweise gibt es eine praktische Tabelle, in der du in der Spalte Bytes (UTF-8) den entsprechenden Code findest.
Ein lachender Smiley 🙂 entspricht z.B. dem Code \xF0\x9F\x98\x8A
Der Code für deine Willkommensnachricht sieht im Sketch also wie folgt aus:
if (text == "/start") {
welcome = "Willkommen, " + from_name + ".\n";
welcome += "Folgende Emojis kannst du verwenden: \n\n";
welcome += "\xF0\x9F\x9A\x97 \n";
welcome += "\xF0\x9F\x98\x8A \n";
bot.sendMessage(chat_id, welcome, "");
}
Auf deinem Smartphone erscheinen dann die entsprechenden Emojis:

Wenn du jetzt eines dieser Emojis versendest, soll es ja auf dem OLED-Display erscheinen. Leider geht das nicht 1:1 – vielmehr empfängt dein ESP8266 das Emoji vom Smartphone (ebenfalls codiert in UTF-8) und nimmt das zum Anlass, ein im Sketch hinterlegtes Bild auf das Display zu zeichnen – das in diesem Fall dem gesendeten Emoji ähnelt.

In der Funktion handleNewRequests() sieht das folgendermaßen aus:
if (text == "\xF0\x9F\x9A\x97") { //das in UTF-8 codierte Emoji
display.clearDisplay(); //Display löschen
display.drawBitmap(0, 0, car, 128, 64, WHITE); //Icon zeichnen...
display.display(); //...und anzeigen
}
Die Funktion display.drawBitmap() müssen wir uns genauer anschauen. Hier findest du den Parameter car. Das ist das Emoji auf dem Bild oben – allerdings nicht als Bild, sondern als Ansammlung von Hexadezimal-Zahlen, gespeichert in einer Konstanten mit dem Datentyp char.
Wirf hier einen Blick auf den Code für dieses Emoji. Mit etwas Phantasie kannst du in diesem Wust aus Zeichen ein Bild erkennen. Dein ESP8266 macht das natürlich ohne Probleme.
Den Inhalt dieser Konstanten car nimmt nun also die Funktion display.drawBitmap() und zeichnet damit das Emoji auf das Display. Die Parameter 0, 0 bedeuten, dass die Funktion mit dem Zeichnen oben links (also x=0 und y=0) anfängt. 128, 64 definiert die Größe des Bilds – die der Größe deines Displays entspricht. WHITE hingegen definiert die Farbe, in der die Funktion zeichnet.
Und das war es schon. Wie du siehst, so wirklich neu ist nur das OLED-Display und die Anzeige von Bildern darauf. Die Buttons verhalten sich im Prinzip wie der Bewegungsmelder aus Projekt 1, nur dass du sie natürlich selbst bedienen musst.
Wie geht es weiter?
Du kannst jetzt Emojis zwischen deinem Zuhause und deinem Smartphone versenden. Wenn dir Zeichensprache nicht reicht, kannst du dieses Projekt natürlich so umbauen, dass richtiger Text versendet und empfangen wird.
Hier nun der gesamte Sketch:
/*
Emojis nach Hause senden mit Telegram - polluxlabs.net
*/
//Auto für das Display
// 'car', 128x64px
const unsigned char car [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xcf, 0xff, 0xff, 0xf9, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1f, 0xff, 0xff, 0xf8, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x38, 0x19, 0x80, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x70, 0x19, 0x80, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0xe0, 0x19, 0x80, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0xc0, 0x19, 0x80, 0x18, 0x38, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x00, 0x19, 0x80, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xce, 0x00, 0x19, 0x80, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x00, 0x19, 0x80, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xfe, 0x3f, 0xff, 0xff, 0xfc, 0x78, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x3f, 0xff, 0xff, 0xfc, 0x70, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x00, 0x00, 0x06, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x0c, 0x00, 0x00, 0x66, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfe, 0x0c, 0x00, 0x00, 0xf6, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc6, 0x0c, 0x00, 0x00, 0x06, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfe, 0x0c, 0x00, 0x00, 0x06, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x00, 0x00, 0x06, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x0c, 0x00, 0x00, 0x06, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x0c, 0x00, 0x00, 0x06, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x7c, 0x00, 0x00, 0x06, 0x00, 0x3e, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc1, 0xff, 0x00, 0x00, 0x0c, 0x00, 0x7f, 0x83, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc3, 0x83, 0x80, 0x00, 0x0c, 0x00, 0xc1, 0xc3, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0xfc, 0xff, 0xff, 0xff, 0x80, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfe, 0x38, 0xfc, 0xff, 0xff, 0xff, 0x9e, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc6, 0x7c, 0xc0, 0x00, 0x00, 0x03, 0x3e, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc6, 0x6c, 0xc0, 0x00, 0x00, 0x03, 0x32, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfe, 0x7c, 0xff, 0xff, 0xff, 0xff, 0x3e, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xff, 0xff, 0xff, 0xff, 0x9c, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xc3, 0x80, 0x00, 0x00, 0x00, 0xe1, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
//Smiley für das Display
// 'smiley', 128x64px
const unsigned char smiley [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xe0, 0x07, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x1e, 0x00, 0x00, 0x78, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x3f, 0x00, 0x00, 0xfc, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x3f, 0x00, 0x00, 0xfc, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x3f, 0x00, 0x00, 0xfc, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x3f, 0x00, 0x00, 0xf8, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x0c, 0x00, 0x00, 0x70, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x0e, 0x00, 0x00, 0x70, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x1f, 0x00, 0x00, 0xf8, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x1f, 0x00, 0x01, 0xf8, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x1f, 0x80, 0x03, 0xf8, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x0f, 0xe0, 0x07, 0xf0, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x0f, 0xf8, 0x1f, 0xe0, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x07, 0xff, 0xff, 0xc0, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x03, 0xff, 0xff, 0x80, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0xff, 0xff, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x7f, 0xfc, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x0f, 0xf0, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xe0, 0x07, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
//Bibliotheken
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//OLED Display
#define SCREEN_WIDTH 128 // Breite des Displays in Pixeln
#define SCREEN_HEIGHT 64 // Höhe des Displays in Pixeln
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//Deine WLAN-Zugangsdaten
const char* ssid = "NETZWERKNAME";
const char* password = "PASSWORT";
//Den Telegram-Bot initialisieren
#define botToken "TOKEN" // den Bot-Token bekommst du vom Botfather)
//Deine UserID
#define userID "USERID"
WiFiClientSecure client;
UniversalTelegramBot bot(botToken, client);
//Variablen für die Buttons
const int button1 = 14; //Am ESP8266 Pin D5
const int button2 = 12; //Am ESP8266 Pin D6
bool button1pressed = false;
bool button2pressed = false;
// Callback-Funktion für Button 1
void IRAM_ATTR button1Pressed() {
button1pressed = true;
}
// Callback-Funktion für Button 2
void IRAM_ATTR button2Pressed() {
button2pressed = true;
}
//Variable für die Anzahl der Anfragen
int numNewRequests;
//Variable für den Text der Anfrage, die du sendest
String text = "";
//UserID des Absenders
String chat_id = "";
//Name des Absenders
String from_name = "";
//Variable für die Willkommensnachricht
String welcome = "";
//Funktion fürs Verarbeiten neuer Anfragen
void handleNewRequests(int numNewRequests) {
for (int i = 0; i < numNewRequests; i++) { //loopt durch die neuen Anfragen
//Checkt, ob du die Anfrage gesendet hast oder jemand anderes
chat_id = String(bot.messages[i].chat_id);
if (chat_id != userID) {
bot.sendMessage(chat_id, "Du bist nicht autorisiert!", "");
continue;
}
// Anfragetext speichern
text = bot.messages[i].text;
Serial.println(text);
from_name = bot.messages[i].from_name;
if (text == "/start") {
welcome = "Willkommen, " + from_name + ".\n";
welcome += "Folgende Emojis kannst du verwenden: \n\n";
welcome += "\xF0\x9F\x9A\x97 \n";
welcome += "\xF0\x9F\x98\x8A \n";
bot.sendMessage(chat_id, welcome, "");
}
if (text == "\xF0\x9F\x9A\x97") {
display.clearDisplay(); //Display löschen
display.drawBitmap(0, 0, car, 128, 64, WHITE); //Icon zeichnen...
display.display(); //...und anzeigen
}
if (text == "\xF0\x9F\x98\x8A") {
display.clearDisplay(); //Display löschen
display.drawBitmap(0, 0, smiley, 128, 64, WHITE); //Icon zeichnen...
display.display(); //...und anzeigen
}
}
}
void setup() {
Serial.begin(115200);
client.setInsecure();
// pinModes und Interrupts
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button1), button1Pressed, RISING);
attachInterrupt(digitalPinToInterrupt(button2), button2Pressed, RISING);
//Check, ob das Display verfügbar ist
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { //Display-Adresse: 0x3C
Serial.println(F("Display nicht gefunden. Checke die Verbindung."));
for (;;);
}
display.clearDisplay(); //Display löschen
display.display();
//Verbindung zum WLAN
Serial.print("Verbinde mich mit: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(300);
}
Serial.println("");
Serial.println("Verbunden!");
}
void loop() {
if (button1pressed == true) {
bot.sendMessage(userID, "\xF0\x9F\x98\x8A", "");
Serial.println("Button 1");
button1pressed = false;
}
else if (button2pressed == true) {
bot.sendMessage(userID, "\xF0\x9F\x98\x92", "");
Serial.println("Button 2");
button2pressed = false;
}
//checkt, ob eine neue Anfrage reinkam
int numNewRequests = bot.getUpdates(bot.last_message_received + 1);
while (numNewRequests) { //wird ausgeführt, wenn numNewRequests == 1
Serial.println("Anfrage erhalten");
handleNewRequests(numNewRequests);
numNewRequests = bot.getUpdates(bot.last_message_received + 1);
}
delay(1000);
}
Letzte Aktualisierung am 2.04.2023 / Affiliate Links / Bilder von der Amazon Product Advertising API