Skip to content

Commit

Permalink
Merge pull request #536 from blinker-iot/dev_3.0
Browse files Browse the repository at this point in the history
Dev 3.0
  • Loading branch information
i3water authored Dec 4, 2019
2 parents 2298fd1 + 95f9784 commit 886cff5
Show file tree
Hide file tree
Showing 32 changed files with 787 additions and 99 deletions.
52 changes: 48 additions & 4 deletions examples/Blinker_DuerOS/DuerOS_OUTLET/DuerOS_OUTLET.ino
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,43 @@ char auth[] = "Your Device Secret Key";
char ssid[] = "Your WiFi network SSID or name";
char pswd[] = "Your WiFi network WPA password or WEP key";

#define BUTTON_1 "ButtonKey"

BlinkerButton Button1(BUTTON_1);

bool oState = false;

void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);

if (state == BLINKER_CMD_ON) {
BLINKER_LOG("Toggle on!");

Button1.icon("icon_1");
Button1.color("#FFFFFF");
Button1.text("Your button name or describe");
Button1.print("on");

oState = true;
}
else if (state == BLINKER_CMD_OFF) {
BLINKER_LOG("Toggle off!");

Button1.icon("icon_1");
Button1.color("#FFFFFF");
Button1.text("Your button name or describe");
Button1.print("off");

oState = false;
}

BlinkerDuerOS.powerState(oState ? "on" : "off");
BlinkerDuerOS.report();

digitalWrite(LED_BUILTIN, oState);
}

void duerPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
Expand Down Expand Up @@ -82,13 +117,18 @@ void duerQuery(int32_t queryCode)

switch (queryCode)
{
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("DuerOS Query power state");
BlinkerDuerOS.powerState(oState ? "on" : "off");
BlinkerDuerOS.print();
break;
case BLINKER_CMD_QUERY_TIME_NUMBER :
BLINKER_LOG("DuerOS Query time");
BlinkerDuerOS.time(millis());
BlinkerDuerOS.print();
break;
default :
BlinkerDuerOS.time(millis());
BlinkerDuerOS.powerState(oState ? "on" : "off");
BlinkerDuerOS.print();
break;
}
Expand All @@ -98,17 +138,21 @@ void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);

Blinker.vibrate();
// Blinker.vibrate();

uint32_t BlinkerTime = millis();
// uint32_t BlinkerTime = millis();

Blinker.print("millis", BlinkerTime);
// Blinker.print("millis", BlinkerTime);

BlinkerDuerOS.powerState("off");
BlinkerDuerOS.report();
}

void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();

pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Expand Down
102 changes: 92 additions & 10 deletions examples/Blinker_OTA/OTA_WiFi/OTA_WiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,102 @@
*
* *****************************************************************/

#define BLINKER_WIFI
#define BLINKER_PRO_ESP
#define BLINKER_BUTTON
#if defined(ESP32)
#define BLINKER_BUTTON_PIN 4
#else
#define BLINKER_BUTTON_PIN D7
#endif

#define BLINKER_OTA_VERSION_CODE "0.1.1"

#include <Blinker.h>

char type[] = "Your Device Type";
char auth[] = "Your Device Secret Key";
char ssid[] = "Your WiFi network SSID or name";
char pswd[] = "Your WiFi network WPA password or WEP key";

#define BLINKER_OTA_BLINK_TIME 500

uint32_t os_time;

void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

/*
* Add your command parse code in this function
*
* When get a command and device not parsed this command, device will call this function
*/
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;
}

/*
* Add your heartbeat message detail in this function
*
* When get heartbeat command {"get": "state"}, device will call this function
* For example, you can print message back
*
* Every 30s will get a heartbeat command from app
*/
void heartbeat()
{
BLINKER_LOG("heartbeat!");
}

