Thank you, @Gunner
I assumed it was something in my code as well, so I blew my changes out and tested with the blynk.cpp
exactly as it was pulled from github. Trying to start simple and add on til it breaks. The issue continued exactly the same; ie. the client CPU usage spikes and the IOS app reports a disconnected hardware.
To be clear, I am not asking for code lessons. I simply cannot get this service to connect for more than 20 seconds. I’ve posted the code below, per your request. Running this code allows my to send and read values on V1 as expect… for 20 seconds.
I believe you are correct that it is something on my end, but I haven’t changed the code make this happen. Therefore, I am thinking it is some other issue. Possibly networking? (I know you aren’t a networking troubleshooting shop, either) I have crawled through this source code for three or four days tracing and testing, but I cannot find 20 second timers or limits that would trigger this. I’m very confused. Thank you for responding.
The code:
* @file main.cpp
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Mar 2015
* @brief
*/
//#define BLYNK_DEBUG
#define BLYNK_PRINT stdout
#ifdef RASPBERRY
#include <BlynkApiWiringPi.h>
#else
#include <BlynkApiLinux.h>
#endif
#include <BlynkSocket.h>
#include <BlynkOptionsParser.h>
static BlynkTransportSocket _blynkTransport;
BlynkSocket Blynk(_blynkTransport);
#include <BlynkWidgets.h>
BLYNK_WRITE(V1)
{
printf("Got a value: %s\n", param[0].asStr());
}
void setup()
{
}
void loop()
{
Blynk.run();
}
int main(int argc, char* argv[])
{
const char *auth, *serv;
uint16_t port;
parse_options(argc, argv, auth, serv, port);
Blynk.begin(auth, serv, port);
setup();
while(true) {
loop();
}
return 0;
}
For what its worth, when I strace the client code and watch what calls are made starting about 20 seconds in, I see that this block from BlynkSocket.h
is repeating:
size_t read(void* buf, size_t len) {
ssize_t rlen = ::read(sockfd, buf, len);
if (rlen == -1) {
//BLYNK_LOG4("Read error ", errno, ": ", strerror(errno));
if (errno == ETIMEDOUT || errno == EWOULDBLOCK || errno == EAGAIN) {
return 0;
}
disconnect();
return -1;
}
return rlen;
}
While it is working, I get traces like this:
16:12:02.232626 read(4, "\24='\0\6", 5) = 5
16:12:02.244679 clock_gettime(CLOCK_MONOTONIC_RAW, {108545, 561753000}) = 0
16:12:02.245207 write(1, "[19757] READ HEADER:\n", 21) = 21
16:12:02.248908 clock_gettime(CLOCK_MONOTONIC_RAW, {108545, 566057000}) = 0
16:12:02.251629 write(1, "[19762] >[14]='[00|06]\n", 23) = 23
16:12:02.255150 read(4, "vw\0000\0000", 6) = 6
16:12:02.256719 clock_gettime(CLOCK_MONOTONIC_RAW, {108545, 573774000}) = 0
16:12:02.258726 write(1, "[19769] PROCESS INPUT:\n", 23) = 23
16:12:02.261993 clock_gettime(CLOCK_MONOTONIC_RAW, {108545, 579184000}) = 0
16:12:02.263467 write(1, "[19775] >vw[00]0[00]0\n", 22) = 22
16:12:02.265439 clock_gettime(CLOCK_MONOTONIC_RAW, {108545, 582594000}) = 0
16:12:02.269220 read(4, 0xbeb8b470, 5) = -1 EAGAIN (Resource temporarily unavailable)
16:12:02.282699 read(4, 0xbeb8b470, 5) = -1 EAGAIN (Resource temporarily unavailable)
16:12:02.302647 read(4, 0xbeb8b470, 5) = -1 EAGAIN (Resource temporarily unavailable)
16:12:02.322642 read(4, 0xbeb8b470, 5) = -1 EAGAIN (Resource temporarily unavailable)
Once is stops working this trace looks like this forever:
16:12:02.502669 read(4, "", 5) = 0
16:12:02.518190 read(4, "", 5) = 0
16:12:02.518640 read(4, "", 5) = 0
16:12:02.523106 read(4, "", 5) = 0
16:12:02.526461 read(4, "", 5) = 0
16:12:02.527027 read(4, "", 5) = 0
16:12:02.527450 read(4, "", 5) = 0