Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module AT.js: getData() returns garbage '\n' character #1512

Closed
wklenk opened this issue Sep 20, 2018 · 6 comments
Closed

Module AT.js: getData() returns garbage '\n' character #1512

wklenk opened this issue Sep 20, 2018 · 6 comments

Comments

@wklenk
Copy link

wklenk commented Sep 20, 2018

When dealing with the Quectel BG96 radio model, common practice is to register for the unsolicited return code +QIURC using the AT module. As soon as this URC is received, a callback function is called that is used to read out the actual data from the peer.

An example URC might look as follows:
\r\n+QIURC: "recv",0,4\r\n1234
This means, 4 bytes where received from the peer and the bytes are 1234

But if you call at.getData() to actually read out the data, you get:
\n123 instead of 1234

So there is obvioulsy a bug in the code that doesn't eliminate the garbage newline character '\n'.

I attach a JavaScript script that can be used to reproduce this bug. The output of this script is as follows:

js at_test.js 
] "\r\n+QIURC: \"recv\",0,4\r\n1234"
Got URC: "+QIURC: \"recv\",0,4"
[ '+QIURC: "recv"', '0', '4' ]
Received data from peer: "\n123"
] "4"

at-bug-test.js.txt

@gfwilliams
Copy link
Member

Thanks - I think the issue here is that registerLine is being called after the \r character, because I believe at some point there were some AT command devices that just used \r rather than \r\n. While it'd normally remove the newline in anything it passed, because data is being grabbed right after execution it's passing along the newline.

It's tempting to change the module to use \r\n, but I'd be quite worried that such a big behaviour change would break other modules that depended on it.

Are you encountering this with the https://github.com/espruino/EspruinoDocs/blob/master/devices/QuectelBG96.js module?

It seems that you could probably work around it using:

 at.getData(1, function(newline) {
    at.getData(lineSplittedUp[2], function(data) {
      console.log("Received data from peer: " + JSON.stringify(data));
    });
  });

@gfwilliams
Copy link
Member

Actually, please can you wait a bit on this? I'll see about changing the AT module for \r\n and will do some testing - it'd simplify a lot of things.

@wklenk
Copy link
Author

wklenk commented Sep 21, 2018

Are you encountering this with the https://github.com/espruino/EspruinoDocs/blob/master/devices/QuectelBG96.js module?

Yes. I am dealing with the RAK8212, so I took this file and adapted it to not create GPRS connections, but LTE-M NB1 "Narrowband IoT" connections.

It seems that you could probably work around it using:

I will try out. Thanks.

@gfwilliams
Copy link
Member

Ok, just done. That should improve things for you I hope, although you may need to tweak the handling of ATE0 in your copy (see the changes in espruino/EspruinoDocs@ebcb304)

Hopefully this doesn't cause problems with other AT-command based devices, but I guess we'll see!

As I mentioned in the forum, if you're happy to share it'd be great to be able to build your NB-IoT related changes into QuectelBG96.js

@wklenk
Copy link
Author

wklenk commented Sep 24, 2018

Thanks. Tried it out and it works.
As I am a Espruino newbie, I don't know how to tell the (native) Web IDE that it should fetch the new file from espruino.com/modules/AT.min.js instead going on to use the "old" file. I guess there somewhere is a local cache that I need to invalidate. Currently, I did just hard code the complete URL in the "require" statement.

Sharing: Sure, I will share, but currently I am still learning and trying to get things running without flaws.

@gfwilliams
Copy link
Member

Thanks - the IDE should always use the new version - everything's set to work without caching (it should work).

The only issue is if you have enabled 'offline mode' in which case it'll always work from the cache of offline modules that it downloaded.

gfwilliams added a commit to espruino/EspruinoDocs that referenced this issue Oct 11, 2018
gfwilliams added a commit to espruino/EspruinoDocs that referenced this issue Oct 11, 2018
wklenk added a commit to wklenk/rak8212-espruino-nb-iot that referenced this issue Oct 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants