|
#define BLINKER_PRO_ESP
#define BLINKER_BUTTON
#define BLINKER_BUTTON_LONGPRESS_POWERDOWN
#define BLINKER_BUTTON_PIN 4
#define BLINKER_OTA_VERSION_CODE "0.1.1"
#include <Blinker.h>
char type[] = "FVozFbCAJ3KJ";
char auth[] = "4tuXJQuBWW2R";
BlinkerButton Button1("btn-abc");
BlinkerNumber Number1("num-abc");
int counter = 0;
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
bool dataParse(const JsonObject & data)
{
String getData;
serializeJson(data, getData);
BLINKER_LOG("Get user command: ", getData);
// if you parsed this data, return TRUE.
// return true;
return false;
}
void heartbeat()
{
BLINKER_LOG("heartbeat!");
}
#if defined(BLINKER_BUTTON)
ICACHE_RAM_ATTR void buttonTick()
{
Blinker.tick();
}
void singleClick()
{
BLINKER_LOG("Button clicked!");
}
/*
* Add your code in this function
*
* When button double clicked, device will call this function
*/
void doubleClick()
{
BLINKER_LOG("Button double clicked!");
}
/*
* Add your code in this function
*
* When long press start, device will call this function
*/
void longPressStart()
{
BLINKER_LOG("Button long press start!");
}
/*
* Add your code in this function
*
* When during long press, device will call this function
*/
void duringLongPress()
{
// BLINKER_LOG("During button long press!");
uint16_t pressed_time = Blinker.pressedTime();
if (pressed_time >= 5000 && Blinker.configType() != BLINKER_AP_CONFIG)
{
Blinker.esptouchInit();
}
}
#endif
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, type);
Blinker.attachData(dataRead);
Blinker.attachParse(dataParse);
Blinker.attachHeartbeat(heartbeat);
Button1.attach(button1_callback);
#if defined(BLINKER_BUTTON)
Blinker.attachClick(singleClick);
Blinker.attachDoubleClick(doubleClick);
Blinker.attachLongPressStart(longPressStart);
Blinker.attachDuringLongPress(duringLongPress);
attachInterrupt(BLINKER_BUTTON_PIN, buttonTick, CHANGE);
#endif
}
void loop()
{
Blinker.run();
}
|
|