skorokithakis / A6lib

An ESP8266/Arduino library for communicating with the A6 GSM module. ⛺
MIT License
127 stars 49 forks source link

Add "__attribute__((used))" to function definition of sscanf #6

Closed BJDayzz closed 7 years ago

BJDayzz commented 7 years ago

I tried to compile the example "dial" in Arduino V1.6.13. After I got the error message

sscanf' referenced in section.text.startup' of C:\Users\BJ\AppData\Local\Temp\ccVAm20R.ltrans0.ltrans.o: defined in discarded section `.text' of libraries\A6lib-master\sscanf.cpp.o (symbol from plugin)

I searched a bit and found this one: https://forum.repetier.com/discussion/2389/stepperwait-referenced-in-section-text-compiliation-issues

After I changed int sscanf(const char *buf, const char *fmt, ...) { in sscan.cpp to int __attribute__((used)) sscanf(const char *buf, const char *fmt, ...) { the sketch "dial" was compileable.

skorokithakis commented 7 years ago

Ah, thank you. Are you using an Arduino to run the sketch on, or an ESP8266? I'm not sure what __attribute__((used)) does or what it's compatible with...

skorokithakis commented 7 years ago

Doesn't seem to hurt anything, so I've implemented it, thanks!

BJDayzz commented 7 years ago

Hi Stavros.

I tried it with Arduino only. I don't have an ESP8266. As far as I understood the problem comes through the compiler / parser. I guess it has to do with code optimization in the Arduino IDE. It seems to first optimize the function away and afterwards finds that it needs it. Since the only effect of the new command is to NOT remove the code, there should not be any negative effect to the ESP8266 and its IDE respectively. But I fear I'm not deep enough into this topic.

But THANK YOU A LOT for providing this lib! :-) It made it very easy for me to get my A6 module working.

Best regards, Bjoern

2016-12-29 0:47 GMT+01:00 Stavros Korokithakis notifications@github.com:

Doesn't seem to hurt anything, so I've implemented it, thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/skorokithakis/A6lib/issues/6#issuecomment-269559978, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ8Z5MZI_C7zD4Il1dI8i5Xg-Rv6wmc9ks5rMvT_gaJpZM4LXEcb .

skorokithakis commented 7 years ago

I tried it on the ESP8266 and it looks like it works fine, thanks for the heads up! Is the module working well for you?

BJDayzz commented 7 years ago

So far it's working fine. But I just use a few functionalities - to receive a call from my mobile, then directly hang up and start the auxiliary heating in my car. Too simple to find serious issues. ;-) But maybe soon I do more sophisticated things with it and then become more useful for the further development of your lib.

Now first I will try to get familiar with GitHub in order to not just demand for changes but also be able to provide them.

2016-12-29 15:01 GMT+01:00 Stavros Korokithakis notifications@github.com:

I tried it on the ESP8266 and it looks like it works fine, thanks for the heads up! Is the module working well for you?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/skorokithakis/A6lib/issues/6#issuecomment-269633973, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ8Z5FAtzIU8oWxWoVzBYnGR7SFbY8ahks5rM71JgaJpZM4LXEcb .

BJDayzz commented 7 years ago

Hi Stavros!

I made a little enhancement of your library but still don't know how to bring it into the official code. That's why I just send it to you via e-mail.

It's a method to get the signal strength in %. I don't know much about C++, so feel free to improve the code if you think it's useful. But at least it seems to work so far.

A6lib.cpp: // Get the strength of the GSM signal. int A6lib::getSignalStrength() { String response = ""; uint32_t respStart = 0; int strength, error = 0;

// Issue the command and wait for the response.
A6command("AT+CSQ", "OK", "+CSQ", A6_CMD_TIMEOUT, 2, &response);

respStart = response.indexOf("+CSQ"); if (respStart >= 0) { sscanf(response.substring(respStart).c_str(), "+CSQ: %d,%d", &strength, &error); // Bring value range 0..31 to 0..100%, don't mind rounding.. strength = (strength * 100)/31; } return strength; }

A6lib.h: int getSignalStrength();

keywords.txt: getSignalStrength KEYWORD2

My test code: int sigStrength = A6l.getSignalStrength(); Serial.println(sigStrength);

Best regards, Bjoern

2016-12-29 15:01 GMT+01:00 Stavros Korokithakis notifications@github.com:

I tried it on the ESP8266 and it looks like it works fine, thanks for the heads up! Is the module working well for you?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/skorokithakis/A6lib/issues/6#issuecomment-269633973, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ8Z5FAtzIU8oWxWoVzBYnGR7SFbY8ahks5rM71JgaJpZM4LXEcb .

skorokithakis commented 7 years ago

Thanks for the contribution (but please open separate issues for separate things). You can create a pull request by following this guide:

https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github

It looks much worse than it is, in reality you just click the "fork" button at the top, make the changes in your repo, push them and click "create pull request", and that's it.

skorokithakis commented 7 years ago

I've added your code, thank you! It would have taken me much less time to review/accept if it were in a PR, but it was small enough to add by hand, thanks again!

BJDayzz commented 7 years ago

Sorry for the inconvenience, the problem was/is that I really don't know much about GitHub. E.g. did I only reply to your last e-mail in gmail and did not expect that it will add my text to the old issue. I'm curious where THIS text will be automatically added in GitHub. :-) But your link gave me some hints to get forward. Thank you!

Does "PR" mean "personal repository"?

2017-01-22 14:42 GMT+01:00 Stavros Korokithakis notifications@github.com:

I've added your code, thank you! It would have taken me much less time to review/accept if it were in a PR, but it was small enough to add by hand, thanks again!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/skorokithakis/A6lib/issues/6#issuecomment-274331668, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ8Z5CjkapF3foKi70F3kXzkPOx4m352ks5rU1yxgaJpZM4LXEcb .

skorokithakis commented 7 years ago

It did get added, yes :)

It means "pull request", it's just a thing that tells me "please integrate my changes" and shows me the changes in a diff.