Blynk library for embedded hardware. Works with Arduino, ESP8266, Raspberry Pi, Intel Edison/Galileo, LinkIt ONE, Particle Core/Photon, Energia, ARM mbed, etc. http://www.blynk.cc/
Dependents: Blynk_RBL_BLE_Nano Blynk_MicroBit Blynk_Serial Blynk_RBL_BLE_Nano
Diff: Blynk/BlynkProtocol.h
- Revision:
- 19:bae78e167b11
- Parent:
- 18:c328c1a97f90
- Child:
- 21:fd9a3d7ddadb
--- a/Blynk/BlynkProtocol.h Wed Nov 29 14:05:41 2017 +0200 +++ b/Blynk/BlynkProtocol.h Fri Dec 15 00:17:41 2017 +0200 @@ -37,9 +37,6 @@ , lastActivityIn(0) , lastActivityOut(0) , lastHeartbeat(0) -#ifdef BLYNK_MSG_LIMIT - , deltaCmd(0) -#endif , msgIdOut(0) , msgIdOutOverride(0) , nesting(0) @@ -72,11 +69,8 @@ void startSession() { conn.connect(); state = CONNECTING; -#ifdef BLYNK_MSG_LIMIT - deltaCmd = 1000; -#endif msgIdOut = 0; - lastHeartbeat = lastActivityIn = lastActivityOut = BlynkMillis(); // TODO: - 5005UL + lastHeartbeat = lastActivityIn = lastActivityOut = (BlynkMillis() - 5000UL); } void sendCmd(uint8_t cmd, uint16_t id = 0, const void* data = NULL, size_t length = 0, const void* data2 = NULL, size_t length2 = 0); @@ -95,6 +89,7 @@ protected: void begin(const char* auth) { this->authkey = auth; + lastHeartbeat = lastActivityIn = lastActivityOut = (BlynkMillis() - 5000UL); #if defined(BLYNK_NO_FANCY_LOGO) BLYNK_LOG1(BLYNK_F("Blynk v" BLYNK_VERSION " on " BLYNK_INFO_DEVICE)); @@ -133,9 +128,6 @@ millis_time_t lastHeartbeat; millis_time_t lastLogin; }; -#ifdef BLYNK_MSG_LIMIT - millis_time_t deltaCmd; -#endif uint16_t msgIdOut; uint16_t msgIdOutOverride; uint8_t nesting; @@ -155,7 +147,7 @@ // Detect nesting BlynkHelperAutoInc guard(nesting); if (msgIdOutOverride || nesting > 2) { -#ifdef BLYNK_DEBUG +#ifdef BLYNK_DEBUG_ALL BLYNK_LOG1(BLYNK_F("Nested run() skipped")); #endif return true; @@ -224,9 +216,6 @@ return false; } -#ifdef BLYNK_MSG_LIMIT - deltaCmd = 1000; -#endif msgIdOut = 1; sendCmd(BLYNK_CMD_LOGIN, 1, authkey, strlen(authkey)); lastLogin = lastActivityOut; @@ -300,7 +289,7 @@ uint8_t inputBuffer[hdr.length+1]; // Add 1 to zero-terminate if (hdr.length != conn.read(inputBuffer, hdr.length)) { -#ifdef DEBUG +#ifdef BLYNK_DEBUG BLYNK_LOG1(BLYNK_F("Can't read body")); #endif return false; @@ -383,7 +372,7 @@ case BLYNK_INT_OTA: BlynkWidgetWriteInternalPinOTA(req, param2); break; case BLYNK_INT_ACON: BlynkWidgetWriteInternalPinACON(req, param2); break; case BLYNK_INT_ADIS: BlynkWidgetWriteInternalPinADIS(req, param2); break; -#ifdef DEBUG +#ifdef BLYNK_DEBUG default: BLYNK_LOG2(BLYNK_F("Invalid internal cmd:"), param.asStr()); #endif } @@ -437,7 +426,7 @@ void BlynkProtocol<Transp>::sendCmd(uint8_t cmd, uint16_t id, const void* data, size_t length, const void* data2, size_t length2) { if (!conn.connected() || (cmd != BLYNK_CMD_RESPONSE && cmd != BLYNK_CMD_PING && cmd != BLYNK_CMD_LOGIN && state != CONNECTED) ) { -#ifdef BLYNK_DEBUG +#ifdef BLYNK_DEBUG_ALL BLYNK_LOG2(BLYNK_F("Cmd skipped:"), cmd); #endif return; @@ -452,13 +441,15 @@ const millis_time_t allowed_time = BlynkMax(lastActivityOut, lastActivityIn) + 1000/BLYNK_MSG_LIMIT; long wait_time = allowed_time - BlynkMillis(); if (wait_time >= 0) { -#ifdef BLYNK_DEBUG +#ifdef BLYNK_DEBUG_ALL BLYNK_LOG2(BLYNK_F("Waiting:"), wait_time); #endif while (wait_time >= 0) { run(); wait_time = allowed_time - BlynkMillis(); } + } else if (nesting == 0) { + run(); } } #endif @@ -467,7 +458,7 @@ (data ? length : 0) + (data2 ? length2 : 0); -#if defined(BLYNK_SEND_ATOMIC) || defined(ESP8266) || defined(SPARK) || defined(PARTICLE) || defined(ENERGIA) +#if defined(BLYNK_SEND_ATOMIC) || defined(ESP8266) || defined(ESP32) || defined(SPARK) || defined(PARTICLE) || defined(ENERGIA) // Those have more RAM and like single write at a time... uint8_t buff[full_length];