From 481a1fee9480c6af83a5d5f67ba919d0992f6733 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 27 Jun 2021 08:16:26 -0400 Subject: [PATCH 1/3] try opening socket twice --- main.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 8a9cdc72..2f049a99 100644 --- a/main.c +++ b/main.c @@ -1577,7 +1577,32 @@ void get_tlm_fox() { printf("\nConnection Failed \n"); printf("Error: %s \n", strerror(errno)); error = 1; - sleep(2.0); // sleep if socket connection refused + sleep(1.0); // sleep if socket connection refused + + // try again + error = 0; + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + printf("\n Socket creation error \n"); + error = 1; + } + + memset( & serv_addr, '0', sizeof(serv_addr)); + + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(PORT); + + // Convert IPv4 and IPv6 addresses from text to binary form + if (inet_pton(AF_INET, "127.0.0.1", & serv_addr.sin_addr) <= 0) { + printf("\nInvalid address/ Address not supported \n"); + error = 1; + } + + if (connect(sock, (struct sockaddr * ) & serv_addr, sizeof(serv_addr)) < 0) { + printf("\nConnection Failed \n"); + printf("Error: %s \n", strerror(errno)); + error = 1; + sleep(1.0); // sleep if socket connection refused + } } if (error == 1) ; //rpitxStatus = -1; From 874ae4830eb4f35101cb77704a0ef60cfa744796 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 27 Jun 2021 08:23:32 -0400 Subject: [PATCH 2/3] 2 second wait to reopen socket --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 2f049a99..8c6dd48f 100644 --- a/main.c +++ b/main.c @@ -1577,7 +1577,7 @@ void get_tlm_fox() { printf("\nConnection Failed \n"); printf("Error: %s \n", strerror(errno)); error = 1; - sleep(1.0); // sleep if socket connection refused + sleep(2.0); // sleep if socket connection refused // try again error = 0; @@ -1601,7 +1601,7 @@ void get_tlm_fox() { printf("\nConnection Failed \n"); printf("Error: %s \n", strerror(errno)); error = 1; - sleep(1.0); // sleep if socket connection refused + // sleep(1.0); // sleep if socket connection refused } } if (error == 1) From fd9626592bbfc2c24489d6d6292dc9968bc8c891 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 27 Jun 2021 08:25:17 -0400 Subject: [PATCH 3/3] reduce sleep by 1 sec --- rpitx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpitx.py b/rpitx.py index c3af11c8..60ca15d2 100644 --- a/rpitx.py +++ b/rpitx.py @@ -86,7 +86,7 @@ if __name__ == "__main__": time.sleep(4); # was 8 GPIO.output(txLed, txLedOff) - time.sleep(2) + time.sleep(1) if (transmit):