Skip to content

Commit

Permalink
Merge pull request #566 from blinker-iot/dev_3.0
Browse files Browse the repository at this point in the history
update codes
  • Loading branch information
i3water authored Mar 11, 2021
2 parents 73d7058 + c3bfc3f commit 500adf3
Show file tree
Hide file tree
Showing 11 changed files with 350 additions and 218 deletions.
18 changes: 18 additions & 0 deletions examples/Blinker_DuerOS/DuerOS_LIGHT/DuerOS_LIGHT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,22 @@ void duerRelativeBright(int32_t bright)
BlinkerDuerOS.print();
}

void duerColoTemp(int32_t colorTemp)
{
BLINKER_LOG("need set colorTemperature: ", colorTemp);

BlinkerDuerOS.colorTemp(colorTemp);
BlinkerDuerOS.print();
}

void duerRelativeColoTemp(int32_t colorTemp)
{
BLINKER_LOG("need set relative colorTemperature: ", colorTemp);

BlinkerDuerOS.colorTemp(colorTemp);
BlinkerDuerOS.print();
}

void duerQuery(int32_t queryCode)
{
BLINKER_LOG("DuerOS Query codes: ", queryCode);
Expand Down Expand Up @@ -309,6 +325,8 @@ void setup()
BlinkerDuerOS.attachCancelMode(duercMode);
BlinkerDuerOS.attachBrightness(duerBright);
BlinkerDuerOS.attachRelativeBrightness(duerRelativeBright);
BlinkerDuerOS.attachColorTemperature(duerColoTemp);
BlinkerDuerOS.attachRelativeColorTemperature(duerRelativeColoTemp);
BlinkerDuerOS.attachQuery(duerQuery);

pinMode(14, OUTPUT);
Expand Down
6 changes: 6 additions & 0 deletions examples/Blinker_Image/Image_WiFi/Image_WiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ BlinkerImage Image1("img_abc");

int counter = 0;

void image1_callback(int32_t num)
{
BLINKER_LOG("image is tapped, number is : ", num);
}

void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
Expand Down Expand Up @@ -85,6 +90,7 @@ void setup()
Blinker.attachData(dataRead);

Button1.attach(button1_callback);
Image1.attach(image1_callback);
}

void loop() {
Expand Down
19 changes: 5 additions & 14 deletions examples/Blinker_OTA/OTA_WiFi/OTA_WiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* if use ESP8266 with Blinker.
* https://github.com/esp8266/Arduino/releases
*
* Make sure installed 1.0.5 or later ESP32/Arduino package,
* Make sure installed 1.0.4 or later ESP32/Arduino package,
* if use ESP32 with Blinker.
* https://github.com/espressif/arduino-esp32/releases
*
Expand Down Expand Up @@ -58,9 +58,10 @@
char type[] = "Your Device Type";
char auth[] = "Your Device Secret Key";

#define BLINKER_OTA_BLINK_TIME 500
BlinkerButton Button1("btn-abc");
BlinkerNumber Number1("num-abc");

uint32_t os_time;
int counter = 0;

void button1_callback(const String & state)
{
Expand Down Expand Up @@ -141,19 +142,10 @@ void dataRead(const String & data)
Number1.print(counter);
}

// void otaStatus(uint32_t load_size, uint32_t total_size)
// {
// if (millis() - os_time >= BLINKER_OTA_BLINK_TIME)
// {
// os_time = millis();

// digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
// }
// }

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

pinMode(LED_BUILTIN, OUTPUT);
Expand All @@ -170,7 +162,6 @@ void setup()
Blinker.attachDoubleClick(doubleClick);
attachInterrupt(BLINKER_BUTTON_PIN, buttonTick, CHANGE);
#endif
// BlinkerUpdater.onProgress(otaStatus);
}

void loop()
Expand Down
3 changes: 3 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ attachLongPressPowerdown KEYWORD2
attachLongPressReset KEYWORD2
attachNoButtonReset KEYWORD2
attachAQI KEYWORD2
attachAir KEYWORD2
attachWeather KEYWORD2
attachWeatherForecast KEYWORD2
attachConfigGet KEYWORD2
attachDataGet KEYWORD2
pressedTime KEYWORD2
Expand Down Expand Up @@ -106,6 +108,7 @@ sms KEYWORD2
push KEYWORD2
wechat KEYWORD2
weather KEYWORD2
weatherForecast KEYWORD2
aqi KEYWORD2
status KEYWORD2
flush KEYWORD2
Expand Down
3 changes: 2 additions & 1 deletion src/Adapters/BlinkerBLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ int BlinkerBLE::print(char * data, bool needCheck)
s_send = s.substring(num*(20), s.length());
else
s_send = s.substring(num*(20), (num+1)*20);

// BLINKER_LOG_ALL("s_send: ", s_send);
pCharacteristic->setValue(s_send.c_str());
pCharacteristic->notify();
delay(5);
Expand All @@ -267,6 +267,7 @@ void BlinkerBLE::onDisconnect(BLEServer* pServer)
{
deviceConnected = false;
BLINKER_LOG_ALL("BLE disconnect");
pServer->startAdvertising();
}

