Hello!
How can I send the AT+CBC value as a sms ?
I've tried:
Declared "batt" as char, string, int. All I get are weird signs on the sms to the phone.
But it show right on the serial monitor.
fona.println("AT+CBC");
updateSerial(); //loop function --> serial.available
batt = fona.read();
....
...
fona.print(batt); // to send as sms.
delay(1000);
fona.print((char)26);
...
and i also tested:
fona.sendSMS(callerIDbuffer, batt);
same result.
Regards
Cristian
Feather 32u4 FONA AT+CBC value to sms
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- rskup
- Posts: 230
- Joined: Sat Aug 01, 2020 9:04 pm
Re: Feather 32u4 FONA AT+CBC value to sms
Just tossing this out there, but have you looked at the AT+CMGF (SMS Message Format) command?
You may have AT+CMGF=0 set, you probably want AT+CMGF=1
You may have AT+CMGF=0 set, you probably want AT+CMGF=1
- Cristian_S
- Posts: 9
- Joined: Fri Nov 13, 2020 10:15 am
Re: Feather 32u4 FONA AT+CBC value to sms
Hi!
Thanks for the answer/guess :-). Yes I already have the AT+CMGF=1.
Do you know what "declaration" (char/String/int...) is using when sending SMS. Do I have to use char? or something else?
Thanks for the answer/guess :-). Yes I already have the AT+CMGF=1.
Do you know what "declaration" (char/String/int...) is using when sending SMS. Do I have to use char? or something else?
- Cristian_S
- Posts: 9
- Joined: Fri Nov 13, 2020 10:15 am
Re: Feather 32u4 FONA AT+CBC value to sms
When I use the AT+CBC command I get in the serial monitor:
+CBC: 0,99,4194
but...
How do I save/send that as an SMS ?
When I use:
batt = fona.read();
It seems to save it "wrong" beacouse when I use Serial.println(batt) it shows strange signs dependent on how I have declared "batt".
+CBC: 0,99,4194
but...
How do I save/send that as an SMS ?
When I use:
batt = fona.read();
It seems to save it "wrong" beacouse when I use Serial.println(batt) it shows strange signs dependent on how I have declared "batt".
- rskup
- Posts: 230
- Joined: Sat Aug 01, 2020 9:04 pm
Re: Feather 32u4 FONA AT+CBC value to sms
Ok, next toss (guess):
What about using fona.readString() rather than fona.read()?
https://www.arduino.cc/reference/tr/lan ... eadstring/
If that doesn't work, will fire up my fona 3g and try to duplicate what you're doing, sending the battery voltage as an SMS would be a useful addition for a gps tracker I'm trying to build, I like that idea.
What about using fona.readString() rather than fona.read()?
https://www.arduino.cc/reference/tr/lan ... eadstring/
If that doesn't work, will fire up my fona 3g and try to duplicate what you're doing, sending the battery voltage as an SMS would be a useful addition for a gps tracker I'm trying to build, I like that idea.
- Cristian_S
- Posts: 9
- Joined: Fri Nov 13, 2020 10:15 am
Re: Feather 32u4 FONA AT+CBC value to sms
Hi!
Thanks rskup!
It works whit fona.readString() :-)
Now I get the entire SMS (AT + CBC) string to my phone. BUT I also hade to remove "updateSerial();" after the "fona.println("AT+CBC\r\n");"
otherwise it does not seem as if there is any value left to retrieve.
The result in the phone:
+CBC: 0,93,4144
OK
So I am very happy.. but I will try to break out a certain part of the string and just send one part of it ...
maybe using substring()?!
https://www.arduino.cc/reference/en/lan ... substring/
This is the working code:
Thanks rskup!
It works whit fona.readString() :-)
Now I get the entire SMS (AT + CBC) string to my phone. BUT I also hade to remove "updateSerial();" after the "fona.println("AT+CBC\r\n");"
otherwise it does not seem as if there is any value left to retrieve.
The result in the phone:
+CBC: 0,93,4144
OK
So I am very happy.. but I will try to break out a certain part of the string and just send one part of it ...
maybe using substring()?!
https://www.arduino.cc/reference/en/lan ... substring/
This is the working code:
Code: Select all
String batt = "";
.
.
void battery()
{
fona.println("AT+CMGF=1\r");
updateSerial();
fona.println("AT+CBC\r\n"); //Battery level
//updateSerial();
batt = fona.readString();
Serial.println("Sending Data...");
delay(1000);
fona.print("AT+CMGS=\"+******************\"\r"); //phone number and country code
delay(1000);
Serial.println(batt);
delay(1000);
fona.print(batt); //This string is sent as SMS
delay(1000);
fona.print((char)26);//Tell the module that it can send the SMS
delay(1000);
fona.println();
Serial.println("Data Sent.");
delay(1000);
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
fona.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(fona.available())
{
Serial.write(fona.read());//Forward what Software Serial received to Serial Port
}
}
- rskup
- Posts: 230
- Joined: Sat Aug 01, 2020 9:04 pm
Re: Feather 32u4 FONA AT+CBC value to sms
Hey Cristian, cool, things are starting to work.
If you're just looking to only send the first line, I have used the "replace()" command for stripping out parts of a reply I didn't want.
So I played around a bit with my FONA 3G and I think (keyword - think) this will work for you:
batt = fona.readString();
batt.replace("\r","");
batt.replace("\n","");
batt.replace("OK","");
That should strip out the return character, the new line character, and the "OK".
Then your "batt" string should just be the "+CBC: 0,xx,yyyy" and nothing else.
fyi, I did try combining all three replace() lines into one like:
batt.replace("\r\nOK","");
but that did not work at all.
Ok, hope things keep going well!
If you're just looking to only send the first line, I have used the "replace()" command for stripping out parts of a reply I didn't want.
So I played around a bit with my FONA 3G and I think (keyword - think) this will work for you:
batt = fona.readString();
batt.replace("\r","");
batt.replace("\n","");
batt.replace("OK","");
That should strip out the return character, the new line character, and the "OK".
Then your "batt" string should just be the "+CBC: 0,xx,yyyy" and nothing else.
fyi, I did try combining all three replace() lines into one like:
batt.replace("\r\nOK","");
but that did not work at all.
Ok, hope things keep going well!
- rskup
- Posts: 230
- Joined: Sat Aug 01, 2020 9:04 pm
Re: Feather 32u4 FONA AT+CBC value to sms
Yep, me again.
If you only want to pull the milli-volts out of batt, then try:
batt = fona.readString();
String battSub = batt.substring(batt.lastIndexOf(",")+1,batt.lastIndexOf(",")+5);
If you only want to pull the milli-volts out of batt, then try:
batt = fona.readString();
String battSub = batt.substring(batt.lastIndexOf(",")+1,batt.lastIndexOf(",")+5);
- Cristian_S
- Posts: 9
- Joined: Fri Nov 13, 2020 10:15 am
Re: Feather 32u4 FONA AT+CBC value to sms
Hi!
Thanks again rskup! Thank you very much for helping me whit the code! :-)
I used your code line and added so that the sms shows ***** mV and % left of the battery.
For example:
The message in the SMS
4200 mV
99%
Thanks again rskup! Thank you very much for helping me whit the code! :-)
I used your code line and added so that the sms shows ***** mV and % left of the battery.
For example:
The message in the SMS
4200 mV
99%
Code: Select all
void battery()
{
fona.println("AT+CMGF=1\r"); //Set the module to SMS mode
updateSerial();
fona.println("AT+CBC\r\n"); //Battery level
batt = fona.readString();
String battSubV = batt.substring(batt.lastIndexOf(",")+1,batt.lastIndexOf(",")+5);
String battSubP = batt.substring(batt.lastIndexOf(",")+0,batt.lastIndexOf(",")-2);
Serial.println("Sending Data...");
delay(500);
fona.print("AT+CMGS=\"+******************\"\r");// Phone number, include country code
delay(500);
Serial.println(battSubV);
Serial.println(battSubP);
delay(500);
fona.print(battSubV + " mV" + "\r\n" + battSubP + " %"); //This string is sent as SMS
delay(500);
fona.print((char)26);//Tell the module that it can send the SMS
delay(500);
fona.println();
Serial.println("Data Sent.");
delay(500);
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
fona.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(fona.available())
{
Serial.write(fona.read());//Forward what Software Serial received to Serial Port
}
}
- rskup
- Posts: 230
- Joined: Sat Aug 01, 2020 9:04 pm
Re: Feather 32u4 FONA AT+CBC value to sms
Hey Cristian, I like how that looks, nice addition to any Fona project!
Dawned on me -- the "percent battery" could be one to three digits depending on its value (1-100).
Just replace your:
String battSubP = batt.substring(batt.lastIndexOf(",")+0,batt.lastIndexOf(",")-2);
with this:
String battSubP = batt.substring(batt.indexOf(",")+1,batt.lastIndexOf(","));
Now it extracts the percent number between the two commas, whether one, two, or three digits.
Shouldn't have to worry about the millivolts, will always be 4 digits since the FONA won't work below about 3 volts, much less 1 volt.
Ok, hope all's well!
Dawned on me -- the "percent battery" could be one to three digits depending on its value (1-100).
Just replace your:
String battSubP = batt.substring(batt.lastIndexOf(",")+0,batt.lastIndexOf(",")-2);
with this:
String battSubP = batt.substring(batt.indexOf(",")+1,batt.lastIndexOf(","));
Now it extracts the percent number between the two commas, whether one, two, or three digits.
Shouldn't have to worry about the millivolts, will always be 4 digits since the FONA won't work below about 3 volts, much less 1 volt.
Ok, hope all's well!
- Cristian_S
- Posts: 9
- Joined: Fri Nov 13, 2020 10:15 am
Re: Feather 32u4 FONA AT+CBC value to sms
Hello rskup!
Thanks again :-)
I noticed yesterday when I tested and the battery was fully charged that it showed 00 :-) then understood that I have to look at that line of code again. But then you had already fixed the solution for me :-) Thank you!
Regards
Cristian
Thanks again :-)
I noticed yesterday when I tested and the battery was fully charged that it showed 00 :-) then understood that I have to look at that line of code again. But then you had already fixed the solution for me :-) Thank you!
Regards
Cristian
Please be positive and constructive with your questions and comments.