#if defined(BLINKER_BUTTON)
/*
* Blinker provide a button parse function for user if you defined BLINKER_BUTTON
*
* Blinker button can detect singal click/ double click/ long press
*
* Blinker.tick() will run by default, use interrupt will be better
*/
ICACHE_RAM_ATTR void buttonTick()
{
Blinker.tick();
}

/*
* Add your code in this function
*
* When button clicked, device will call this function
*/
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!");
}
#endif

void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);

Blinker.vibrate();

uint32_t BlinkerTime = millis();

Blinker.print("millis", BlinkerTime);
counter++;
Number1.print(counter);
}

// void otaStatus(uint32_t load_size, uint32_t total_size)
Expand All @@ -80,14 +154,22 @@ void dataRead(const String & data)
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();

pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);

Blinker.begin(auth, ssid, pswd);
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);
attachInterrupt(BLINKER_BUTTON_PIN, buttonTick, CHANGE);
#endif
// BlinkerUpdater.onProgress(otaStatus);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
// #define BLINKER_BUTTON
// #define BLINKER_BUTTON_PIN D7

#define BLINKER_OTA_VERSION_CODE "0.1.1"

#include <Blinker.h>

/*
Expand Down
13 changes: 2 additions & 11 deletions examples/Blinker_PRO/Blinker_PRO_ESP/Blinker_PRO_ESP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@
*
* *****************************************************************/

/*
* BLINKER_PRO is use for professional device
*
* Please make sure you have permission to modify professional device!
* Please read usermanual first! Thanks!
* https://doc.blinker.app/
*
* Written by i3water for blinker.
* Learn more:https://blinker.app/
*/

#define BLINKER_PRO_ESP
#define BLINKER_BUTTON
#if defined(ESP32)
Expand All @@ -62,6 +51,8 @@
#define BLINKER_BUTTON_PIN D7
#endif

#define BLINKER_OTA_VERSION_CODE "0.1.1"

#include <Blinker.h>

char type[] = "Your Device Type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#define BLINKER_BUTTON_PIN D7
#endif

#define BLINKER_OTA_VERSION_CODE "0.1.1"

#include <Blinker.h>

char type[] = "Your Device Type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
// #define BLINKER_BUTTON
// #define BLINKER_BUTTON_PIN D7

#define BLINKER_OTA_VERSION_CODE "0.1.1"

#include <Blinker.h>

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#define BLINKER_BUTTON_PIN D7
#endif

#define BLINKER_OTA_VERSION_CODE "0.1.1"

#include <Blinker.h>

char type[] = "Your Device Type";
Expand Down
2 changes: 2 additions & 0 deletions examples/Blinker_PRO_Wlan_Config/Blinker_PRO_Wlan_Config.ino
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
#define BLINKER_BUTTON_PIN D7
#endif

#define BLINKER_OTA_VERSION_CODE "0.1.1"

#include <Blinker.h>

char type[] = "Your Device Type";
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ ppm KEYWORD2
co2 KEYWORD2
mode KEYWORD2
tab KEYWORD2
report KEYWORD2

stream KEYWORD2
debugAll KEYWORD2
Expand Down
6 changes: 3 additions & 3 deletions src/Adapters/BlinkerAIR202LP.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int BlinkerAIR202LP::print(char * data, bool needCheck)
msg += data;
msg += BLINKER_F("}");

String host = BLINKER_F("https://iot.diandeng.tech");
String host = BLINKER_F(BLINKER_SERVER_HTTPS);
String url_iot = BLINKER_F("/api/v1/user/device/lowpower/data");

BLINKER_LOG_ALL(BLINKER_F("HTTPS begin: "), host + url_iot);
Expand Down Expand Up @@ -139,7 +139,7 @@ int BlinkerAIR202LP::print(char * data, bool needCheck)

