diff --git a/19_m1284p_WIZNET_blynk/Application/Blynk/blynk.c b/19_m1284p_WIZNET_blynk/Application/Blynk/blynk.c index d9006df..7ee58d9 100644 --- a/19_m1284p_WIZNET_blynk/Application/Blynk/blynk.c +++ b/19_m1284p_WIZNET_blynk/Application/Blynk/blynk.c @@ -760,3 +760,14 @@ static void replacetonull(uint8_t * str, uint8_t c) for (x = 0; str[x]; x++) if (str[x] == c) str[x] = NULL; } + +uint8_t is_blynk_connection_available(void) +{ + return blynk_connection_available; +} + +//Requests Server to re-send current values for all widgets +void blynk_syncAll(void) +{ + sendCmd(BLYNK_CMD_HARDWARE_SYNC, 0, NULL, 0, NULL, 0); +} diff --git a/19_m1284p_WIZNET_blynk/Application/Blynk/blynk.h b/19_m1284p_WIZNET_blynk/Application/Blynk/blynk.h index 347e6a0..d90290e 100644 --- a/19_m1284p_WIZNET_blynk/Application/Blynk/blynk.h +++ b/19_m1284p_WIZNET_blynk/Application/Blynk/blynk.h @@ -79,6 +79,7 @@ enum BlynkCmd BLYNK_CMD_EMAIL = 13, BLYNK_CMD_PUSH_NOTIFICATION = 14, BLYNK_CMD_BRIDGE = 15, + BLYNK_CMD_HARDWARE_SYNC = 16, BLYNK_CMD_HARDWARE = 20 }; @@ -136,6 +137,9 @@ BlynkParam; void blynk_begin(uint8_t * auth, uint8_t * dest_ip, uint16_t dest_port, uint8_t * buf, uint8_t socket); void blynk_run(void); -void blynk_time_handler(void); +//void blynk_time_handler(void); +uint8_t is_blynk_connection_available(void); +void sendCmd(uint8_t cmd, uint16_t id, uint8_t * data, size_t length, uint8_t * data2, size_t length2); +void blynk_syncAll(void); #endif diff --git a/19_m1284p_WIZNET_blynk/main.c b/19_m1284p_WIZNET_blynk/main.c index 8a77944..a100a85 100644 --- a/19_m1284p_WIZNET_blynk/main.c +++ b/19_m1284p_WIZNET_blynk/main.c @@ -63,7 +63,7 @@ uint8_t Domain_IP[4] = {0, }; // Translated IP address by DNS S * OK (v1.3)GPIO IN - fixed bug (remove redundant space symbol in ) * Virtual IN/OUT -Not fully supported yet, so decide not use here.. * OK (v1.4)Analog Read/Write - * Restore pins state on board reboot + * OK (v1.5)Restore pins state on board reboot * OK ??3.Try fix frequent reconnection with blynk server - every ~22sec may be this OK. * Need compare local blynk.c code with modern library - (Too old version here - 0.2.1 (On git blynk March 2019 - 0.6.x) ) * @@ -100,7 +100,7 @@ volatile unsigned long _millis; // for millis tick !! Overflow every ~49.7 days //*********Program metrics const char compile_date[] PROGMEM = __DATE__; // Mmm dd yyyy - Дата компиляции const char compile_time[] PROGMEM = __TIME__; // hh:mm:ss - Время компиляции -const char str_prog_name[] PROGMEM = "\r\nAtMega1284p v1.4 Static IP BLYNK WIZNET_5500 ETHERNET 14/03/2019\r\n"; // Program name +const char str_prog_name[] PROGMEM = "\r\nAtMega1284p v1.5 Static IP BLYNK WIZNET_5500 ETHERNET 14/03/2019\r\n"; // Program name #if defined(__AVR_ATmega128__) const char PROGMEM str_mcu[] = "ATmega128"; //CPU is m128 @@ -497,7 +497,8 @@ int main() /* Loopback Test: TCP Server and UDP */ // Test for Ethernet data transfer validation - uint32_t timer_link_1sec = millis(); + uint32_t timer_tick_1sec = millis(); + uint8_t blynk_restore_connection = 1; while(1) { //Here at least every 1sec @@ -515,22 +516,23 @@ int main() //loopback_ret = loopback_tcpc(SOCK_TCPS, gDATABUF, destip, destport); //if(loopback_ret < 0) printf("loopback ret: %ld\r\n", loopback_ret); // TCP Socket Error code - //Shouldn't use it here - /* - if((millis()-timer_link_1sec)> 1000) + //Here every 1sec + if((millis()-timer_tick_1sec)> 1000) { //here every 1 sec - timer_link_1sec = millis(); - if(wizphy_getphylink() == PHY_LINK_ON) - { - led1_high(); - } - else + timer_tick_1sec = millis(); + //To restore GPIO state on start-up application + if(blynk_restore_connection) { - led1_low(); + if(is_blynk_connection_available()) + { + blynk_restore_connection = 0; + //Requests Server to re-send current values for all widgets + PRINTF("++blynk_syncAll event\r\n"); //Just for debug + blynk_syncAll(); + } } } - */ } return 0; }