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:
- 3:31e4b850b126
- Parent:
- 0:58b20b438383
- Child:
- 7:8879692d4e6c
--- a/Blynk/BlynkProtocol.h Fri Jun 24 00:58:58 2016 +0300 +++ b/Blynk/BlynkProtocol.h Fri Jun 24 01:10:02 2016 +0300 @@ -65,8 +65,9 @@ bool run(bool avail = false); + // TODO: Fixme void startSession() { - //TODO: conn.connect(); + conn.connect(); state = CONNECTING; #ifdef BLYNK_MSG_LIMIT deltaCmd = 1000; @@ -102,6 +103,7 @@ millis_time_t deltaCmd; #endif uint16_t currentMsgId; +protected: BlynkState state; }; @@ -185,6 +187,10 @@ lastLogin = lastActivityOut; return true; } +#else + } else if (state == CONNECTING) { + if (!tconn) + conn.connect(); #endif } return true; @@ -203,7 +209,7 @@ if (ret < 0 || hdr.msg_id == 0) { #ifdef BLYNK_DEBUG - BLYNK_LOG1(BLYNK_F("Wrong header on input")); + BLYNK_LOG2(BLYNK_F("Bad hdr len: "), ret); #endif return false; } @@ -245,7 +251,9 @@ #ifdef BLYNK_DEBUG BLYNK_LOG2(BLYNK_F("Packet too big: "), hdr.length); #endif - return false; + // TODO: Flush + conn.connect(); + return true; } uint8_t inputBuffer[hdr.length+1]; // Add 1 to zero-terminate @@ -263,17 +271,25 @@ switch (hdr.type) { + case BLYNK_CMD_LOGIN: { #ifdef BLYNK_USE_DIRECT_CONNECT - case BLYNK_CMD_LOGIN: { if (!strncmp(authkey, (char*)inputBuffer, 32)) { + BLYNK_LOG1(BLYNK_F("Ready")); state = CONNECTED; sendCmd(BLYNK_CMD_RESPONSE, hdr.msg_id, NULL, BLYNK_SUCCESS); this->sendInfo(); + BlynkOnConnected(); } else { + BLYNK_LOG1(BLYNK_F("Invalid token")); sendCmd(BLYNK_CMD_RESPONSE, hdr.msg_id, NULL, BLYNK_INVALID_TOKEN); } +#else + BLYNK_LOG1(BLYNK_F("Ready")); + state = CONNECTED; + sendCmd(BLYNK_CMD_RESPONSE, hdr.msg_id, NULL, BLYNK_SUCCESS); + this->sendInfo(); +#endif } break; -#endif case BLYNK_CMD_PING: { sendCmd(BLYNK_CMD_RESPONSE, hdr.msg_id, NULL, BLYNK_SUCCESS); } break; @@ -287,6 +303,8 @@ #ifdef BLYNK_DEBUG BLYNK_LOG2(BLYNK_F("Invalid header type: "), hdr.type); #endif + // TODO: Flush + conn.connect(); } break; } @@ -304,10 +322,12 @@ if (sizeof(hdr) != rlen) { return -1; } + + BLYNK_DBG_DUMP(">", &hdr, sizeof(BlynkHeader)); + hdr.msg_id = ntohs(hdr.msg_id); hdr.length = ntohs(hdr.length); - BLYNK_DBG_DUMP(">", &hdr, sizeof(BlynkHeader)); return rlen; }