void BlinkerBLE::onWrite(BLECharacteristic *pCharacteristic)
Expand Down
24 changes: 13 additions & 11 deletions src/Adapters/BlinkerMQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ void BlinkerMQTT::parseData(const char* data)
BLINKER_ERR_LOG_ALL(BLINKER_F("No authority uuid found, check is from bridge/share device, data: "), dataGet);

_needCheckShare = true;

dataGet = data;
}
}
}
Expand All @@ -880,13 +882,13 @@ void BlinkerMQTT::parseData(const char* data)
BLINKER_ERR_LOG_ALL(BLINKER_F("No authority&share uuid found, check is from bridge/share device, data: "), dataGet);

_needCheckShare = true;

dataGet = data;
}
// dataGet = String((char *)iotSub_MQTT->lastread);
// root.printTo(dataGet);
// serializeJson(root, dataGet);

dataGet = data;

// BLINKER_ERR_LOG_ALL(BLINKER_F("No authority uuid found,
// check is from bridge/share device, \
// data: "), dataGet);
Expand Down Expand Up @@ -1014,7 +1016,7 @@ int BlinkerMQTT::print(char * data, bool needCheck)
// data_add = BLINKER_F(",\"fromDevice\":\"");
// strcat(data, data_add.c_str());
strcat(data, ",\"fromDevice\":\"");
strcat(data, MQTT_ID_MQTT);
strcat(data, DEVICE_NAME_MQTT);
// data_add = BLINKER_F("\",\"toDevice\":\"");
// strcat(data, data_add.c_str());
strcat(data, "\",\"toDevice\":\"");
Expand Down Expand Up @@ -1212,7 +1214,7 @@ int BlinkerMQTT::bPrint(char * name, const String & data)

data_add += data;
data_add += BLINKER_F(",\"fromDevice\":\"");
data_add += MQTT_ID_MQTT;
data_add += DEVICE_NAME_MQTT;
data_add += BLINKER_F("\",\"toDevice\":\"");
data_add += name;
data_add += BLINKER_F("\",\"deviceType\":\"DiyBridge\"}");
Expand Down Expand Up @@ -1309,7 +1311,7 @@ int BlinkerMQTT::aliPrint(const String & data)

data_add += data;
data_add += BLINKER_F(",\"fromDevice\":\"");
data_add += MQTT_ID_MQTT;
data_add += DEVICE_NAME_MQTT;
data_add += BLINKER_F("\",\"toDevice\":\"AliGenie_r\"");
data_add += BLINKER_F(",\"deviceType\":\"vAssistant\"}");

Expand Down Expand Up @@ -1341,7 +1343,7 @@ int BlinkerMQTT::aliPrint(const String & data)
strcpy(BLINKER_RRPC_PUB_TOPIC_MQTT, "/sys/");
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_PRODUCTINFO_MQTT);
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/");
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_ID_MQTT);
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, DEVICE_NAME_MQTT);
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/rrpc/response/");
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, message_id);

Expand Down Expand Up @@ -1401,7 +1403,7 @@ int BlinkerMQTT::duerPrint(const String & data, bool report)
}

data_add += BLINKER_F(",\"fromDevice\":\"");
data_add += MQTT_ID_MQTT;
data_add += DEVICE_NAME_MQTT;
data_add += BLINKER_F("\",\"toDevice\":\"DuerOS_r\"");
data_add += BLINKER_F(",\"deviceType\":\"vAssistant\"}");

Expand Down Expand Up @@ -1434,7 +1436,7 @@ int BlinkerMQTT::duerPrint(const String & data, bool report)
strcpy(BLINKER_RRPC_PUB_TOPIC_MQTT, "/sys/");
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_PRODUCTINFO_MQTT);
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/");
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_ID_MQTT);
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, DEVICE_NAME_MQTT);
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/rrpc/response/");
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, message_id);

Expand Down Expand Up @@ -1487,7 +1489,7 @@ int BlinkerMQTT::miPrint(const String & data)

data_add += data;
data_add += BLINKER_F(",\"fromDevice\":\"");
data_add += MQTT_ID_MQTT;
data_add += DEVICE_NAME_MQTT;
data_add += BLINKER_F("\",\"toDevice\":\"MIOT_r\"");
data_add += BLINKER_F(",\"deviceType\":\"vAssistant\"}");

Expand Down Expand Up @@ -1519,7 +1521,7 @@ int BlinkerMQTT::miPrint(const String & data)
strcpy(BLINKER_RRPC_PUB_TOPIC_MQTT, "/sys/");
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_PRODUCTINFO_MQTT);
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/");
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, MQTT_ID_MQTT);
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, DEVICE_NAME_MQTT);
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, "/rrpc/response/");
strcat(BLINKER_RRPC_PUB_TOPIC_MQTT, message_id);

Expand Down Expand Up @@ -1669,7 +1671,7 @@ int BlinkerMQTT::autoPrint(unsigned long id)
payload += String(id);
payload += BLINKER_F("}}}");
payload += BLINKER_F(",\"fromDevice\":\"");
payload += STRING_format(MQTT_ID_MQTT);
payload += STRING_format(DEVICE_NAME_MQTT);
payload += BLINKER_F("\",\"deviceType\":\"Auto\"");
payload += BLINKER_F(",\"toDevice\":\"serverClient\"}");
// "\",\"deviceType\":\"" + "type" + "\"}";
Expand Down
Loading

0 comments on commit 500adf3

Please sign in to comment.