SIM900 throws error after resetting and re-connecting. #5389
Replies: 1 comment
-
Posted at 2016-07-10 by @gfwilliams Sounds strange - The Basically Espruino can often take a string or a function as an argument to callbacks - usually you'd just have something executable in that string so it's fine, but if you put something like JSON in it, it will fail. If you put It'd be an idea to figure out what variable contains that data, and then go through your code and figure out where it is used. Posted at 2016-07-11 by sp33c Of course I do deserializing pass an object to the callback : - > Posted at 2016-07-11 by sp33c I try one guess... Could it be related to the fact, I applied a success callback on my own func within getIP (SIM900). This callback does not get executed in the SIM900 before the final statement? Posted at 2016-07-12 by sp33c @gfwilliams I reset the SIM900 with a relais. I really switch it off and back on. After that the uplink (refresh IP) works... but not the requests. they will fail with above errors. Should I initialize something I forgot about? Posted at 2016-07-12 by @gfwilliams Is there a reset pin on your SIM900? Without it, But I don't think that is your problem... I don't think it's really SIM900 related at all - it looks to me like your code is passing non-executable code into a function that expects a callback. If you could post your code up here, we could take a look for you? Posted at 2016-07-12 by sp33c I have an SIM900 wich is Arduino compatible. As I know the Arduino has a RST-Pin I connected the appropriate SIM900 one to B4 on espruino. Posted at 2016-07-12 by sp33c All I do is run the below calls .... one after another it works as expected over 1.5 hour ... even chaining them via callback. Then once I start resetting the SIM900 (my own reset) wich completely switches the SIM900 off and back on. The first request (getJobs) will fail repeatedly.
the calls are done like:
Posted at 2016-07-12 by sp33c ups... I forgot to post the requests... 1.post(device, {xyz: 1}) I chain it: Posted at 2016-07-12 by @gfwilliams And what exact messages do you get on the console? The messages you posted previously started like this:
But you don't have those print statements in the code you posted up. As it happens after Posted at 2016-07-13 by jonreid Hi Gordon, as you know I have made a bunch of changes to my own SIM900 module. Most of these changes you probably wont want in the standard library but there are a couple of important bug fixes here and there for the original code. There is one bug in the receiveHandler which can cause corruption depending on the data framing. Shall I send you my current file so you can see my fixes ? Posted at 2016-07-18 by @gfwilliams Sorry for the delay - yes, that'd be great! If you're ok with sharing it I'd love to be able to pull your changes back. Potentially you could create a second module that you used with Posted at 2016-07-28 by sp33c I rewritten things entirely from scratch.... also with use of promises.
OK 0, CONN 0, S +RECEIVE,0, 0, CLOS the next call then will get stuck then. kind regards, Posted at 2016-07-29 by sp33c my carriots module is here: Posted at 2016-07-29 by @gfwilliams Strange - I haven't seen that before. After Can you check Can you try using Posted at 2016-07-29 by sp33c yes, I will try that. Posted at 2016-07-29 by sp33c Hi Gordon, thanks again for you support. I have only limited time today. Only, if you have time.
Posted at 2016-07-29 by sp33c I accidentally also put my debug output from the request in their above? Should I take it out.
Posted at 2016-07-29 by sp33c It is wired once more carriots wants me to send content-length on get.... Posted at 2016-07-29 by sp33c I believe I shouldn't bother about this behavior. I just seen, the carriots io supports the max parameter. So I will get only two at a time. And my code will be fixed. :-) Posted at 2016-07-29 by @gfwilliams I'm still confused about But the Which board are you using this on? And you're connecting over USB? Posted at 2016-07-29 by sp33c I am using the Pico board. If the document gets parsed by one the total_document is there every time. If however the document getting JSON parsed is only truncated this is missing. A good thing. As I understood now at least the source of error, I could so far fix it with the max param that carriots provides. I pick only one job at a time. If this works for 7d/24h I'll be glad. My garden is in a remote area very far away. :-) Posted at 2016-07-29 by sp33c I use the maximum baud rate on the SIM900, can this be a cause? Posted at 2016-07-29 by sp33c in the above log from the example it looks like that the response string itself handed into JSON.parse is not valid json anymore. It has passages like:
So I came to the conclusion the SIM900 mixed it up(?) Posted at 2016-07-29 by @gfwilliams
What is the baud rate? It definitely won't help... The Pico can buffer around 500 bytes, so it won't take long to fill it at higher rates. I'd definitely try and lower the rate significantly - it should stop the FIFO_FULL messages anyway.
I think the SIM900 is probably fine - it's just that Espruino's buffers are getting full so it's losing the odd character. Posted at 2016-07-29 by jonreid This could be caused by a bug I found in the SIM900 driver. In the function 'receiverHandler' there is a line of code: This needs to be changed to I found if the whole response fitted within one handler transfer the orginal code would corrupt the response. Posted at 2016-07-29 by sp33c Amazinly doing so.. it seems to works! I just put the max=1 param out. As of today a collection length of >3 broke that.
Posted at 2016-07-29 by sp33c I have to test this over a long period of time. Thanks @jonreid if this works! Posted at 2016-07-29 by sp33c I think @gfwilliams is right:
Posted at 2016-07-29 by jonreid My fix is for responses that are small in size - so you still need that. If you are getting low memory errors you need to process your data in smaller chunks ie either optimise your json or request it in smaller chunks. You never want to get into a low memory scenario as things start breaking pretty fast. It is worthwhile monitoring 'process.memory().free' at various parts of your code to highlight issues. In my project - if I ever get an 'out of memory' error (which you should code to prevent) I reboot otherwise the code operation will be in an unknown state, also use the new watchdog feature. Posted at 2016-07-30 by @allObjects @sp33c, I asume that the data you published in this forum is test data and therefore, my conclusion may not be the answer to the payload capacity issues... but I still want to mention it. JSON is already much leaner than XML, but it is still 'fat', especially for repetitive data... and last but not least the lots of double quotes required. JSON is very easy and fast to process, but may be you can afford some CPU cycles to get over the bump. In case 'you know your data' / 'have control over the data', a CSV string is still the most effective to get there.... and furthermore, even having a catalog with ids for values that repeat. The challenge is now to provide what xml does best and JSON about equally as good: provide the meta data (reference) about the individual data/information elements, and the structure... The first one 'is easy' and is applicable if you have a number of defined data structures: first or last data item includes the id to the definition of the data structure. The second one is when the values are sparse and variable in distribution across the overall (complete) structure: use the 1st approach - if useful - to identify the main structure, and a second - or second last - value for a bitmap that identifies which attribute (always same sequence) has value... (saves you from sending commas). When values are repeated, a dictionary is built, passed as first thing in the payload, and then payload-local references describe the content (Some DBs do compression this way in order to not have to run uncompress algorithms). Further option is to code the values if the values are known beforehand. Posted at 2016-07-30 by sp33c @jonreid yes, i knew about it and my status post requests are publishing the memory free. may i ask how do you reboot? what command? hm... my code is not that big, actually at any point there shouldn't be a less memory state. i even taking care about intervals and timeout myself. it might due to memory leaking somewhere else. Posted at 2016-07-30 by sp33c @allObjects the blownup json is due mainly of infrastructure. carriots is a great iot platform. of course i can write the whole platform myself and being leaner. but i rely on such infrastructure for inter device communication. i like there way. i think the espruino device should be capable of handling such simple things. the productive response data is a bit leaner just carrying two values, cycle (watercycle) and time. also i use the max param to limit the get to one response entry at a time. carriots doesnt represent a full schema but all you need to be able to handle different devices and logik. one optimization point can be to put the logic into carriots and have not a autonomous device anymore. the overhead to deal with csv isnt really an advantage. Posted at 2016-07-30 by sp33c i am experienced with garbage collection issues, it should theoretically never be the case to run out of memory if constantly destroying references my self carefully. also not json is an isue as after processing the objects are nulled. i may have to rething the overall model of that piece of hardware. Posted at 2016-07-30 by sp33c I updated my version to get rid of self caused memory leaks, I use the immediate return for timeouts. Thanks to the fix to the SIM900 module it is so far quite stable.
Posted at 2016-07-31 by sp33c I just noticed, the SIM900 library is memory leaking, maybe du networkJS.create(netCallbacks). Posted at 2016-07-31 by sp33c per reconnect my code is leaking 200 memory units (a 20bytes?) Posted at 2016-07-31 by jonreid I have given my SIM900 module to Gordon so he can sync in the bug fixes I have made. There are a couple of other basic things required for reliable operation ie in netcallbacks/create - there are more unregisterLine required for error cases and you need to remove the CIPSTART exception throw. Also if the SIM800 CIPSTART fails, the driver wont catch that so I added a timeout which then closes the socket and things are cleaned up properly. At the app level, you need to ensure that the connect/send/receive process is completely finished before calling again otherwise memory will be consumed - this also means catching errors so the process can unwind properly. Use the request.on('error', function(e) ... If you are in a low coverage area and the SIM800 can falloff the network there are a whole lot more considerations that come into play - you could just choose the approach of if things go wrong, reset and start all over, but I chose to handle all the states the SIM800 can get into and handle them in a more managed fashion. Hopefully Gordon will have the time to sync in the basics of my changes to benefit everyone. Posted at 2016-07-31 by sp33c thanks for the feedback. could you send me your code as well? Do you have any? ([email protected]) Posted at 2016-08-01 by @gfwilliams Thanks - I'll try and update this, but maybe not this week - things are a bit busy! For the memory leak, it's actually most likely that the sockets are still open? You should be able to check in Posted at 2016-08-02 by sp33c thank you very much. eventhough i resetted the sockets, the leak was still there. i expect the netcallbacks to leave external references (to the sim900 code) in the networkjs. closures are prone for memory leaks but most websites do not run above 1h, so nobody notices it. Posted at 2016-08-02 by sp33c i have not closed the sockets. i declared them to null. this may not have been enough. however this may be part of networkjs. i cannot test further i am abroad, the next 4 weeks. thank you for your kind support so far. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-07-10 by sp33c
Excuse me this issue may not be SIM900 related, which performs quite good with the module... see my fix below:
Whenever I reset my SIM900 (switch it totally off) and would run a JSON-Request after reset it throws this kind of error, even I am online:
req start
Closed: undefined
Uncaught SyntaxError: Got ID:total_documents expected ':'
at line 3 col 3
{"total_documents":0,"result"l_documents":0,"result":""}:""}
^
in function called from system
However when I first doing a request with a non JSON result say the hello-request with a text result. The consecutive calls with JSON will NOT fail.
If someone has a hint, please tell me. kind regards, Alex
Beta Was this translation helpful? Give feedback.
All reactions