void BlinkerAIR202LP::dataGet()
{
String host = BLINKER_F("https://iot.diandeng.tech");
String host = BLINKER_F(BLINKER_SERVER_HTTPS);
String uri = "";
uri += BLINKER_F("/api/v1/user/device/lowpower/data?deviceName=");
uri += _deviceName;
Expand Down Expand Up @@ -232,7 +232,7 @@ void BlinkerAIR202LP::initStream(Stream& s, bool state, blinker_callback_t func)

int BlinkerAIR202LP::connectServer()
{
String host = BLINKER_F("https://iot.diandeng.tech");
String host = BLINKER_F(BLINKER_SERVER_HTTPS);
String uri = "";
if (!_isAuthKey)
{
Expand Down
18 changes: 9 additions & 9 deletions src/Adapters/BlinkerGateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class BlinkerGateway : public BlinkerStream
int bPrint(char * name, const String & data);
int aliPrint(const String & data);
int subAliPrint(const String & data, const String & subDevice);
int duerPrint(const String & data);
int duerPrint(const String & data, bool report = false);
int subDuerPrint(const String & data, const String & subDevice);
int miPrint(const String & data);
int subMiPrint(const String & data, const String & subDevice);
Expand Down Expand Up @@ -1254,7 +1254,7 @@ int BlinkerGateway::subAliPrint(const String & data, const String & subDevice)
}
}

int BlinkerGateway::duerPrint(const String & data)
int BlinkerGateway::duerPrint(const String & data, bool report)
{
String data_add = BLINKER_F("{\"data\":");

Expand Down Expand Up @@ -1695,15 +1695,15 @@ int BlinkerGateway::authCheck()
int BlinkerGateway::connectServer() {
const int httpsPort = 443;
#if defined(ESP8266)
String host = BLINKER_F("iot.diandeng.tech");
String host = BLINKER_F(BLINKER_SERVER_HOST);
client_mqtt.stop();
#elif defined(ESP32)
String host = BLINKER_F("https://iot.diandeng.tech");
String host = BLINKER_F(BLINKER_SERVER_HTTPS);
#endif
if (!_isAuthKey)
{
#if defined(ESP8266)
// String host = BLINKER_F("iot.diandeng.tech");
// String host = BLINKER_F(BLINKER_SERVER_HOST);
String fingerprint = BLINKER_F("84 5f a4 8a 70 5e 79 7e f5 b3 b4 20 45 c8 35 55 72 f6 85 5a");

// WiFiClientSecure client_s;
Expand Down Expand Up @@ -1892,7 +1892,7 @@ int BlinkerGateway::connectServer() {
}

#elif defined(ESP32)
// String host = BLINKER_F("https://iot.diandeng.tech");
// String host = BLINKER_F(BLINKER_SERVER_HTTPS);
// const char* ca = \
// "-----BEGIN CERTIFICATE-----\n" \
// "MIIEgDCCA2igAwIBAgIQDKTfhr9lmWbWUT0hjX36oDANBgkqhkiG9w0BAQsFADBy\n" \
Expand Down Expand Up @@ -3272,10 +3272,10 @@ bool BlinkerGateway::subRegister(uint32_t num)
{
const int httpsPort = 443;
#if defined(ESP8266)
String host = BLINKER_F("iot.diandeng.tech");
String host = BLINKER_F(BLINKER_SERVER_HOST);
client_mqtt.stop();
#elif defined(ESP32)
String host = BLINKER_F("https://iot.diandeng.tech");
String host = BLINKER_F(BLINKER_SERVER_HTTPS);
#endif

#if defined(ESP8266)
Expand Down Expand Up @@ -3576,7 +3576,7 @@ String BlinkerGateway::blinkerServer(uint8_t _type, const String & msg)
#endif

#ifndef BLINKER_LAN_DEBUG
String host = BLINKER_F("https://iot.diandeng.tech");
String host = BLINKER_F(BLINKER_SERVER_HTTPS);
#elif defined(BLINKER_LAN_DEBUG)
String host = BLINKER_F("http://192.168.1.121:9090");
#endif
Expand Down
Loading

0 comments on commit 886cff5

Please sign in to comment.