RAK8212/BG96 tcp close socket anomaly #7253
Replies: 1 comment
-
Posted at 2018-09-25 by @gfwilliams Ok, I've just updated the code so new firmwares will hopefully automatically call close - let me know if that works ok for you. I also added some extra debugging when sending data. The splitting of data is expected - it's just to do with the buffer sizes Espruino uses internally. What's not expected is if it doesn't immediately send the second packet. I think the send function is waiting for Thanks for your help with this! Posted at 2018-10-01 by Kartman Gordon,
We can see on the second invocation of sendCloud() that it 'knows' about the left over data, but the send fails.
Posted at 2018-10-02 by @gfwilliams Sorry about that - can you try again with I think the issue is that the send callback is getting Posted at 2018-10-02 by @gfwilliams Can you also try and see if that helps? I just made the relevant tweaks. Posted at 2018-10-03 by Kartman Since I've made tweaks to the BG96 module, I copied the changes to my module and tried it.
The second time looked like it worked as the webserver responded, so it was happy with the amount of data it got.
My guess it might be a timing sensitivity with the prompt?? Posted at 2018-10-03 by @gfwilliams It might help to give a bit of the dump before What's happening is the send function isn't getting the response it wanted with the given time period (you didn't lower the timeouts in your version did you?). Although as you say there's a My guess is that the BG96 may actually output I assumed wrong on a change for ESP8266 extremely recently, and had to make this change: espruino/EspruinoDocs@7b4b448#diff-465a45343fb61c597d45aa2f89be369b It's possible that if you make a similar one, it'll work. Posted at 2018-10-11 by Kartman Gordon, i couldn’t figure out how to graft the esp8266 code in. I did some more investigation and it seems the code doesn’t allow enough time for the send to complete and respond. Cat-nb1 is only 20kbit/s methinks, so it takes a bit longer than gsm/lte. I changed the timeout from 2000 to 10000. I’ve yet to do extensive testing to verify this. Posted at 2018-10-11 by @gfwilliams Hmm - it looks like the existing code doesn't wait for I've just made the changes to the QuectelBG96 on GitHub (including your timeout) so please could you give it a go and let me know how it works? Posted at 2018-10-12 by Kartman Initial tests indicate....... failure. Seems to be highly unreliable. I must preface this by saying I merged your changes into my code, so I may have missed something. So I've reverted the changes and are working from 225. I'm trying to get something working so I can test over the weekend, so I'll revisit this next week. Why was it hard for me to make the changes? I'm not the most experienced javascript programmer, so some of the idioms leave me perplexed. Like returning the closure. I wrote a little program to see what happens with return cb; vs return cb(d); As for the changes I've made to the BG96 code, I added the retry on the CREG?/CEREG? I can send you the code to see if you want to incorporate it? Posted at 2018-10-12 by @allObjects Without being to familiar with the detail - and going a bit on a limb - I try to answer the difference between
From variable name, I assume, it is a callback. It is for sure a function, because otherwise In JavaScript everything is an object... and a function, like JavaScript syntax defines that a function reference (function name) followed by opening and closing parenthesis it to be invoked. In other words, Typical with callbacks is that their invocation has to be deferred, because the parameter(s) that have to be passed on invocation are not available yet with the right values, and therefore the callback is handed to the next processing stage, to finally end up at the point AND time where the arguments are ready / populated with the right values and the callback can be invoked. Posted at 2018-10-12 by @gfwilliams
Yes, that'd be really helpful - thanks! Posted at 2018-10-12 by Kartman Here it is:
Posted at 2018-10-13 by Kartman I think I'm going to have to use the logic analyser to get some hard evidence as to what happens with the send function. Posted at 2018-10-15 by @gfwilliams Thanks - I've just added that code in on GitHub. It should go live this week. Shame that send isn't working properly yet - you say it is unreliable - so it does at least work sometimes now? Posted at 2018-10-15 by Kartman It doesn’t work even with small packets! It looks like it gets out of sync by one line. Posted at 2018-10-16 by Kartman A new day and a fresh perspective! I've hooked up the logic analyser and what seems to be happening is that the BG96 isn't receiving enough bytes only sometimes when doing the QISEND. It's expecting 536 bytes and we send around that amount. When it fails, it doesn't give the SEND OK until the next command comes along, which in my case is around 1 second later. That command fails as it gets gobbled up as data. What I am not sure of is which end is at fault. I'll hook up the CTS line to the analyser to see if the module wants us to stop or if the espruino code is not always sending what it should. Posted at 2018-10-16 by Kartman I've issued the command AT+IFC=2,2 to enable flow control. This seems to have made a difference. No hard evidence yet, as the defect only happens occasionally. Posted at 2018-10-16 by Kartman I've just tried rev 251 to see what happens. The code sends the AT+QISEND, the module responds with the \r\n> and then 1 second later, the code sends AT+QICLOSE Posted at 2018-10-16 by @gfwilliams But no other activity between Posted at 2018-10-16 by Kartman The forum gobbled my space - it must've thought it was a html tag, so yes, there is a space after the > My guess is the listener for the > is not firing. Posted at 2018-10-16 by Kartman I'm thinking your code expects an "OK" from the AT+QISEND. This doesn't happen. The sequence should be: Thus the current send function in QuectelBG96.js is borken. My current thought is there was a timing issue with the way the original code handled send but it worked most of the time. Adding extra time probably 'fixed' this. On top of this, sometimes there seems to be a discrepancy between the length of data we think we send and what the BG96 thinks it got - I've yet to narrow down on this. Setting flow control seems to help. Posted at 2018-10-17 by @gfwilliams Ahh, ok. Can you try this code for send please?
If that works, I'd be interested whether it works without the Posted at 2018-10-17 by Kartman I’ll try that tomorrow. Should the busy flag be reset in the send fail condition? Posted at 2018-10-17 by @gfwilliams Thanks - yes, good point! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2018-09-25 by Kartman
Gordon,
further to the previous thread regarding the RAK8212/BG96, here's a dump of the sequence-
Note that the ip address and auth have been changed to protect the innocent.
state() and close() and my functions that issue QISTATE and QICLOSE.
The function I used to create this:
We can see that close is not happening.
My workaround is adding the QICLOSE into the on "close" method works although it hard codes the socket number.
Another anomaly is what seems to be a size limitation on the packet which is less than the MTU (around 512 bytes??). The body is truncated and the truncated length is correct to the send request to the module, however the length in the header is the original length, so the server is waiting for more. You can see I've commented out part of the payload I send. When I un-comment it, the send size is 352 bytes even though the packet is larger.
Beta Was this translation helpful? Give feedback.
All reactions