You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.2 KiB
79 lines
2.2 KiB
#include <Arduino.h>
|
|
#include <BluetoothSerial.h>
|
|
#include <esp_system.h>
|
|
|
|
#define LED_PIN 2
|
|
|
|
String device_name = "ESP-menu-Skrabanek";
|
|
BluetoothSerial SerialBT;
|
|
|
|
unsigned long lastStatusTime = 0;
|
|
const unsigned long statusInterval = 10000; //10 vterin
|
|
|
|
void posliMenu() {
|
|
SerialBT.println("\n--- HLAVNI MENU ---");
|
|
SerialBT.println("1 - Zapnout LED");
|
|
SerialBT.println("2 - Vypnout LED");
|
|
SerialBT.println("3 - Info o systemu");
|
|
SerialBT.println("4 - MAC adresa zarizeni");
|
|
SerialBT.println("m - zobrazit toto menu");
|
|
SerialBT.println("--------------------");
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
SerialBT.begin(device_name);
|
|
pinMode(LED_PIN,OUTPUT);
|
|
Serial.println("Projekt menu spusten");
|
|
}
|
|
|
|
void loop() {
|
|
if(SerialBT.available()) {
|
|
//získání znaku
|
|
char volba = SerialBT.read();
|
|
// X -> Enter -> ['X','\r','\n']
|
|
//je potřeba čistit tzv.buffer (např. konce řádků)
|
|
while(SerialBT.available() && (SerialBT.peek() == '\n' || SerialBT.peek() == '\r')){
|
|
SerialBT.read();
|
|
}
|
|
switch(volba){
|
|
case '1':
|
|
digitalWrite(LED_PIN,HIGH);
|
|
SerialBT.println(">> LED zapnuta");
|
|
break;
|
|
case '2':
|
|
digitalWrite(LED_PIN,LOW);
|
|
SerialBT.println(">> LED vypnuta");
|
|
break;
|
|
case '3':
|
|
SerialBT.print(">> Uptime: ");
|
|
SerialBT.print(millis()/1000);
|
|
SerialBT.println(" sekund");
|
|
break;
|
|
case '4':
|
|
uint8_t mac[6];
|
|
//přeřteme Bluetooth MAC adresu
|
|
esp_read_mac(mac,ESP_MAC_BT);
|
|
char macStr[18];
|
|
sprintf(macStr,"%02X:%02X:%02X:%02X:%02X:%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
|
|
SerialBT.print(">> MAC Adresa(BT): ");
|
|
SerialBT.println(macStr);
|
|
break;
|
|
case 'm':
|
|
case 'M':
|
|
posliMenu();
|
|
break;
|
|
default:
|
|
SerialBT.println(">> Neplatná volba. Napiš 'm' pro menu.");
|
|
break;
|
|
}
|
|
}
|
|
//pravidelné posílání stavu
|
|
if(millis() - lastStatusTime >= statusInterval){
|
|
lastStatusTime = millis();
|
|
if(SerialBT.hasClient()){//pošleme pokud je někdo připojen
|
|
SerialBT.println("\n[INFO] System bezi v poradku...");
|
|
Serial.println("\n[INFO] System bezi v poradku...");
|
|
}
|
|
}
|
|
}
|
|
|