I don't think we ever get a 0x0A
from the spacebrew server, but rather, 0x09
, as the ping. The library sends 0x8A
out as the pong in response.
In the original Arduino Websocket library that you ported from, the outgoing pong opcode is also 0x8A
. However, RFC6455 specifies a 0x0A
for the pong. I'm aware that the library isn't 100% RFC6455 compliant, which is not crucial at this point anyway, but I was just curious about these opcodes as I went through the code trying to figure out what's causing my lockups.
[quote="ekbduffy, post:22, topic:3090"]
Do You understand that CC3000 has his own little "brain" and as I understant it can "discuss" with cloud and hold an tcp connection by itself. And only warn main processor when it need to be warned (in case of arriving message, for example). So there is somewhere your send code more buggy than my, or maybe you using this function in wrong way %) Not shure. because after reading all send functions in Spacebrew and websocket cpp's, i've seen same as my code.[/quote]
Yes I'm aware of the way the CC3000 works and how it processing cycles are delegated between the user's main firmware loop and Spark.process()
. This was where I'm left wondering, whether the shared TCP access between the Spark and the firmware processes is preventing websocket traffic from completely transmitting, before the Spark processes kick in. As you've looked at my code, yup, it's all just basic boolean sends/receives for me at the moment.
I've even tried SYSTEM_MODE(MANUAL);
and manually handled the Spark.connect() and Spark.process() calls, but that didn't resolve the issue.
I'm also intentionally testing this setup on my spacebrew server a few continents away from where my Sparks are, in order to simulate a worst-case lag scenario. This could be contributing to the issues and I'm testing a local setup today to see if things improve. Will post updates on this later.
[quote="ekbduffy, post:22, topic:3090"]
What do You mean under "Streamed data" continous sending? I never tried this ...[/quote]
Basically just polling, for example, an analog input and posting it as a spacebrew range datatype at short intervals. Knowing how the Spark splits processing cycles between cloud-specific code and user firmware, I tried relatively short intervals (100ms) first, all the way past our current measured lag time (600ms to 1s).
This is a repeatable error that will cause my Spark to freeze after the first/second message is sent.
[quote="ekbduffy, post:22, topic:3090"]
ofcourse, that because it not got pong on his ping.[/quote]
Exactly, which is why I'm wondering: why would my Spark not return a pong? The ws connection is supposedly still alive when this stall in communication happens.
I can confirm that the WebSocketClient::monitor()
function still runs, via serial. However, a clue here is with client.available()
in the function – my Spark's 'freeze' is happening because client.avaliable()
turns out to be zero bytes, therefore causing the rest of the WebSocketClient::monitor()
function not to execute.
It sounds to me like the Spacebrew server was still expecting websocket data to conclude, leading both parties listening on each other for a response, and therefore no new pings from the Spacebrew server.
During the times when it's working (basically when I don't send any data out, but what's the point then? :)), I see the pongs going back to my spacebrew server without issue.
[quote="ekbduffy, post:22, topic:3090"]
But my is works.. Or You still mean streamed data?[/quote]
Could you try hooking up a button to send boolean messages, but then stress-testing it by rapidly pressing it to send a succession of spacebrew messages to the server? Just to check if your Spark locks up? It's the same as 'streaming' data to spacebrew at short intervals.
[quote="ekbduffy, post:22, topic:3090"]
I have almost same timings, but if you enter some prints on serial in arriving of message - You will see, that message arrived almost as button pressed, but 0.5-0.4 second took it's parsing. So this mades me sad and thinking how to speed this up...[/quote]
Yes indeed, same for me, the string parsing and concatenation to send data out as a publisher is near instantaneous.
[quote="ekbduffy, post:22, topic:3090"]
Hmmm! This is interesting. This can mean, that there is lag in TCPClient itself... not in parsing/compiling JSON code..[/quote]
Correct, whenever my Spark freezes up, outgoing JSON strings parsed by the WebSocketClient::send function executes as expected, hardly any delays. When my spacebrew is connected, I do get the 0.5s delays as mentioned above.