adafruit / Adafruit_FONA

Arduino library for the Adafruit FONA
https://www.adafruit.com/products/1946
211 stars 237 forks source link

USSD messages truncated too short #121

Open uwezi opened 4 years ago

uwezi commented 4 years ago

When using the example sketch FONAtest for the Adafruit Feather 32u4 FONA I encountered a problem sending the code to charge my sim-card. The message was 20 characters long, and only when sending it for the third time I noticed that the last characters were missing.

This in spite the fact that the test sketch tells the user that the message can be up to 140 characters long.

in Adafruit_FONA.cpp from line #928

char sendcmd[30] = "AT+CUSD=1,\""; strncpy(sendcmd + 11, ussdmsg, 30 - 11 - 2); // 11 bytes beginning, 2 bytes for close quote + null sendcmd[strlen(sendcmd)] = '\"';

needs to be changed because it limits and truncates the message including the AT-command to 30 characters. In order to allow for 140 character long messages it should be:

char sendcmd[140+11+2] = "AT+CUSD=1,\""; strncpy(sendcmd + 11, ussdmsg, 140); // 11 bytes beginning, 2 bytes for close quote + null sendcmd[strlen(sendcmd)] = '\"';